Fortran: diagnose USE associated symbols in COMMON blocks [PR108453]
authorHarald Anlauf <anlauf@gmx.de>
Sat, 28 Jan 2023 16:59:23 +0000 (17:59 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 28 Jan 2023 20:57:54 +0000 (21:57 +0100)
gcc/fortran/ChangeLog:

PR fortran/108453
* match.cc (gfc_match_common): A USE associated name shall not appear
in a COMMON block (F2018:C8121).

gcc/testsuite/ChangeLog:

PR fortran/108453
* gfortran.dg/common_27.f90: New test.

gcc/fortran/match.cc
gcc/testsuite/gfortran.dg/common_27.f90 [new file with mode: 0644]

index 5e933c1..5eb6d0e 100644 (file)
@@ -5345,6 +5345,16 @@ gfc_match_common (void)
                goto cleanup;
            }
 
+         /* F2018:R874:  common-block-object is variable-name [ (array-spec) ]
+            F2018:C8121: A variable-name shall not be a name made accessible
+            by use association.  */
+         if (sym->attr.use_assoc)
+           {
+             gfc_error ("Symbol %qs at %C is USE associated from module %qs "
+                        "and cannot occur in COMMON", sym->name, sym->module);
+             goto cleanup;
+           }
+
          /* Deal with an optional array specification after the
             symbol name.  */
          m = gfc_match_array_spec (&as, true, true);
diff --git a/gcc/testsuite/gfortran.dg/common_27.f90 b/gcc/testsuite/gfortran.dg/common_27.f90
new file mode 100644 (file)
index 0000000..dcde5de
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/108453 - a use associated variable cannot occur in COMMON
+! Contributed by G.Steinmetz
+
+module m
+  type t
+  end type
+  real :: r
+end
+program p
+  use m, only: t, r
+  common t      ! { dg-error "USE associated from module" }
+  common /cm/ r ! { dg-error "USE associated from module" }
+end