Consider the following set of modules: module a1 contains subroutine myRoutine end subroutine end module module a2 contains subroutine myRoutine end subroutine end module module b contains subroutine otherRoutine use a1 use a2 call myRoutine ! this is ambiguous ! end subroutine subroutine myRoutine end subroutine myRoutine ! this is not ambiguous ! end module Feeding this to gfortran gives two errors: all.f90:19.18: call myRoutine ! this is ambiguous ! 1 Error: Name 'myroutine' at (1) is an ambiguous reference to 'myroutine' from module 'a1' all.f90:23.52: end subroutine myRoutine ! this is not ambiguous ! 1 Error: Name 'myroutine' at (1) is an ambiguous reference to 'myroutine' from module 'a1' This first error is ok, the second is bogus. Same for all gfortran versions I tried (4.3.3, 4.4.0 and trunk).
Something like this should do it: Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (Revision 146826) +++ gcc/fortran/parse.c (Arbeitskopie) @@ -3310,7 +3310,7 @@ gfc_fixup_sibling_symbols (gfc_symbol *s sym->attr.referenced = 1; for (ns = siblings; ns; ns = ns->sibling) { - gfc_find_sym_tree (sym->name, ns, 0, &st); + st = gfc_find_symtree (ns->sym_root, sym->name); if (!st || (st->n.sym->attr.dummy && ns == st->n.sym->ns)) goto fixup_contained; It seems a bit unfortunate that we have two functions with almost the same name (gfc_find_sym_tree and gfc_find_symtree), which do almost the same, but not quite. The little difference is important here. Maybe one of these functions should be renamed to make the usage clearer?
Subject: Bug 39930 Author: janus Date: Tue Apr 28 09:44:36 2009 New Revision: 146880 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146880 Log: 2009-04-28 Janus Weil <janus@gcc.gnu.org> PR fortran/39930 PR fortran/39931 * expr.c (gfc_check_pointer_assign): Correctly detect if the left hand side is a pointer. * parse.c (gfc_fixup_sibling_symbols): Don't check for ambiguity. 2009-04-28 Janus Weil <janus@gcc.gnu.org> PR fortran/39930 PR fortran/39931 * gfortran.dg/ambiguous_reference_2.f90: New. * gfortran.dg/pointer_assign_7.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/ambiguous_reference_2.f90 trunk/gcc/testsuite/gfortran.dg/pointer_assign_7.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/fortran/parse.c trunk/gcc/testsuite/ChangeLog
Fixed with r146880. Closing.