The one of following valid Fortran 90 functions is rejected: While the first function "func" works and has function name = result name, the second ("func2"), which uses RESULT(), is rejected with the error message: Error: The type for function 'func2' at (1) is not accessible type(t) function func() type t sequence integer :: i = 5 end type t end function func type(t) function func2() result(res) type t sequence integer :: i = 5 end type t end function func2
type(t) function func2() result(res) type t sequence integer :: i = 5 end type t res%i = 2 end function func2 causes a segmentation fault! Confirmed Paul
The problem is somehow that for the second parsing using decl.c's gfc_match_decl_type_spec one has in: else if (ts->kind == -1) { int iface = gfc_state_stack->previous->state != COMP_INTERFACE || gfc_current_ns->has_import_set; if (gfc_find_symbol (name, NULL, iface, &sym)) { gfc_error ("Type name '%s' at %C is ambiguous", name); return MATCH_ERROR; } the result sym == NULL with RESULT() but not without RESULT(); while "iface==1" and name == "t" for both cases.
Patch: Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (Revision 156433) +++ gcc/fortran/parse.c @@ -111,7 +111,7 @@ decode_specification_statement (void) match ("import", gfc_match_import, ST_IMPORT); match ("use", gfc_match_use, ST_USE); - if (gfc_current_block ()->ts.type != BT_DERIVED) + if (gfc_current_block ()->result->ts.type != BT_DERIVED) goto end_of_block; match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION);
Subject: Bug 42650 Author: burnus Date: Tue Feb 2 13:05:50 2010 New Revision: 156449 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156449 Log: 2010-02-02 Tobias Burnus <burnus@net-b.de> PR fortran/42650 * parse.c (decode_specification_statement): Use sym->result not * sym. 2010-02-02 Tobias Burnus <burnus@net-b.de> PR fortran/42650 * gfortran.dg/func_result_5.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/func_result_5.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/parse.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 42650 Author: burnus Date: Tue Feb 2 14:27:24 2010 New Revision: 156450 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156450 Log: 2010-02-02 Tobias Burnus <burnus@net-b.de> PR fortran/42650 * parse.c (decode_specification_statement): Use sym->result not * sym. 2010-02-02 Tobias Burnus <burnus@net-b.de> PR fortran/42650 * gfortran.dg/func_result_5.f90: New test. Added: branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/func_result_5.f90 Modified: branches/gcc-4_4-branch/gcc/fortran/ChangeLog branches/gcc-4_4-branch/gcc/fortran/parse.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
FIXED on the trunk (4.5) and 4.4 branch.