re PR fortran/31600 (Better error message for redeclation of USEd symbols)
authorTobias Burnus <burnus@net-b.de>
Tue, 23 Aug 2011 12:13:34 +0000 (14:13 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Tue, 23 Aug 2011 12:13:34 +0000 (14:13 +0200)
2011-08-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/31600
        * symbol.c (gfc_add_type): Better diagnostic if redefining
        use-associated symbol.
        * module.c (gfc_use_module): Use module name as locus.

2011-08-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/31600
        * gfortran.dg/use_16.f90: New.

From-SVN: r177985

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

index 075c366f0b590d218d2919a9a8229e9d7629adad..80cee087c6b36608fa73e7fa8485e96af5a5d8d4 100644 (file)
@@ -1,3 +1,10 @@
+2011-08-23  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/31600
+       * symbol.c (gfc_add_type): Better diagnostic if redefining
+       use-associated symbol.
+       * module.c (gfc_use_module): Use module name as locus.
+
 2011-08-22  Gabriel Charette  <gchare@google.com>
 
        * cpp.c (gfc_cpp_init): Force BUILTINS_LOCATION for tokens
index aef340464c5d95eb771d43eda6d655c1f336c180..4250a170a9275c73f5ede86af7b115282db5a722 100644 (file)
@@ -5727,6 +5727,9 @@ gfc_use_module (void)
   int c, line, start;
   gfc_symtree *mod_symtree;
   gfc_use_list *use_stmt;
+  locus old_locus = gfc_current_locus;
+
+  gfc_current_locus = use_locus;
 
   filename = (char *) alloca (strlen (module_name) + strlen (MODULE_EXTENSION)
                              + 1);
@@ -5748,6 +5751,7 @@ gfc_use_module (void)
                             "intrinsic module at %C") != FAILURE)
        {
         use_iso_fortran_env_module ();
+        gfc_current_locus = old_locus;
         return;
        }
 
@@ -5756,6 +5760,7 @@ gfc_use_module (void)
                             "ISO_C_BINDING module at %C") != FAILURE)
        {
          import_iso_c_binding_module();
+         gfc_current_locus = old_locus;
          return;
        }
 
@@ -5845,6 +5850,8 @@ gfc_use_module (void)
   gfc_rename_list = NULL;
   use_stmt->next = gfc_current_ns->use_stmts;
   gfc_current_ns->use_stmts = use_stmt;
+
+  gfc_current_locus = old_locus;
 }
 
 
index 446346029ca5a99a508679f854f35d847823c4b4..126a52b9e7e8f733aa7fcde118e767795d9042f2 100644 (file)
@@ -1672,7 +1672,12 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
 
   if (type != BT_UNKNOWN && !(sym->attr.function && sym->attr.implicit_type))
     {
-      gfc_error ("Symbol '%s' at %L already has basic type of %s", sym->name,
+      if (sym->attr.use_assoc)
+       gfc_error ("Symbol '%s' at %L conflicts with symbol from module '%s', "
+                  "use-associated at %L", sym->name, where, sym->module,
+                  &sym->declared_at);
+      else
+       gfc_error ("Symbol '%s' at %L already has basic type of %s", sym->name,
                 where, gfc_basic_typename (type));
       return FAILURE;
     }
index 57454939b9fadd063f58e9a8bafbdf385c7a75ba..fa80622a4e2ac09cc29209695e3dc8cf0859e0c4 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-23  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/31600
+       * gfortran.dg/use_16.f90: New.
+
 2011-08-22  Uros Bizjak  <ubizjak@gmail.com>
            Kirill Yukhin  <kirill.yukhin@intel.com>
 
diff --git a/gcc/testsuite/gfortran.dg/use_16.f90 b/gcc/testsuite/gfortran.dg/use_16.f90
new file mode 100644 (file)
index 0000000..35176de
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!
+! PR fortran/31600
+!
+module a
+implicit none
+contains
+  integer function bar()
+    bar = 42
+  end function
+end module a
+
+use a ! { dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from module 'a'" }
+implicit none
+integer :: bar ! { dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from module 'a'" }
+end
+
+! { dg-final { cleanup-modules "a" } }