Reduced from http://gcc.gnu.org/ml/fortran/2007-10/msg00280.html The following gives the bogus error: write(lu,'(a)') 'UNIT '//UpperCase(UNAME(1)) 1 Error: Variable 'str' is used at (1) before the ENTRY statement in which it is a parameter subroutine ExportZMX(lu) implicit real(selected_real_kind(15)) (a-h,o-z) character(*),parameter :: UNAME(1:1)=(/'XXX'/) write(lu,'(a)') 'UNIT '//UpperCase(UNAME(1)) entry ExportSEQ(lu) contains function UpperCase(str) result(res) character(*),intent(in) :: str character(len(str)) res res=str end function end
The bug is not present in 4.2.2, and appeared before revision 129038.
It is not in gcc version 4.3.0 20070713.
Slightly further reduced test: subroutine ExportZMX(lu) implicit none integer :: lu interface function UpperCase(str) character(*),intent(in) :: str character(len(str)) :: UpperCase ! Rejected ! character(1) :: UpperCase ! Works end function UpperCase end interface character, parameter :: UNAME ='X' write(lu,'(a)') 'UNIT '//UpperCase(UNAME) ! Rejected ! write(lu,'(a)') UpperCase(UNAME) ! Works entry ExportSEQ(lu) end
I'm not completely sure which bug is triggered that, but the error occurs for the expression character(len(str)) :: UpperCase "str" is a dummy (of the interface function UpperCase) and despite being a dummy it is not a dummy of the current entry function (which is "ExportZMX"). The check assumes: Dummy + not-dummy of current function => Dummy of another Entry -> invalid. The solution is to add a check whether the dummy in in the current name space or not. I could not find any bit in the patches which caused this, but my un-educated guess would be http://gcc.gnu.org/viewcvs?view=rev&revision=127939 which added some character substring fixes. Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 129495) +++ gcc/fortran/resolve.c (working copy) @@ -3935,7 +3935,7 @@ resolve_variable (gfc_expr *e) bool seen; /* If the symbol is a dummy... */ - if (sym->attr.dummy) + if (sym->attr.dummy && sym->ns == gfc_current_ns) { entry = gfc_current_ns->entries; seen = false; @@ -3952,7 +3952,7 @@ resolve_variable (gfc_expr *e) if (!seen) { if (specification_expr) - gfc_error ("Variable '%s',used in a specification expression, " + gfc_error ("Variable '%s', used in a specification expression, " "is referenced at %L before the ENTRY statement " "in which it is a parameter", sym->name, &cs_base->current->loc);
Subject: Bug number PR 33818 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-10/msg01188.html
Subject: Bug 33818 Author: burnus Date: Sat Oct 20 11:34:21 2007 New Revision: 129510 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129510 Log: 2007-10-20 Tobias Burnus <burnus@net-b.de> PR fortran/33818 * resolve.c (resolve_variable): Check that symbol is in the same namespace as the entry function. 2007-10-20 Tobias Burnus <burnus@net-b.de> PR fortran/33818 * gfortran.dg/entry_dummy_ref_3.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/entry_dummy_ref_3.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
FIXED on the trunk (4.3.0).