------- Comment #3 from burnus at gcc dot gnu dot org 2007-02-26 21:36 ------- > Tobias, the same happens if the MODULE foo contains anything and the ONLY part > actually lists something. I omitted this to keep the testcase short.
Good news. That means that indicates that my patch does the right thing and is not too kludgy. In read_module, p = find_use_name_n (name, &j); is used to find renamed symbols. If a symbol is not in in the only list, p == NULL. Since the module name is never in the only list, we have "p = NULL". Index: module.c =================================================================== --- module.c (Revision 122328) +++ module.c @@ -3438,6 +3438,9 @@ /* 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. */ Another related bug: "use foo, only: foo" gives no error. ------------- test case ------- MODULE foo integer :: i END MODULE 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 -------------------------- Possible patch below; note: Even with the patch use bar, only foo => j use foo is possible. But as soon as one accesses foo, e.g. "foo = 5", an error is given. This is in the line with other compilers. Index: module.c =================================================================== *** module.c (revision 122328) --- 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: -- burnus at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu dot | |org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30973