Bug 34657 - program-unit MY_SUB imports symbol MY_SUB
program-unit MY_SUB imports symbol MY_SUB
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: accepts-invalid
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-03 20:12 UTC by Joost VandeVondele
Modified: 2011-07-18 06:20 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-04 07:29:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2008-01-03 20:12:27 UTC
The following is non-standard and the compiler should probably generate a
warning/error with '-pedantic -std=f95', but does not do so with
gcc version 4.3.0 20080103 (experimental) [trunk revision 131300] (GCC)

module test_mod
interface
  subroutine my_sub (a)
    real a
  end subroutine
end interface
end module

subroutine my_sub (a)
  use test_mod
  real a
  print *, a
end subroutine

END
Comment 1 Tobias Burnus 2008-01-04 07:29:49 UTC
NAG f95 and g95 print an error:
  Error: USE TEST_MOD in program-unit MY_SUB imports symbol MY_SUB
  Error: Module 'test_mod' at (1) redefines the current program unit 'my_sub'

ifort prints nothing by default and with -stand f95:
  Warning: An interface-block in a subprogram shall not contain an interface-body for a procedure defined by that subprogram.   [MY_SUB]
Comment 2 Tobias Burnus 2011-07-17 11:54:40 UTC
Draft patch:

--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -4278,6 +4278,13 @@ check_for_ambiguous (gfc_symbol *st_sym, pointer_info *info)
   module_locus locus;
   symbol_attribute attr;
 
+  if (st_sym->ns->proc_name && st_sym->name == st_sym->ns->proc_name->name)
+    {
+      gfc_error ("'%s' of module '%s' imported at %C is also the name of the "
+                "current program unit", st_sym->name, module_name);
+      return true;
+    }
+
   rsym = info->u.rsym.sym;
   if (st_sym == rsym)
     return false;
Comment 3 Thomas Koenig 2011-07-17 15:24:02 UTC
(In reply to comment #2)

The patch causes two "regressions".

The first one, in interface_3.f90, triggers because the error message
from this patch takes precedence over the "ambiguous" error message
before. This should be fine with changing the error message in the
test case.

The second one, in generic_17.f90, is simply an incorrect test case,
which is very much like the one from the test case.

For the test case for this PR, please also add a test case like

module test_mod
interface
  subroutine my_sub (a)
    real a
  end subroutine
end interface
end module

subroutine my_sub (a)
  use test_mod, gugu => my_sub
  real a
  print *, a
end subroutine

END

(which is OK, and which passes for your patch).
Comment 4 Tobias Burnus 2011-07-17 19:57:13 UTC
Author: burnus
Date: Sun Jul 17 19:57:10 2011
New Revision: 176375

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176375
Log:
2011-07-17  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34657
        * module.c (check_for_ambiguous): Check whether the name is
        * matches
        the current program unit.

2011-07-17  Tobias Burnus  <burnus@net-b.de>
            Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/34657
        * gfortran.dg/generic_17.f90: Fix testcase.
        * gfortran.dg/interface_3.f90: Add dg-error.
        * gfortran.dg/use_14.f90: New.
        * gfortran.dg/use_15.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/use_14.f90
    trunk/gcc/testsuite/gfortran.dg/use_15.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/generic_17.f90
    trunk/gcc/testsuite/gfortran.dg/interface_3.f90
Comment 5 Tobias Burnus 2011-07-17 20:17:42 UTC
FIXED on the trunk (4.7). Thanks for the bug report - and sorry that it took 3 years to fix it.
Comment 6 Tobias Burnus 2011-07-18 06:20:23 UTC
(In reply to comment #5)
> FIXED on the trunk (4.7). Thanks for the bug report - and sorry that it took 3
> years to fix it.

Really close as FIXED