public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: substituting CONST_DECL_USING_P enumerator [PR103081]
Date: Fri, 2 Dec 2022 14:37:08 -0500	[thread overview]
Message-ID: <befa364c-2feb-b75c-36bb-03513debc673@redhat.com> (raw)
In-Reply-To: <20221202190110.3491914-1-ppalka@redhat.com>

On 12/2/22 14:01, Patrick Palka wrote:
> We implement using enum at class scope by injecting clones of the enum's
> CONST_DECLs as fields of the class, for which CONST_DECL_USING_P is
> true, so that qualified lookup naturally finds the enumerators.
> Substitution into such a CONST_DECL currently ICEs however, because we
> assume the DECL_CONTEXT is always the ENUMERAL_TYPE (which has TYPE_VALUES)
> but in this case it's the RECORD_TYPE of the class scope (which has
> TYPE_FIELDS).
> 
> Since these CONST_DECLs appear to always be non-dependent, this patch
> fixes this by shortcutting substitution for CONST_DECLs which have a
> non-dependent scope.  This subsumes the existing (and seemingly dead)
> DECL_NAMESPACE_SCOPE_P early exit test and also benefits substitution
> into ordinary non-dependent CONST_DECLs.
> 
> Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for
> trunk/12?

OK.

> 	PR c++/103081
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (tsubst_copy) <case CONST_DECL>: Generalize
> 	early exit test for namespace-scope decls to check dependence of
> 	the enclosing scope instead.  Remove dead args early exit test.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/using-enum-10.C: New test.
> 	* g++.dg/cpp2a/using-enum-10a.C: New test.
> ---
>   gcc/cp/pt.cc                                |  7 +------
>   gcc/testsuite/g++.dg/cpp2a/using-enum-10.C  | 16 ++++++++++++++++
>   gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C | 18 ++++++++++++++++++
>   3 files changed, 35 insertions(+), 6 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/using-enum-10.C
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 31691618d1b..bc8ea06ceae 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -17066,13 +17066,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   
>   	if (DECL_TEMPLATE_PARM_P (t))
>   	  return tsubst_copy (DECL_INITIAL (t), args, complain, in_decl);
> -	/* There is no need to substitute into namespace-scope
> -	   enumerators.  */
> -	if (DECL_NAMESPACE_SCOPE_P (t))
> +	if (!uses_template_parms (DECL_CONTEXT (t)))
>   	  return t;
> -	/* If ARGS is NULL, then T is known to be non-dependent.  */
> -	if (args == NULL_TREE)
> -	  return scalar_constant_value (t);
>   
>   	/* Unfortunately, we cannot just call lookup_name here.
>   	   Consider:
> diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C b/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C
> new file mode 100644
> index 00000000000..98fe0644729
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C
> @@ -0,0 +1,16 @@
> +// PR c++/103081
> +// { dg-do compile { target c++20 } }
> +
> +enum class Pig { OINK };
> +
> +struct Hog {
> +  using enum Pig;
> +  Hog(Pig) { }
> +};
> +
> +template<int>
> +void pen() {
> +  Hog(Hog::OINK);
> +}
> +
> +template void pen<0>();
> diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C b/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C
> new file mode 100644
> index 00000000000..43688e69b19
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C
> @@ -0,0 +1,18 @@
> +// A version of using-enum-10.C where Hog is a template.
> +// PR c++/103081
> +// { dg-do compile { target c++20 } }
> +
> +enum class Pig { OINK };
> +
> +template<int>
> +struct Hog {
> +  using enum Pig;
> +  Hog(Pig) { OINK; }
> +};
> +
> +template<int N>
> +void pen() {
> +  Hog<N>(Hog<N>::OINK);
> +}
> +
> +template void pen<0>();


      reply	other threads:[~2022-12-02 19:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 19:01 Patrick Palka
2022-12-02 19:37 ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=befa364c-2feb-b75c-36bb-03513debc673@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).