Bug 25087 - Error for missing explicit interface needed.
Summary: Error for missing explicit interface needed.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks: Fortran_character 29670
  Show dependency treegraph
 
Reported: 2005-11-26 18:03 UTC by Joost VandeVondele
Modified: 2006-11-23 19:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-11-15 18:59:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2005-11-26 18:03:55 UTC
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
Comment 1 kargls 2005-11-27 04:25:36 UTC
Need more details?  Are the 3 routines in separate files?
Comment 2 eedelman 2005-11-29 12:00:12 UTC
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


Comment 3 eedelman 2005-11-29 12:06:22 UTC
(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
-------------------------------^
Comment 4 Francois-Xavier Coudert 2006-09-28 11:35:16 UTC
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.  */
Comment 5 patchapp@dberlin.org 2006-11-15 18:02:32 UTC
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
Comment 6 Paul Thomas 2006-11-22 00:05:21 UTC
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

Comment 7 Paul Thomas 2006-11-23 19:14:19 UTC
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

Comment 8 Paul Thomas 2006-11-23 19:17:06 UTC
Fixed on trunk and 4.2

Paul