From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 9DBC2385BF92 for ; Wed, 1 Apr 2020 14:47:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9DBC2385BF92 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-hYdRw4ioMrCk3tLRYuq5FQ-1; Wed, 01 Apr 2020 10:47:27 -0400 X-MC-Unique: hYdRw4ioMrCk3tLRYuq5FQ-1 Received: by mail-qt1-f200.google.com with SMTP id g25so30871qts.0 for ; Wed, 01 Apr 2020 07:47:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Iu1aRXVWjlPgrr4jPuKb6OHQfNJYHjSIj7yvXaZ/BDs=; b=fIHzyzmLRMpef3jCybC8FO4Fu9Dn35ZSEXZ0wgphEndIGp2t1GD7UzUIJWD11DJLvs owlVku7Q5Y6bF2uk+E6dVU7L4REURbcRCrbaIdip0KDK56t67E76VzXLF2aMRxXHRGOP fd6gfprlk2AdMLueQIv6S97AEgCQgOEiwXNx8M1me2El0O7v40l76PqhLMJh9KdT9luh o1WGI0tEqULOPVCv2xx4Fz0r+v7/+0hHzQCquHAS+Jz1wMZ2hXHhfED1bteVFNg6OKVQ MbkCQnzIM9YjZRV8vItNl0iJVQx5tMg6qNRiKLb1SgXLv76v3NoldWA0yIFlzjbydI9j QmMw== X-Gm-Message-State: ANhLgQ0532zS8cUY5vxdmrGmmUcJG7JrawhxCtLttq56sc8cgxEGEYYp GcukJMcsepvopZBFJiNhUMyoLhKEs1ubNWZNRiNhiDdHOE8FIGyqJOT7rIuJNjgvxLcv8bvsOWu EsXk1StsNMIWWk0It6w== X-Received: by 2002:ae9:e212:: with SMTP id c18mr10646727qkc.452.1585752446502; Wed, 01 Apr 2020 07:47:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs1JToA5x/cP5AJV3BPrUFIBkjtju/hgmQZadnsZjvlK3XxDRIIS0Z9Y9ykYA91jUdSXVRn/g== X-Received: by 2002:ae9:e212:: with SMTP id c18mr10646634qkc.452.1585752446142; Wed, 01 Apr 2020 07:47:26 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id w28sm1611384qtc.27.2020.04.01.07.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 07:47:25 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 1 Apr 2020 10:47:24 -0400 (EDT) To: Jason Merrill cc: gcc-patches@gcc.gnu.org, ppalka@redhat.com Subject: Re: [pushed] c++: Fix DMI with lambda 'this' capture [PR94205] In-Reply-To: <20200401051620.15165-1-jason@redhat.com> Message-ID: References: <20200401051620.15165-1-jason@redhat.com> User-Agent: Alpine 2.22 (DEB 413 2020-03-19) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-31.1 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: Wed, 01 Apr 2020 14:47:29 -0000 On Wed, 1 Apr 2020, Jason Merrill wrote: > We represent 'this' in a default member initializer with a PLACEHOLDER_EX= PR. > Normally in constexpr evaluation when we encounter one it refers to > ctx->ctor, but when we're creating a temporary of class type, that replac= es > ctx->ctor, so a PLACEHOLDER_EXPR that refers to the type of the member be= ing > initialized needs to be replaced before that happens. >=20 > This patch fixes the testcase below, but not the original testcase from t= he PR, > which is still broken due to PR94219. >=20 > Tested x86_64-pc-linux-gnu, applying to trunk and 9. >=20 > gcc/cp/ChangeLog > 2020-03-31 Jason Merrill >=20 > =09PR c++/94205 > =09* constexpr.c (cxx_eval_constant_expression) [TARGET_EXPR]: Call > =09replace_placeholders. > =09* typeck2.c (store_init_value): Fix arguments to > =09fold_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 >=20 > 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, > =09tree init =3D TARGET_EXPR_INITIAL (t); > =09if ((AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type))) > =09 { > +=09 if (ctx->object) > +=09 /* If the initializer contains any PLACEHOLDER_EXPR, we need to > +=09=09 resolve them before we create a new CONSTRUCTOR for the > +=09=09 temporary. */ > +=09 init =3D 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=3Dc++17) ICEs struct S { int a =3D [this] { return 6; } (); }; S foo() { return {}; } with internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:28= 30 Unsharing 'init' before before doing replace_placeholders seems to fix this ICE. (This came up while working on PR94034, which seems like it may admit a fix that's similar to this one for PR94205.) > + > =09 /* We're being expanded without an explicit target, so start > =09 initializing a new object; expansion with an explicit target > =09 strips the TARGET_EXPR before we get here. */ > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c > index a2172dea0d8..5eb0dcd717a 100644 > --- a/gcc/cp/tree.c > +++ b/gcc/cp/tree.c > @@ -3239,7 +3239,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees= , void* data_) > a PLACEHOLDER_EXPR has been encountered. */ > =20 > tree > -replace_placeholders (tree exp, tree obj, bool *seen_p) > +replace_placeholders (tree exp, tree obj, bool *seen_p /*=3D NULL*/) > { > /* This is only relevant for C++14. */ > if (cxx_dialect < cxx14) > diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c > index bff4ddbcf81..cf1cb5ace66 100644 > --- a/gcc/cp/typeck2.c > +++ b/gcc/cp/typeck2.c > @@ -871,7 +871,7 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) > { > bool const_init; > tree oldval =3D value; > - value =3D fold_non_dependent_expr (value); > + value =3D fold_non_dependent_expr (value, tf_warning_or_error, tru= e, decl); > if (DECL_DECLARED_CONSTEXPR_P (decl) > =09 || (DECL_IN_AGGR_P (decl) > =09 && DECL_INITIALIZED_IN_CLASS_P (decl))) > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-nsdmi2.C b/gcc/testsuit= e/g++.dg/cpp0x/constexpr-nsdmi2.C > new file mode 100644 > index 00000000000..c51f734a134 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-nsdmi2.C > @@ -0,0 +1,20 @@ > +// PR c++/94205 > +// { dg-do compile { target c++14 } } > + > +struct S > +{ > + struct A > + { > + S *p; > + constexpr A(S* p): p(p) {} > + constexpr operator int() { p->i =3D 5; return 6; } > + }; > + int i; > + int a =3D A(this); > +}; > + > + > +constexpr S s =3D {}; > + > +#define SA(X) static_assert((X),#X) > +SA(s.i =3D=3D 5 && s.a =3D=3D 6); > diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-this4.C b/gcc/testsuite/g+= +.dg/cpp1z/lambda-this4.C > new file mode 100644 > index 00000000000..5d968791491 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1z/lambda-this4.C > @@ -0,0 +1,13 @@ > +// PR c++/94205 > +// { dg-do compile { target c++17 } } > + > +struct S > +{ > + int i; > + int a =3D [this] { this->i =3D 5; return 6; } (); > +}; > + > + > +constexpr S s =3D {}; > + > +static_assert (s.i =3D=3D 5 && s.a =3D=3D 6); >=20 > base-commit: f14b41d27124601284347a10d496362c8b4b8e1c > --=20 > 2.18.1 >=20 >=20