User account creation filtered due to spam.

Bug 42167 - [OOP] SELECT TYPE with function return value
Summary: [OOP] SELECT TYPE with function return value
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-11-24 20:15 UTC by Damian Rouson
Modified: 2016-11-16 12:23 UTC (History)
2 users (show)

See Also:
Host: Mac OS X 10.5.8
Target: Mac OS X 10.5.8
Build: Mac OS X 10.5.8
Known to work:
Known to fail:
Last reconfirmed: 2009-11-24 21:26:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Rouson 2009-11-24 20:15:13 UTC
When the argument to a TYPE IS construct is a function result variable with the same name as the encompassing function, the compiler interprets the variable as a function invocation and fails without arguments.  The code below produces the error message below the code.  Also, replacing TYPE IS with CLASS IS produces the same result.

Damian

$ cat select_type.f03
module bar_module
  implicit none
  type :: bar
    real ,dimension(:) ,allocatable :: f
  contains
    procedure :: total
  end type

contains

  function total(lhs,rhs)
    class(bar) ,intent(in) :: lhs
    class(bar) ,intent(in) :: rhs
    class(bar) ,pointer :: total
    select type(rhs)
      type is (bar)
        allocate(bar :: total)
        select type(total)
          type is (bar)
            total%f = lhs%f + rhs%f
        end select
    end select
  end function

$ gfortran -c select_type.f03
select_type.f03:18.25:

        select type(total)
                         1
Error: Function 'total' requires an argument list at (1)
select_type.f03:20.17:

            total%f = lhs%f + rhs%f
                 1
Error: 'total' at (1) is not a variable
select_type.f03:22.7:

    end select
       1
Error: Expecting END FUNCTION statement at (1)
Comment 1 janus 2009-11-26 19:01:30 UTC
Subject: Bug 42167

Author: janus
Date: Thu Nov 26 19:01:02 2009
New Revision: 154679

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154679
Log:
2009-11-26  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42048
	PR fortran/42167
	* gfortran.h (gfc_is_function_return_value): New prototype.
	* match.c (gfc_match_call): Use new function
	'gfc_is_function_return_value'.
	* primary.c (gfc_is_function_return_value): New function to check if a
	symbol is the return value of an encompassing function.
	(match_actual_arg,gfc_match_rvalue,match_variable): Use new function
	'gfc_is_function_return_value'.
	* resolve.c (resolve_common_blocks,resolve_actual_arglist): Ditto.

2009-11-26  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42048
	PR fortran/42167
	* gfortran.dg/select_type_10.f03: New test case.
	* gfortran.dg/typebound_call_11.f03: Extended test case.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_10.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/typebound_call_11.f03

Comment 2 janus 2009-11-26 19:05:50 UTC
Fixed with r154679. Closing.