From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 0CC06385DC2F for ; Thu, 2 Apr 2020 04:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0CC06385DC2F Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-pUwfa2nHP9uHYAbnT4qvGA-1; Thu, 02 Apr 2020 00:35:41 -0400 X-MC-Unique: pUwfa2nHP9uHYAbnT4qvGA-1 Received: by mail-qk1-f200.google.com with SMTP id a21so1998691qkg.6 for ; Wed, 01 Apr 2020 21:35:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nib5zsdsdsBlBDZk8ghQbklhfEm9TGvT/gWr67Sjd2k=; b=NUqCBGJCTrBgqIt6qbQvAJdIMMqYSJKxjs6ApBjjNyFDHp0MnG5mjJiUooQ2qBaPD7 nsdmr1InsvUhG7GvxqT2uyfbZf/xvoQdanu1jdt5Z3UPtkda9G9udSU0nhjTZE3fLWLk piK4aXEOmzr6ixKVeVjdzNqiIPp8qRMbIhcI10MPjjiCjcBUCXzKIr+3Ds2s+3IkAQhi JNZS5p8o/ZvG3gsO0cJGwszUJAHnp+NE0B9O1xiEFXjbZjeXHYKGtSSGefkISrig8ZRx rKDhagyvyMKyzXt70bZ+QdP/CSTnd5S9zi5QS8X1vOACLIcnMzBiMvq8tJHWNW6+IDef hP2A== X-Gm-Message-State: AGi0PuY0RsP6tcpVDPc06pvIbdhR4His1YmjiKWLi18KQNuJuDQKZy8S If4zqqTnsb0HwITxPonsZhZsf84QROjlEI73WGZ8D0xDi0k9K+j3JWeri+xijxh4oO+JC1xFpay XeLdXYMpMSPYgGsvH0w== X-Received: by 2002:a37:591:: with SMTP id 139mr1661302qkf.281.1585802140179; Wed, 01 Apr 2020 21:35:40 -0700 (PDT) X-Google-Smtp-Source: APiQypKj6uktMnUDKxYVjVS6GZRFONdWHzMyJo5rvWlqLe6iLAaFWOa27UHRCDGul1gl0+nv0ZxPrg== X-Received: by 2002:a37:591:: with SMTP id 139mr1661282qkf.281.1585802139760; Wed, 01 Apr 2020 21:35:39 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id p35sm3033901qtk.2.2020.04.01.21.35.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Apr 2020 21:35:39 -0700 (PDT) Subject: Re: [pushed] c++: Fix DMI with lambda 'this' capture [PR94205] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20200401051620.15165-1-jason@redhat.com> From: Jason Merrill Message-ID: <6e17a81b-c029-f8cb-a633-9fe994d987fb@redhat.com> Date: Thu, 2 Apr 2020 00:35:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-30.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Apr 2020 04:35:44 -0000 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 >> >> 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