re PR fortran/30973 ([4.1, 4.2 only] undetected name conflict: variables may be named...
authorTobias Burnus <burnus@gcc.gnu.org>
Thu, 8 Mar 2007 12:30:58 +0000 (13:30 +0100)
committerTobias Burnus <burnus@gcc.gnu.org>
Thu, 8 Mar 2007 12:30:58 +0000 (13:30 +0100)
2007-03-08  Tobias Burnus  <burnus@net-b.de>

PR fortran/30973
* module.c (read_module): Always import module name as symbol.
(gfc_match_use): Disallow module name in the only clause of
a use statement.

2007-03-08  Tobias Burnus  <burnus@net-b.de>

PR fortran/30973
* gfortran.dg/use_4.f90: New test.
* gfortran.dg/used_dummy_types_7.f90: Correct ambiguous symbol.

From-SVN: r122696

gcc/fortran/ChangeLog
gcc/fortran/module.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/use_4.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/used_dummy_types_7.f90

index 987bc50d53975afd8a15f31b950e9d23e699a7f6..3580963bdef337ef5fc9d9800003d83adf655596 100644 (file)
@@ -1,9 +1,16 @@
-2007-03-08  Paul Thomas  <pault@gcc.gnu.org>\r
-\r
-       PR fortran/31011\r
-       * expr.c (find_array_section): Correct arithmetic for section\r
-       size.\r
-\r
+2007-07-08  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/30973
+       * module.c (read_module): Always import module name as symbol.
+       (gfc_match_use): Disallow module name in the only clause of
+       a use statement.
+
+2007-03-08  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/31011
+       * expr.c (find_array_section): Correct arithmetic for section
+       size.
+
 2007-03-07  Brooks Moses  <brooks.moses@codesourcery.com>
 
        * iresolve.c (gfc_resolve_ishftc): Correct s_kind value.
index efb27e33fd34d215eb2dee1b941f21121c350966..fcae6bd7d3f7671d861f4beca342d1ea56b846b7 100644 (file)
@@ -619,6 +619,14 @@ gfc_match_use (void)
                goto cleanup;
            }
 
+         if (strcmp (new->use_name, module_name) == 0
+             || strcmp (new->local_name, module_name) == 0)
+           {
+             gfc_error ("The name '%s' at %C has already been used as "
+                        "an external module name.", module_name);
+             goto cleanup;
+           }
+
          break;
 
        case INTERFACE_USER_OP:
@@ -3438,6 +3446,9 @@ read_module (void)
          /* Get the jth local name for this symbol.  */
          p = find_use_name_n (name, &j);
 
+         if (p == NULL && strcmp (name, module_name) == 0)
+           p = name;
+
          /* Skip symtree nodes not in an ONLY clause, unless there
             is an existing symtree loaded from another USE
             statement.  */
index 6267c8ad8fd3fdab1c500bc3a9f26d726d499b59..dbc2c1fe91b859767456def23eee684dd57a96ed 100644 (file)
@@ -1,7 +1,13 @@
-2007-03-08  Paul Thomas  <pault@gcc.gnu.org>\r
-\r
-       PR fortran/31011\r
-       * gfortran.dg/parameter_array_section_2.f90: New test.\r
+2007-03-08  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/30973
+       * gfortran.dg/use_4.f90: New test.
+       * gfortran.dg/used_dummy_types_7.f90: Correct ambiguous symbol.
+
+2007-03-08  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/31011
+       * gfortran.dg/parameter_array_section_2.f90: New test.
 
 2007-03-08  Volker Reichelt  <reichelt@netcologne.de>
 
diff --git a/gcc/testsuite/gfortran.dg/use_4.f90 b/gcc/testsuite/gfortran.dg/use_4.f90
new file mode 100644 (file)
index 0000000..43d94bc
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do "compile" }
+! PR fortran/30973
+! Using symbols with the name of the module
+
+module foo
+  integer :: i
+end module foo
+
+module bar
+  integer :: j
+end module bar
+
+module test
+  use foo, only:
+  integer :: foo ! { dg-error "cannot have a type" }
+end module test
+
+module test2
+  use bar, only: foo => j
+  use foo ! ok, unless foo is accessed
+end module test2
+
+module test3
+  use bar, only: foo => j
+  use foo ! ok, unless foo is accessed
+  foo = 5 ! { dg-error "is an ambiguous reference to 'j'" }
+end module test3
+
+program test_foo
+  use foo, only: foo  ! { dg-error "been used as an external module name" }
+  use foo, only: i => foo! { dg-error "been used as an external module name" }
+  use foo, only: foo => i! { dg-error "been used as an external module name" }
+end program
index 9e591b23ea385efb10011de8870c9ad8ec75e882..b0acc51409f441dc67c9d2b28466ab82ead87db2 100644 (file)
@@ -33,12 +33,12 @@ END MODULE
 
 MODULE list
 INTERFACE
-  SUBROUTINE dummy_atom_list_insert(this, atom)
+  SUBROUTINE dummy_atom_list_insert(this, atom2)
     USE types, ONLY: dummy_atom_list
     USE atom, ONLY: dummy_atom
 
     TYPE(dummy_atom_list), INTENT(inout) :: this
-    TYPE(dummy_atom), INTENT(in)         :: atom
+    TYPE(dummy_atom), INTENT(in)         :: atom2
   END SUBROUTINE
 END INTERFACE
 END MODULE