using GNU Fortran 95 (GCC) 4.1.0 20051126 (prerelease) with '-g -pedantic -std=f95', I get a bad / no diagnostic for the following invalid code: SUBROUTINE s(n) CHARACTER(LEN=n), EXTERNAL :: a write(6,*) a(n) END SUBROUTINE s FUNCTION a(n) CHARACTER(LEN=n) :: a a="1111111" END FUNCTION a PROGRAM TEST CALL S(3) END PROGRAM TEST
Need more details? Are the 3 routines in separate files?
Reduced testcase: SUBROUTINE s(n) CHARACTER(LEN=n), EXTERNAL :: a write(6,*) a(n) END SUBROUTINE s The problem, unless I'm missing something, is that the external function a would need an explicit interface. From the draft F2003 standard, 12.3.1.1: "A procedure [...] shall have an explicit interface if it is referenced and
(In reply to comment #2) > Reduced testcase: > > SUBROUTINE s(n) > CHARACTER(LEN=n), EXTERNAL :: a > write(6,*) a(n) > END SUBROUTINE s > > The problem, unless I'm missing something, is that the external function a > would need an explicit interface. From the draft F2003 standard, 12.3.1.1: > > "A procedure [...] shall have an explicit interface if it is referenced and > Sorry, I messed up. Here's what I intended to write: "A procedure [...] shall have an explicit interface if it is referenced and [...] (3) The procedure has a result that [...] (c) has a nonassumed type parameter value that is not an initialization expression" Ifort 8.1 gives the following error message for this code: beam:~$ ifort huj.f90 fortcom: Error: huj.f90, line 2: This passed length character name has been used in an invalid context. [A] CHARACTER(LEN=n), EXTERNAL :: a -------------------------------^
There's a TODO about this in front-end resolve.c. It's a good point to start... static void resolve_formal_arglist (gfc_symbol * proc) { gfc_formal_arglist *f; gfc_symbol *sym; int i; /* TODO: Procedures whose return character length parameter is not constant or assumed must also have explicit interfaces. */
Subject: Bug number PR25087 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/2006-11/msg01058.html
Subject: Bug 25087 Author: pault Date: Wed Nov 22 00:05:10 2006 New Revision: 119077 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119077 Log: 2006-11-22 Paul Thomas <pault@gcc.gnu.org> PR fortran/25087 * resolve.c (resolve_fl_procedure): Add an error if an external automatic character length function does not have an explicit interface. 2006-11-22 Paul Thomas <pault@gcc.gnu.org> PR fortran/25087 * gfortran.dg/auto_char_len_4.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/auto_char_len_4.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 25087 Author: pault Date: Thu Nov 23 19:14:05 2006 New Revision: 119132 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119132 Log: 2006-11-23 Paul Thomas <pault@gcc.gnu.org> PR fortran/25087 * resolve.c (resolve_fl_procedure): Add an error if an external automatic character length function does not have an explicit interface. PR fortran/29652 * interface.c (check_interface1): Use a local value, instead of the dummy, as the inner iterator over interface symbols. PR fortran/29820 * trans-array.c (gfc_get_derived_type): Once done, spread the backend_decl to all identical derived types in all sibling namespaces. 2006-11-23 Paul Thomas <pault@gcc.gnu.org> PR fortran/25087 * gfortran.dg/auto_char_len_4.f90: New test. PR fortran/29652 * gfortran.dg/generic_7.f90: New test. * gfortran.dg/defined_operators_1.f90: Add new error. PR fortran/29820 * gfortran.dg/used_types_13.f90: New test. Added: branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/auto_char_len_4.f90 branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_7.f90 branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/used_types_13.f90 Modified: branches/gcc-4_2-branch/gcc/fortran/ChangeLog branches/gcc-4_2-branch/gcc/fortran/interface.c branches/gcc-4_2-branch/gcc/fortran/resolve.c branches/gcc-4_2-branch/gcc/fortran/trans-types.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/defined_operators_1.f90
Fixed on trunk and 4.2 Paul