[PATCH] c++: Check DECL_TEMPLATE_PARM_P in duplicate_decls [PR97511]
Jason Merrill
jason@redhat.com
Wed Oct 21 20:41:33 GMT 2020
On 10/21/20 4:35 PM, Patrick Palka wrote:
> This makes duplicate_decls differentiate a TYPE_DECL for an alias
> template from a TYPE_DECL for one of its template parameters. The
> recently added assert in template_parm_to_arg revealed this latent issue
> because merging of the two TYPE_DECLs cleared the DECL_TEMPLATE_PARM_P
> flag.
>
> With this patch, we now also correctly diagnose the name shadowing in
> the below testcase (as required by [temp.local]/6).
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to
> commit?
OK.
> gcc/cp/ChangeLog:
>
> PR c++/97511
> * decl.c (duplicate_decls): Return NULL_TREE if
> DECL_TEMPLATE_PARM_P differ.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/97511
> * g++.dg/template/shadow3.C: New test.
> ---
> gcc/cp/decl.c | 3 +++
> gcc/testsuite/g++.dg/template/shadow3.C | 4 ++++
> 2 files changed, 7 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/template/shadow3.C
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 5f370e60b4e..2de4e1657fb 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -2002,6 +2002,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
> || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
> return NULL_TREE;
>
> + if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
> + return NULL_TREE;
> +
> if (!validate_constexpr_redeclaration (olddecl, newdecl))
> return error_mark_node;
>
> diff --git a/gcc/testsuite/g++.dg/template/shadow3.C b/gcc/testsuite/g++.dg/template/shadow3.C
> new file mode 100644
> index 00000000000..a5f256384ac
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/shadow3.C
> @@ -0,0 +1,4 @@
> +// PR c++/97511
> +// { dg-do compile { target c++11 } }
> +
> +template <class Z> using Z = Z; // { dg-error "shadow|declaration" }
>
More information about the Gcc-patches
mailing list