User account creation filtered due to spam.

Bug 36704

Summary: Procedure pointer as function result
Product: gcc Reporter: Tobias Burnus <burnus>
Component: fortranAssignee: janus
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, jaydub66
Priority: P3 Keywords: rejects-valid
Version: 4.4.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2008-11-28 21:26:57
Attachments: patch v1
patch v2

Description Tobias Burnus 2008-07-02 20:37:49 UTC
Remaining item since PR 32580 has been fixed.

Procedure pointers as function result are not yet implemented and currently rejected.

Short example:

function foo() result(bar)
  procedure() :: bar

and

function foo()
  procedure() :: foo

Long example:
http://groups.google.com/group/comp.lang.fortran/msg/7bddd7097fb985a5
Comment 1 janus 2008-11-28 21:26:55 UTC
Btw the examples in comment #0 slightly miss the point, since they lack the POINTER attribute. Correct version:

function foo() result(bar)
  procedure(),pointer :: bar

and

function foo()
  procedure(),pointer :: foo
Comment 2 janus 2008-11-30 17:50:37 UTC
Created attachment 16793 [details]
patch v1

Attached is a minimal patch, which makes the simple case work where a separate result variable is used, like in this example:

procedure(real),pointer :: p
p => foo()
print *,p(1.0)
contains
  function foo() result(bar)
    procedure(real),pointer :: bar
    bar => sin
  end function
end
Comment 3 janus 2008-11-30 22:00:03 UTC
Created attachment 16795 [details]
patch v2

This updated patch passes the testsuite without regressions and adds some additional checks.
Comment 4 janus 2008-12-02 11:59:42 UTC
Subject: Bug 36704

Author: janus
Date: Tue Dec  2 11:58:16 2008
New Revision: 142351

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142351
Log:
2008-12-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	PR fortran/38290
	* decl.c (match_result): Result may be a standard variable or a
	procedure pointer.
	* expr.c (gfc_check_pointer_assign): Additional checks for procedure
	pointer assignments.
	* primary.c (gfc_match_rvalue): Bugfix for procedure pointer
	assignments.
	* resolve.c (resolve_function): Check for attr.subroutine.
	* symbol.c (check_conflict): Addtional checks for RESULT statements.
	* trans-types.c (gfc_sym_type,gfc_get_function_type): Support procedure
	pointers as function result.


2008-12-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	PR fortran/38290
	* gfortran.dg/entry_7.f90: Modified.
	* gfortran.dg/proc_ptr_2.f90: Extended.
	* gfortran.dg/proc_ptr_3.f90: Modified.
	* gfortran.dg/proc_ptr_11.f90: New.
	* gfortran.dg/proc_ptr_12.f90: New.
	* gfortran.dg/result_1.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_11.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_12.f90
    trunk/gcc/testsuite/gfortran.dg/result_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/entry_7.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_2.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_3.f90

Comment 6 janus 2009-03-11 16:26:01 UTC
Patch: http://gcc.gnu.org/ml/fortran/2009-03/msg00044.html
Comment 7 janus 2009-04-09 09:39:24 UTC
Subject: Bug 36704

Author: janus
Date: Thu Apr  9 09:39:09 2009
New Revision: 145815

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

	PR fortran/36704
	* decl.c (add_hidden_procptr_result): New function for handling
	procedure pointer return values by adding a hidden result variable.
	(variable_decl,match_procedure_decl,gfc_match_function_decl,
	gfc_match_subroutine,gfc_match_end,attr_decl1): Handle procedure pointer
	return values.
	* parse.c (parse_interface): Add EXTERNAL attribute only after
	FUNCTION/SUBROUTINE declaration is complete.
	* primary.c (replace_hidden_procptr_result): New function for replacing
	function symbol by hidden result variable.
	(gfc_match_rvalue,match_variable): Replace symbol by hidden result
	variable.
	* resolve.c (resolve_contained_fntype,resolve_function,resolve_variable,
	resolve_symbol): Allow for procedure pointer function results.
	(resolve_fl_procedure): Conflict detection moved here from
	'check_conflict'.
	* symbol.c (gfc_check_function_type): Allow for procedure pointer
	function results.
	(check_conflict): Move some conflict detection to resolution stage.
	* trans-types.c (gfc_sym_type,gfc_get_function_type): Handle hidden
	result variables.


2009-04-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/36704
	* gfortran.dg/external_procedures_1.f90: Modified.
	* gfortran.dg/proc_ptr_result_1.f90: New.
	* gfortran.dg/proc_ptr_result_2.f90: New.
	* gfortran.dg/proc_ptr_result_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_1.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_2.f90
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/external_procedures_1.f90

Comment 8 janus 2009-04-09 09:41:19 UTC
Fixed by r145815. Closing.