This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Fortran] PR30973, disallow to reuse a module name or to use the module name on an ONLY clause of USE
- From: Tobias Burnus <burnus at net-b dot de>
- Cc: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 28 Feb 2007 13:27:35 +0100
- Subject: Re: [Patch, Fortran] PR30973, disallow to reuse a module name or to use the module name on an ONLY clause of USE
- References: <45E46D19.9020206@net-b.de>
I missed some part; gcc/testsuite/gfortran.dg/used_dummy_types_7.f90 had
to be updated as "atom" conflicts now in
SUBROUTINE dummy_atom_list_insert(this, atom)
USE atom, ONLY: dummy_atom
TYPE(dummy_atom), INTENT(in) :: atom
gfortran prints with the attached patch applied:
Error: Name 'atom' at (1) is an ambiguous reference to 'atom' from
current program unit
This is by the way in line with g95, NAG f95 and ifort.
Updated patch below. Full bootstrap and check-gfortraned on
x86_64-unknown-linux-gnu.
Tobias
2007-02-27 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-02-27 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.
Index: gcc/fortran/module.c
===================================================================
*** gcc/fortran/module.c (revision 122377)
--- gcc/fortran/module.c (working copy)
*************** gfc_match_use (void)
*** 619,624 ****
--- 619,632 ----
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:
*************** read_module (void)
*** 3438,3443 ****
--- 3446,3454 ----
/* 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: gcc/testsuite/gfortran.dg/use_4.f90
===================================================================
*** gcc/testsuite/gfortran.dg/use_4.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/use_4.f90 (revision 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: gcc/testsuite/gfortran.dg/used_dummy_types_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/used_dummy_types_7.f90 (revision 122401)
+++ gcc/testsuite/gfortran.dg/used_dummy_types_7.f90 (working copy)
@@ -33,12 +33,12 @@
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