[2/2] c++: Implement resolution for DR 36 [PR116160]
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Test passed
|
Commit Message
Noticed how to fix this while working on the other patch.
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
-- >8 --
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>
---
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(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/using-enum-11.C
Comments
On 9/19/24 7:56 PM, Nathaniel Shead wrote:
> Noticed how to fix this while working on the other patch.
> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
OK.
> -- >8 --
>
> 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>
> ---
> 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(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/using-enum-11.C
>
> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
> index 94b031e6be2..22a1c6aac8c 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))
> @@ -5375,8 +5381,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;
> @@ -6648,9 +6653,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 34f8bf4fa0b..4638181c63c 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 00000000000..ff99ed422d5
> --- /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 e91829e939a..8279c73bfc4 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)" }
> }
@@ -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))
@@ -5375,8 +5381,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;
@@ -6648,9 +6653,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);
@@ -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 }
}
new file mode 100644
@@ -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;
+}
@@ -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)" }
}