OSDN Git Service

2006-11-22 Paul Thomas <pault@gcc.gnu.org>
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Nov 2006 00:05:10 +0000 (00:05 +0000)
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Nov 2006 00:05:10 +0000 (00:05 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119077 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/auto_char_len_4.f90 [new file with mode: 0644]

index d758a48..b9c5944 100644 (file)
@@ -1,5 +1,12 @@
 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/29652
        * interface.c (check_interface1): Use a local value, instead of
        the dummy, as the inner iterator over interface symbols.
index 5bd8296..e798070 100644 (file)
@@ -89,8 +89,6 @@ resolve_formal_arglist (gfc_symbol * proc)
   gfc_symbol *sym;
   int i;
 
-  /* TODO: Procedures whose return character length parameter is not constant
-     or assumed must also have explicit interfaces.  */
   if (proc->result != NULL)
     sym = proc->result;
   else
@@ -5529,17 +5527,25 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
        && resolve_fl_var_and_proc (sym, mp_flag) == FAILURE)
     return FAILURE;
 
-  if (sym->attr.proc == PROC_ST_FUNCTION)
+  if (sym->ts.type == BT_CHARACTER)
     {
-      if (sym->ts.type == BT_CHARACTER)
-        {
-          gfc_charlen *cl = sym->ts.cl;
-          if (!cl || !cl->length || cl->length->expr_type != EXPR_CONSTANT)
-            {
+      gfc_charlen *cl = sym->ts.cl;
+      if (!cl || !cl->length || cl->length->expr_type != EXPR_CONSTANT)
+       {
+         if (sym->attr.proc == PROC_ST_FUNCTION)
+           {
               gfc_error ("Character-valued statement function '%s' at %L must "
                          "have constant length", sym->name, &sym->declared_at);
               return FAILURE;
             }
+
+         if (sym->attr.external && sym->formal == NULL
+               && cl && cl->length && cl->length->expr_type != EXPR_CONSTANT)
+            {
+              gfc_error ("Automatic character length function '%s' at %L must "
+                         "have an explicit interface", sym->name, &sym->declared_at);
+              return FAILURE;
+            }
         }
     }
 
index 564af55..ae046ed 100644 (file)
@@ -1,5 +1,10 @@
 2006-11-22 Paul Thomas  <pault@gcc.gnu.org>
 
+       PR fortran/25087
+       * gfortran.dg/auto_char_len_4.f90: New test.
+
+2006-11-22 Paul Thomas  <pault@gcc.gnu.org>
+
        PR fortran/29652
        * gfortran.dg/generic_7.f90: New test.
        * gfortran.dg/defined_operators_1.f90: Add new error.
diff --git a/gcc/testsuite/gfortran.dg/auto_char_len_4.f90 b/gcc/testsuite/gfortran.dg/auto_char_len_4.f90
new file mode 100644 (file)
index 0000000..3749abd
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! Tests the fix for PR25087, in which the following invalid code
+! was not detected.
+!
+! Contributed by Joost VandeVondele  <jv244@cam.ac.uk>
+!
+SUBROUTINE s(n)
+  CHARACTER(LEN=n), EXTERNAL :: a ! { dg-error "must have an explicit interface" }
+  interface
+    function b (m)                ! This is OK
+      CHARACTER(LEN=m) :: b
+      integer :: m
+    end function b
+  end interface
+  write(6,*) a(n)
+  write(6,*) b(n)
+  write(6,*) c()
+contains
+    function c ()                ! This is OK
+      CHARACTER(LEN=n):: c
+      c = ""
+    end function c
+END SUBROUTINE s
+