Created attachment 25258 [details] just compile it ICE in gfc_typenode_for_spec at fortran/trans-types.c
With GCC 4.3:: interface res 1 Error: VARIABLE attribute of 'res' conflicts with PROCEDURE attribute at (1) Having a generic name which is the same as the result variable looks wrong ... I think gfortran stopped rejecting the code in decl.c/symbol.c since 4.4 when procedure-pointer (results) were allowed - such as in the following valid example: function f() result(res) interface subroutine res end subroutine end interface pointer :: res res => null() end
Note: We get the correct error message (twice, unfortunately) for: function f() result(res) interface res subroutine sub end subroutine end interface end function f() result(res) 1 Error: PROCEDURE attribute conflicts with RESULT attribute in 'res' at (1) but not when the interface is empty: interface res end interface
One way to reject it would be: Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 178778) +++ gcc/fortran/resolve.c (working copy) @@ -10567,6 +10567,12 @@ "in '%s' at %L", sym->name, &sym->declared_at); return FAILURE; } + if (sym->attr.generic && sym->attr.result) + { + gfc_error ("GENERIC attribute conflicts with RESULT attribute " + "in '%s' at %L", sym->name, &sym->declared_at); + return FAILURE; + } if (sym->attr.external && sym->attr.function && ((sym->attr.if_source == IFSRC_DECL && !sym->attr.procedure) || sym->attr.contained))
Or better: Index: gcc/fortran/symbol.c =================================================================== --- gcc/fortran/symbol.c (revision 178778) +++ gcc/fortran/symbol.c (working copy) @@ -373,7 +373,7 @@ check_conflict (symbol_attribute *attr, const char *volatile_ = "VOLATILE", *is_protected = "PROTECTED", *is_bind_c = "BIND(C)", *procedure = "PROCEDURE", *asynchronous = "ASYNCHRONOUS", *codimension = "CODIMENSION", - *contiguous = "CONTIGUOUS"; + *contiguous = "CONTIGUOUS", *generic = "GENERIC"; static const char *threadprivate = "THREADPRIVATE"; const char *a1, *a2; @@ -490,8 +490,6 @@ check_conflict (symbol_attribute *attr, const char conf (in_common, codimension); conf (in_common, result); - conf (dummy, result); - conf (in_equivalence, use_assoc); conf (in_equivalence, codimension); conf (in_equivalence, dummy); @@ -503,7 +501,9 @@ check_conflict (symbol_attribute *attr, const char conf (in_equivalence, allocatable); conf (in_equivalence, threadprivate); + conf (dummy, result); conf (entry, result); + conf (generic, result); conf (function, subroutine);
The patch in comment #4 regtests cleanly. Will commit as obvious.
Author: janus Date: Tue Sep 13 18:37:33 2011 New Revision: 178829 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178829 Log: 2011-09-13 Janus Weil <janus@gcc.gnu.org> PR fortran/50379 * symbol.c (check_conflict): Check conflict between GENERIC and RESULT attributes. 2011-09-13 Janus Weil <janus@gcc.gnu.org> PR fortran/50379 * gfortran.dg/result_2.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/result_2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/symbol.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk with r178829. Closing. Thanks for the report!