https://gcc.gnu.org/g:394e626ed19a73b6c30ce62c6be9148357c2a43d

commit r16-9745-g394e626ed19a73b6c30ce62c6be9148357c2a43d
Author: Jason Merrill <[email protected]>
Date:   Wed Oct 7 17:23:39 2026 -0400

    c++/modules: redeclaring built-ins [PR122774]
    
    Here we merged the export from _a with the built-in declaration in _b, but
    the latter is still hidden in the overload set.  Then when we go to push a
    new declaration we ignore the built-in one.  But since they've already been
    merged, we end up with two of the same decl in the overload set.  Fixed by
    checking DECL_IS_UNDECLARED_BUILTIN instead, as that is no longer true after
    merging.
    
            PR c++/122774
    
    gcc/cp/ChangeLog:
    
            * name-lookup.cc (pushdecl): Check DECL_IS_UNDECLARED_BUILTIN rather
            than iter.hidden_p ().
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/gmf-7_a.C: New test.
            * g++.dg/modules/gmf-7_b.C: New test.

Diff:
---
 gcc/cp/name-lookup.cc                  | 2 +-
 gcc/testsuite/g++.dg/modules/gmf-7_a.C | 5 +++++
 gcc/testsuite/g++.dg/modules/gmf-7_b.C | 5 +++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 09c83e18d6f7..45c2976d698b 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -4073,7 +4073,7 @@ pushdecl (tree decl, bool hiding)
          for (ovl_iterator iter (oldi); iter; ++iter)
            if (iter.using_p ())
              ; /* Ignore using decls here.  */
-           else if (iter.hidden_p ()
+           else if (DECL_IS_UNDECLARED_BUILTIN (*iter)
                     && TREE_CODE (*iter) == FUNCTION_DECL
                     && DECL_LANG_SPECIFIC (*iter)
                     && DECL_MODULE_IMPORT_P (*iter))
diff --git a/gcc/testsuite/g++.dg/modules/gmf-7_a.C 
b/gcc/testsuite/g++.dg/modules/gmf-7_a.C
new file mode 100644
index 000000000000..21db8a445946
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gmf-7_a.C
@@ -0,0 +1,5 @@
+// PR c++/122774
+// { dg-additional-options "-fmodules" }
+
+export module M;
+export extern "C" int scanf(const char *, ...);
diff --git a/gcc/testsuite/g++.dg/modules/gmf-7_b.C 
b/gcc/testsuite/g++.dg/modules/gmf-7_b.C
new file mode 100644
index 000000000000..18f79a42b767
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gmf-7_b.C
@@ -0,0 +1,5 @@
+// { dg-additional-options "-fmodules" }
+import M;
+extern "C" int scanf(const char *, ...);
+int scanf(const char *, ...);
+using ::scanf;

Reply via email to