https://gcc.gnu.org/g:2196a20b82bdde2aeb099bcfd164fa29a698e837

commit r15-3939-g2196a20b82bdde2aeb099bcfd164fa29a698e837
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Fri Sep 20 00:47:12 2024 +1000

    c++: Implement resolution for DR 36 [PR116160]
    
    This implements part of P1787 to no longer complain about redeclaring an
    entity via using-decl other than in a class scope.
    
            PR c++/116160
    
    gcc/cp/ChangeLog:
    
            * name-lookup.cc (supplement_binding): Allow redeclaration via
            USING_DECL if not in class scope.
            (do_nonmember_using_decl): Remove function-scope exemption.
            (push_using_decl_bindings): Remove outdated comment.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/using-enum-3.C: No longer expect an error.
            * g++.dg/lookup/using53.C: Remove XFAIL.
            * g++.dg/cpp2a/using-enum-11.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Diff:
---
 gcc/cp/name-lookup.cc                      | 12 +++++++-----
 gcc/testsuite/g++.dg/cpp0x/using-enum-3.C  |  2 +-
 gcc/testsuite/g++.dg/cpp2a/using-enum-11.C |  9 +++++++++
 gcc/testsuite/g++.dg/lookup/using53.C      |  2 +-
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index a2f94e0f363e..4754ef5a5229 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -2874,6 +2874,12 @@ supplement_binding (cxx_binding *binding, tree decl)
                 "%<-std=c++2c%> or %<-std=gnu++2c%>");
       binding->value = name_lookup::ambiguous (decl, binding->value);
     }
+  else if (binding->scope->kind != sk_class
+          && TREE_CODE (decl) == USING_DECL
+          && decls_match (target_bval, target_decl))
+    /* Since P1787 (DR 36) it is OK to redeclare entities via using-decl,
+       except in class scopes.  */
+    ok = false;
   else
     {
       if (!error_operand_p (bval))
@@ -5377,8 +5383,7 @@ do_nonmember_using_decl (name_lookup &lookup, bool 
fn_scope_p,
   else if (value
           /* Ignore anticipated builtins.  */
           && !anticipated_builtin_p (value)
-          && (fn_scope_p
-              || !decls_match (lookup.value, strip_using_decl (value))))
+          && !decls_match (lookup.value, strip_using_decl (value)))
     {
       diagnose_name_conflict (lookup.value, value);
       failed = true;
@@ -6651,9 +6656,6 @@ push_using_decl_bindings (name_lookup *lookup, tree name, 
tree value)
       type = binding->type;
     }
 
-  /* DR 36 questions why using-decls at function scope may not be
-     duplicates.  Disallow it, as C++11 claimed and PR 20420
-     implemented.  */
   if (lookup)
     do_nonmember_using_decl (*lookup, true, true, &value, &type);
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C 
b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C
index 34f8bf4fa0bb..4638181c63ce 100644
--- a/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C
+++ b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C
@@ -9,7 +9,7 @@
 void f ()
 {
   enum e { a };
-  using e::a;  // { dg-error "redeclaration" }
+  using e::a;  // { dg-bogus "redeclaration" "P1787" }
   // { dg-error "enum" "" { target { ! c++2a } } .-1 }
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C 
b/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C
new file mode 100644
index 000000000000..ff99ed422d5f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C
@@ -0,0 +1,9 @@
+// PR c++/116160
+// { dg-do compile { target c++20 } }
+
+enum class Blah { b };
+void foo() {
+  using Blah::b;
+  using Blah::b;
+  using enum Blah;
+}
diff --git a/gcc/testsuite/g++.dg/lookup/using53.C 
b/gcc/testsuite/g++.dg/lookup/using53.C
index e91829e939a9..8279c73bfc4f 100644
--- a/gcc/testsuite/g++.dg/lookup/using53.C
+++ b/gcc/testsuite/g++.dg/lookup/using53.C
@@ -52,5 +52,5 @@ void
 f ()
 {
   using N::i;
-  using N::i;       // { dg-bogus "conflicts" "See P1787 (CWG36)" { xfail 
*-*-* } }
+  using N::i;       // { dg-bogus "conflicts" "See P1787 (CWG36)" }
 }

Reply via email to