]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Also check conflicting internal-linkage entities
authorNathaniel Shead <nathanieloshead@gmail.com>
Fri, 26 Sep 2025 12:03:24 +0000 (22:03 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sun, 5 Oct 2025 10:37:32 +0000 (21:37 +1100)
While investigating another issue I noticed that the condition in
check_module_override seems incorrect: the wording in [basic.link] p11
has no exceptions for internal-linkage entities.

gcc/cp/ChangeLog:

* name-lookup.cc (check_module_override): Remove check for
TREE_PUBLIC when checking mergeable entities.

gcc/testsuite/ChangeLog:

* g++.dg/modules/namespace-1_c.C: Adjust to expect errors.
* g++.dg/modules/namespace-2_b.C: Likewise.
* g++.dg/modules/namespace-3_a.C: Removed.
* g++.dg/modules/namespace-3_b.C: Removed.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/modules/namespace-1_c.C
gcc/testsuite/g++.dg/modules/namespace-2_b.C
gcc/testsuite/g++.dg/modules/namespace-3_a.C [deleted file]
gcc/testsuite/g++.dg/modules/namespace-3_b.C [deleted file]

index 8d7fc06f6988e37594fa689401ae7316274e5983..85c7fcc7a6e8095510ae80e8a27024ec702731e0 100644 (file)
@@ -3882,7 +3882,7 @@ check_module_override (tree decl, tree mvec, bool hiding,
          }
       }
 
-  if (TREE_PUBLIC (scope) && TREE_PUBLIC (STRIP_TEMPLATE (decl))
+  if (TREE_PUBLIC (scope)
       /* Namespaces are dealt with specially in
         make_namespace_finish.  */
       && !(TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl)))
index 748ef5d79a4bf42a6c3bd218e7d1d6ff7fad8d20..e4f81b6bea6611fc484723a3efec6cbeab7dd1c1 100644 (file)
@@ -1,13 +1,7 @@
 // { dg-additional-options "-fmodules-ts" }
-// The indirect import of frob, with namespaces impl and ompl doesn't
-// affect us.
-static int impl;
-import Frink;
 
-static int ompl;
+static int impl;  // IF but no diagnostic required: impl@Frob not reachable from here
+
+import Frink;
 
-void corge (int x)
-{
-  impl = x;
-  ompl = frab (x);
-}
+static int ompl;  // { dg-error "different kind" }
index 6ab5113c23abf5ec51351e3ce7eee0e814690f8e..d71c630c75e6415591230f3a342a4944ad8cf531 100644 (file)
@@ -2,16 +2,5 @@
 
 import foo;
 
-static int also_not_exported; // ok
-
-void X ()
-{
-  implicit_export::bob ();
-}
-
+static int also_not_exported; // { dg-error "different kind" }
 static int implicit_export; // { dg-error "different kind" }
-
-void Y ()
-{
-  also_not_exported = 1;
-}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-3_a.C b/gcc/testsuite/g++.dg/modules/namespace-3_a.C
deleted file mode 100644 (file)
index 8e9508d..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Check namespace needed only by internal reference is not made visible
-// { dg-additional-options "-fmodules-ts" }
-
-export module frob;
-// { dg-module-cmi frob }
-
-namespace silent 
-{
-  namespace inner 
-  {
-    static int X () 
-    {
-      return 1;
-    }
-  }
-}
-
-export int f (int y)
-{
-  return y + silent::inner::X ();
-}
diff --git a/gcc/testsuite/g++.dg/modules/namespace-3_b.C b/gcc/testsuite/g++.dg/modules/namespace-3_b.C
deleted file mode 100644 (file)
index f779ffe..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// { dg-additional-options "-fmodules-ts" }
-
-import frob;
-
-int x = silent; // { dg-error "not declared" }
-
-static int silent;
-
-int user ()
-{
-  return f (silent);
-}