From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15348 invoked by alias); 29 Dec 2018 02:33:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 15339 invoked by uid 89); 29 Dec 2018 02:33:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Split X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Dec 2018 02:33:34 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07ACC356CF; Sat, 29 Dec 2018 02:33:33 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 755C35C1B4; Sat, 29 Dec 2018 02:33:32 +0000 (UTC) Received: from libre (free-to-gw.home [172.31.160.161]) by free.home (8.15.2/8.15.2) with ESMTP id wBT2XIMn477487; Sat, 29 Dec 2018 00:33:20 -0200 From: Alexandre Oliva To: Jason Merrill Cc: Christophe Lyon , gcc-patches List Subject: Re: [C++ Patch] [PR c++/88146] do not crash synthesizing inherited ctor(...) References: <81ac6c22-8907-a166-b8df-80e06d2850da@redhat.com> <12883fc9-4e44-e16d-fdc6-9a90c21bf01c@redhat.com> Date: Sat, 29 Dec 2018 06:40:00 -0000 In-Reply-To: (Alexandre Oliva's message of "Fri, 28 Dec 2018 17:39:22 -0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-12/txt/msg01752.txt.bz2 On Dec 28, 2018, Alexandre Oliva wrote: > I guess I still need to > fill in other gaps to in my knowledge to try and make sense of it. Done. > diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c Here's a patch based on your suggestion. [PR88146] do not instantiate constexpr if not manifestly const This is another approach at fixing the g++.dg/cpp0x/inh-ctor32.C test failures on targets that have non-void return values for cdtors: only instantiate constexpr functions for expressions that are potentially constant evaluated. Alas, this exposed a latent problem elsewhere: braced initializer lists underwent check_narrowing when simplified to non-lists, but that did not signal maybe_constant_value the potentially constant evaluated constant that all direct members of braced initializer lists have, so after the change above we'd no longer initialize constexpr functions that per P0859 we ought to. cpp2a/constexpr-init1.C, taken directly from P0859, flagged the regression. While looking into it, I realized it was fragile: it could have passed even if we flagged the error we should flag for the construct that we are supposed to accept. So, I split it out, to catch too-aggressive constexpr instantiation as much as the too-lax instantiation the original testcase flagged after the first part of the change. Regstrapped on x86_64- and i686-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/88146 * constexpr.c (cxx_eval_outermost_constant_expr): Only instantiate constexpr fns for manifestly const eval. * typeck2.c (check_narrowing): Test for maybe constant value with manifestly const eval. for gcc/testsuite/ChangeLog PR c++/88146 * g++.dg/cpp2a/constexpr-inst1a.C: Split out of... * g++.dg/cpp2a/constexpr-inst1.C: ... this. --- gcc/cp/constexpr.c | 3 ++- gcc/cp/typeck2.c | 6 +++++- gcc/testsuite/g++.dg/cpp2a/constexpr-inst1.C | 3 --- gcc/testsuite/g++.dg/cpp2a/constexpr-inst1a.C | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-inst1a.C diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index cea414d33def..88bee7aa1fed 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5076,7 +5076,8 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_= non_constant, r =3D TARGET_EXPR_INITIAL (r); } =20 - instantiate_constexpr_fns (r); + if (ctx.manifestly_const_eval) + instantiate_constexpr_fns (r); r =3D cxx_eval_constant_expression (&ctx, r, false, &non_constant_p, &overflow_p); =20 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index cc9bf02439b6..ae194d519395 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -918,7 +918,11 @@ check_narrowing (tree type, tree init, tsubst_flags_t = complain, bool const_only) return ok; } =20 - init =3D maybe_constant_value (init); + /* Immediate subexpressions in BRACED_ENCLOSED_INITIALIZERs are + potentially constant evaluated. Without manifestly_const_eval, + we won't instantiate constexpr functions that we must + instantiate. */ + init =3D maybe_constant_value (init, NULL_TREE, /*manifestly_const_eval= =3D*/true); =20 /* If we were asked to only check constants, return early. */ if (const_only && !TREE_CONSTANT (init)) diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-inst1.C b/gcc/testsuite/g= ++.dg/cpp2a/constexpr-inst1.C index 1016bec9d3e1..34863de3cf84 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-inst1.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst1.C @@ -2,12 +2,9 @@ // { dg-do compile { target c++14 } } =20 template constexpr int f() { return T::value; } // { dg-error = "int" } -template void g(decltype(B ? f() : 0)); -template void g(...); template void h(decltype(int{B ? f() : 0})); template void h(...); void x() { - g(0); // OK, B ? f() : 0 is not potentially constant eval= uated h(0); // error, instantiates f even though B evaluates = to false and // list-initialization of int from int cannot be narro= wing } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-inst1a.C b/gcc/testsuite/= g++.dg/cpp2a/constexpr-inst1a.C new file mode 100644 index 000000000000..1c068595e374 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst1a.C @@ -0,0 +1,9 @@ +// Testcase from P0859 +// { dg-do compile { target c++14 } } + +template constexpr int f() { return T::value; } +template void g(decltype(B ? f() : 0)); +template void g(...); +void x() { + g(0); // OK, B ? f() : 0 is not potentially constant eval= uated +} --=20 Alexandre Oliva, freedom fighter https://FSFLA.org/blogs/lxo Be the change, be Free! FSF Latin America board member GNU Toolchain Engineer Free Software Evangelist Hay que enGNUrecerse, pero sin perder la terGNUra jam=C3=A1s-GNUChe