]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Implement resolution for DR 36 [PR116160]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 19 Sep 2024 14:47:12 +0000 (00:47 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 27 Sep 2024 23:00:52 +0000 (09:00 +1000)
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 <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/cpp0x/using-enum-3.C
gcc/testsuite/g++.dg/cpp2a/using-enum-11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/using53.C

index a2f94e0f363ef72e4d7b0d02f82a33ec8a641f0f..4754ef5a5229a35a19a8127de552c94d79847772 100644 (file)
@@ -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);
 
index 34f8bf4fa0bb1491375daab1c42991a89e5664b7..4638181c63cebdc8be98f631ab8a8ce06556c7d5 100644 (file)
@@ -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 (file)
index 0000000..ff99ed4
--- /dev/null
@@ -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;
+}
index e91829e939a9f061a7a90a546426a76fcf9e43da..8279c73bfc4ff53ac3c8cdaef633c7ccf381662a 100644 (file)
@@ -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)" }
 }