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>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: constraint matching, TEMPLATE_ID_EXPR, current inst
Date: Thu, 20 Oct 2022 12:21:41 -0400	[thread overview]
Message-ID: <a6f5b2a3-f11c-5a9b-5d9a-d96df2d1660f@redhat.com> (raw)
In-Reply-To: <fe799517-760d-671f-1f84-c6d590a53230@idea>

On 9/17/22 10:31, Patrick Palka wrote:
> On Sat, 17 Sep 2022, Jason Merrill wrote:
> 
>> On 9/16/22 10:59, Patrick Palka wrote:
>>> On Fri, 16 Sep 2022, Jason Merrill wrote:
>>>
>>>> On 9/15/22 11:58, Patrick Palka wrote:
>>>>> Here we're crashing during constraint matching for the instantiated
>>>>> hidden friends due to two issues with dependent substitution into a
>>>>> TEMPLATE_ID_EXPR naming a template from the current instantiation
>>>>> (as performed from maybe_substitute_reqs_for for C<3> with T=T):
>>>>>
>>>>>      * tsubst_copy substitutes into such a TEMPLATE_DECL by looking it
>>>>>        up from the substituted class scope.  But for this to not fail
>>>>> when
>>>>>        the args are dependent, we need to pass entering_scope=true for
>>>>> the
>>>>>        class scope substitution so that we obtain the primary template
>>>>> type
>>>>>        A<T> (which has TYPE_BINFO) instead of the implicit instantiation
>>>>>        A<T> (which doesn't).
>>>>>      * lookup_and_finish_template_variable shouldn't instantiate a
>>>>>        TEMPLATE_ID_EXPR that names a TEMPLATE_DECL which has more than
>>>>>        one level of (unsubstituted) parameters (such as A<T>::C).
>>>>>
>>>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
>>>>> trunk?
>>>>>
>>>>> gcc/cp/ChangeLog:
>>>>>
>>>>> 	* pt.cc (lookup_and_finish_template_variable): Don't
>>>>> 	instantiate if the template's scope is dependent.
>>>>> 	(tsubst_copy) <case TEMPLATE_DECL>: Pass entering_scope=true
>>>>> 	when substituting the class scope.
>>>>>
>>>>> gcc/testsuite/ChangeLog:
>>>>>
>>>>> 	* g++.dg/cpp2a/concepts-friend10.C: New test.
>>>>> ---
>>>>>     gcc/cp/pt.cc                                  | 14 +++++++------
>>>>>     .../g++.dg/cpp2a/concepts-friend10.C          | 21
>>>>> +++++++++++++++++++
>>>>>     2 files changed, 29 insertions(+), 6 deletions(-)
>>>>>     create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend10.C
>>>>>
>>>>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>>>>> index db4e808adec..bfcbe0b8670 100644
>>>>> --- a/gcc/cp/pt.cc
>>>>> +++ b/gcc/cp/pt.cc
>>>>> @@ -10475,14 +10475,15 @@ tree
>>>>>     lookup_and_finish_template_variable (tree templ, tree targs,
>>>>>     				     tsubst_flags_t complain)
>>>>>     {
>>>>> -  templ = lookup_template_variable (templ, targs);
>>>>> -  if (!any_dependent_template_arguments_p (targs))
>>>>> +  tree var = lookup_template_variable (templ, targs);
>>>>> +  if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) == 1
>>>>> +      && !any_dependent_template_arguments_p (targs))
>>>>
>>>> I notice that finish_id_expression_1 uses the equivalent of
>>>> type_dependent_expression_p (var).  Does that work here?
>>>
>>> Hmm, it does, but kind of by accident: type_dependent_expression_p
>>> returns true for all variable TEMPLATE_ID_EXPRs because of their empty
>>> TREE_TYPE (as set by finish_template_variable).  So testing t_d_e_p here
>>> is equivalent to testing processing_template_decl, it seems -- maximally
>>> conservative.
>>>
>>> We can improve type_dependent_expression_p for variable TEMPLATE_ID_EXPR
>>> by ignoring its (always empty) TREE_TYPE and just considering dependence
>>> of its template and args directly.

I guess the problem is that a variable template specialization is 
type-dependent until it's instantiated or specialized, and here we're 
trying to instantiate if that hasn't happened yet, so using 
type_dependent_expression_p would be wrong.

The patch is OK as is.

Jason


      reply	other threads:[~2022-10-20 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 15:58 Patrick Palka
2022-09-16 12:08 ` Jason Merrill
2022-09-16 14:59   ` Patrick Palka
2022-09-16 15:05     ` Patrick Palka
2022-09-16 23:30     ` Jason Merrill
2022-09-17 14:31       ` Patrick Palka
2022-10-20 16:21         ` 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=a6f5b2a3-f11c-5a9b-5d9a-d96df2d1660f@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).