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: [pushed] c++: Fix DMI with lambda 'this' capture [PR94205]
Date: Thu, 2 Apr 2020 00:35:38 -0400	[thread overview]
Message-ID: <6e17a81b-c029-f8cb-a633-9fe994d987fb@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.22.413.2004011024000.3094475@idea>

On 4/1/20 10:47 AM, Patrick Palka wrote:
> On Wed, 1 Apr 2020, Jason Merrill wrote:
> 
>> We represent 'this' in a default member initializer with a PLACEHOLDER_EXPR.
>> Normally in constexpr evaluation when we encounter one it refers to
>> ctx->ctor, but when we're creating a temporary of class type, that replaces
>> ctx->ctor, so a PLACEHOLDER_EXPR that refers to the type of the member being
>> initialized needs to be replaced before that happens.
>>
>> This patch fixes the testcase below, but not the original testcase from the PR,
>> which is still broken due to PR94219.
>>
>> Tested x86_64-pc-linux-gnu, applying to trunk and 9.
>>
>> gcc/cp/ChangeLog
>> 2020-03-31  Jason Merrill  <jason@redhat.com>
>>
>> 	PR c++/94205
>> 	* constexpr.c (cxx_eval_constant_expression) [TARGET_EXPR]: Call
>> 	replace_placeholders.
>> 	* typeck2.c (store_init_value): Fix arguments to
>> 	fold_non_dependent_expr.
>> ---
>>   gcc/cp/constexpr.c                            |  6 ++++++
>>   gcc/cp/tree.c                                 |  2 +-
>>   gcc/cp/typeck2.c                              |  2 +-
>>   gcc/testsuite/g++.dg/cpp0x/constexpr-nsdmi2.C | 20 +++++++++++++++++++
>>   gcc/testsuite/g++.dg/cpp1z/lambda-this4.C     | 13 ++++++++++++
>>   5 files changed, 41 insertions(+), 2 deletions(-)
>>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-nsdmi2.C
>>   create mode 100644 gcc/testsuite/g++.dg/cpp1z/lambda-this4.C
>>
>> diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
>> index e85b3c113f0..91f0c3ba269 100644
>> --- a/gcc/cp/constexpr.c
>> +++ b/gcc/cp/constexpr.c
>> @@ -5553,6 +5553,12 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
>>   	tree init = TARGET_EXPR_INITIAL (t);
>>   	if ((AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type)))
>>   	  {
>> +	    if (ctx->object)
>> +	      /* If the initializer contains any PLACEHOLDER_EXPR, we need to
>> +		 resolve them before we create a new CONSTRUCTOR for the
>> +		 temporary.  */
>> +	      init = replace_placeholders (init, ctx->object);
> 
> I think I'm running into an issue due to this call to replace_placeholders.
> After this change, the following (compiled with -std=c++17) ICEs
> 
>      struct S
>      {
>        int a = [this] { return 6; } ();
>      };
> 
>      S
>      foo()
>      {
>        return {};
>      }
> 
> with
> 
>      internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:2830
> 
> Unsharing 'init' before before doing replace_placeholders seems to fix
> this ICE.

That sounds good, thanks.

Jason


      reply	other threads:[~2020-04-02  4:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01  5:16 Jason Merrill
2020-04-01 14:47 ` Patrick Palka
2020-04-02  4:35   ` 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=6e17a81b-c029-f8cb-a633-9fe994d987fb@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).