]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/39414 (PROCEDURE statement double declaration bug)
authorJanus Weil <janus@gcc.gnu.org>
Mon, 6 Apr 2009 08:33:31 +0000 (10:33 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Mon, 6 Apr 2009 08:33:31 +0000 (10:33 +0200)
2009-04-06  Janus Weil  <janus@gcc.gnu.org>

       PR fortran/39414
       * decl.c (match_procedure_decl): Fix double declaration problems with
       PROCEDURE statements.
       * symbol.c (gfc_add_type): Ditto.

2009-04-06  Janus Weil  <janus@gcc.gnu.org>

       PR fortran/39414
       * gfortran.dg/proc_decl_21.f90: New.

From-SVN: r145583

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/proc_decl_21.f90 [new file with mode: 0644]

index 1e5ebc621d7c06a12c6d278919247d93c17aefe7..6db6c63c41d94db45460f475eb31f2acdbd53dc6 100644 (file)
@@ -1,3 +1,10 @@
+2009-04-06  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/39414
+       * decl.c (match_procedure_decl): Fix double declaration problems with
+       PROCEDURE statements.
+       * symbol.c (gfc_add_type): Ditto.
+
 2009-04-06  Paul Thomas  <pault@gcc.gnu.org>
 
         PR fortran/36091
index 1e83d21bbe028eeea2f9c6679e478a556e2086e0..2e541471f2ba4936833820609688941cd4dda0cc 100644 (file)
@@ -4207,12 +4207,20 @@ got_ts:
       /* Set interface.  */
       if (proc_if != NULL)
        {
+          if (sym->ts.type != BT_UNKNOWN)
+           {
+             gfc_error ("Procedure '%s' at %L already has basic type of %s",
+                        sym->name, &gfc_current_locus,
+                        gfc_basic_typename (sym->ts.type));
+             return MATCH_ERROR;
+           }
          sym->ts.interface = proc_if;
          sym->attr.untyped = 1;
        }
       else if (current_ts.type != BT_UNKNOWN)
        {
-         sym->ts = current_ts;
+         if (gfc_add_type (sym, &current_ts, &gfc_current_locus) == FAILURE)
+           return MATCH_ERROR;
          sym->ts.interface = gfc_new_symbol ("", gfc_current_ns);
          sym->ts.interface->ts = current_ts;
          sym->ts.interface->attr.function = 1;
index 788823503aa6b09851d27c0402babbc567e7af56..74146165637b83281bf126cc65e73f98f33501d3 100644 (file)
@@ -1555,8 +1555,7 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
   if (sym->ts.type != BT_UNKNOWN)
     {
       const char *msg = "Symbol '%s' at %L already has basic type of %s";
-      if (!(sym->ts.type == ts->type
-           && (sym->attr.flavor == FL_PROCEDURE || sym->attr.result))
+      if (!(sym->ts.type == ts->type && sym->attr.result)
          || gfc_notification_std (GFC_STD_GNU) == ERROR
          || pedantic)
        {
@@ -1570,6 +1569,13 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
        gfc_warning (msg, sym->name, where, gfc_basic_typename (sym->ts.type));
     }
 
+  if (sym->attr.procedure && sym->ts.interface)
+    {
+      gfc_error ("Procedure '%s' at %L may not have basic type of %s", sym->name, where,
+                gfc_basic_typename (ts->type));
+      return FAILURE;
+    }
+
   flavor = sym->attr.flavor;
 
   if (flavor == FL_PROGRAM || flavor == FL_BLOCK_DATA || flavor == FL_MODULE
index d93f198b12d1f122a9fbcacd4e1c77d53d859362..3bedcb74caf8e6b7f7af1173174906f837c51f98 100644 (file)
@@ -1,4 +1,9 @@
-2009-04-06  Paul Thomas  <pault@gcc.gnu.org
+2009-04-06  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/39414
+       * gfortran.dg/proc_decl_21.f90: New.
+
+2009-04-06  Paul Thomas  <pault@gcc.gnu.org>
 
         PR fortran/36091
         * gfortran.dg/forall_13.f90: Add -fbounds-check option.
diff --git a/gcc/testsuite/gfortran.dg/proc_decl_21.f90 b/gcc/testsuite/gfortran.dg/proc_decl_21.f90
new file mode 100644 (file)
index 0000000..4fd4020
--- /dev/null
@@ -0,0 +1,32 @@
+! { dg-do compile }
+!
+! PR fortran/39414: PROCEDURE statement double declaration bug
+!
+! Discovered by Paul Thomas <pault@gcc.gnu.org>
+! Modified by Janus Weil <janus@gcc.gnu.org>
+
+
+! forbidden
+
+procedure(integer) :: a
+integer :: a   ! { dg-error "already has basic type of" }
+
+integer :: b
+procedure(integer) :: b          ! { dg-error "already has basic type of" }
+
+procedure(iabs) :: c
+integer :: c   ! { dg-error "may not have basic type of" }
+
+integer :: d
+procedure(iabs) :: d   ! { dg-error "already has basic type of" }
+
+! allowed
+
+integer :: e
+procedure() :: e
+
+procedure() :: f
+integer :: f
+
+end
+