diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-09-20 00:47:12 +1000 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-09-28 09:00:52 +1000 |
commit | 2196a20b82bdde2aeb099bcfd164fa29a698e837 (patch) | |
tree | 120cf7dfec42883c9d47aba40f9083ecef1a05f8 /gcc | |
parent | b9ac51a843f9dc807b00ab7f49f64968807a4ee8 (diff) | |
download | gcc-2196a20b82bdde2aeb099bcfd164fa29a698e837.zip gcc-2196a20b82bdde2aeb099bcfd164fa29a698e837.tar.gz gcc-2196a20b82bdde2aeb099bcfd164fa29a698e837.tar.bz2 |
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 <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/name-lookup.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/using-enum-3.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/using-enum-11.C | 9 | ||||
-rw-r--r-- | 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 a2f94e0..4754ef5 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 34f8bf4..4638181 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 0000000..ff99ed4 --- /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 e91829e..8279c73 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)" } } |