From patchwork Thu Sep 29 17:51:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp99519wrs; Thu, 29 Sep 2022 10:52:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gY/IPCwZn9cXFhKs6SNcF04RugoTDaxMgTqY56jksChYGaEB39tQfp/wjgGxN8HW1dOAM X-Received: by 2002:a17:907:724e:b0:783:5fba:4298 with SMTP id ds14-20020a170907724e00b007835fba4298mr3868851ejc.28.1664473954685; Thu, 29 Sep 2022 10:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664473954; cv=none; d=google.com; s=arc-20160816; b=VRwJpmrpCj5CC5T4Z9f4dmhIKUIyDr79rdmiEMOilHMURcB9RCjq5YmiJ/rVP/b/HM LNKQlBgV7BuTdOVF4tWNTpBqmFXBEheQusQz0D9aCkdUe4APUHnSpJ0IymBM+lhnBX4b dUUe1WaS0hiN77Lt2LDDZZoPNZU1Dysp1eQtAIKzTrq/+8ACD627UghSjA1SwOapH1Vp NXSczHOVNn1H+IYMUWmbJMCy07TXgQ89ckA7QWfmfdjLYqk2K7UNbh/GYPmCZe8QnO8Q KDMEoxDNU2J4QmwasY9zrWWrHezMFWIe1tszSH1JUyVUNF7j+QNWz4GCUgLR8Bn7EI69 loVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=JAgDgGhsSuMui6rNVzLfffSGfFifxl4EVLIDEOmuB+0=; b=ssvHbZGoylGOiSCm6UyfgwFNClIrTzHzHPhWkGLMUZWb3R4FjyXEIuRHti2bppPU06 wdIMrO+8dZLxkZLl9HCu5p5B+vYIM9mE9IILbt4YjxiVwnBLQF5ig0G2NFCri2H93pfM 6nwrLIqyC+9sZWNnXzDCpTXjICaOtdI26Eu0OENnEUcSnPZkzUe4YReATZnMmvlvuayJ uTjjSGjl0e5xbgsLqVR+KNHRAu9crqLhWN3U+iOtvPzkk0xoAs8fRL6TUBbfNPaq+aK8 40vtYHYFMQWmUHMO/Gq9xkSgQbIXndNeBGYlYltm8YQtlF72QE4eaybifxSPJYsy6WvG UYWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QaTesiil; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y9-20020a50e609000000b00456d901922bsi104343edm.510.2022.09.29.10.52.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 10:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QaTesiil; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E793F3854174 for ; Thu, 29 Sep 2022 17:52:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E793F3854174 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664473945; bh=JAgDgGhsSuMui6rNVzLfffSGfFifxl4EVLIDEOmuB+0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QaTesiilJ9ux+7hDbD7/vaI/IJgzhZ6q3oWU7xMiYAi+OgKGWx7YxydqyELVRvxxr e+wdElY5Ik89rFpIgKgCAxzV3g/Fkz96CYKNoSpxEIZSuOZmmjqL6ZMt+TlB9zaLyK N8mIi49+x0lJpuMgjQr/49ECPLecdoVmazO2bVCE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A4890385C40F for ; Thu, 29 Sep 2022 17:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4890385C40F Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-466-T2qEyN_jOPmgEEoM7kL2iQ-1; Thu, 29 Sep 2022 13:51:23 -0400 X-MC-Unique: T2qEyN_jOPmgEEoM7kL2iQ-1 Received: by mail-qk1-f200.google.com with SMTP id br14-20020a05620a460e00b006cec4af5a2fso1748968qkb.2 for ; Thu, 29 Sep 2022 10:51:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=JAgDgGhsSuMui6rNVzLfffSGfFifxl4EVLIDEOmuB+0=; b=mcVvJUloqdq+Z/BJ8E+4FELPeuQX4iShXZ8fJdWDZRHJGtUQ1OggJDT3x2QlS0PRvH QO9o8sElrLRylXvJLYLgkEdhOonpnS3JiEeMOh/D2/y/gZZ5YVVuOLYeOh9oSwSm8+cT ZM1rfv8llA7plVnRCcPr0KGo8yP/o8prkwFKD4VqwtnqIRSEU1ibHsP6dlkjXAubtZuM C3G5gKYrZfxyp7cqPYuVrPsr/wPcg455GtyNyWWm5qIirbhMoRlKqspIUpIl8RWyFWss tcH2fnT3gvR7lT1Vaan6kY21+k7EjxNZlRBwFCWR+GLtBPI5enipdLgWgXqJ+tBsrICA G6HA== X-Gm-Message-State: ACrzQf2DDUi7Q9r32s666ZR3QBRQQQlT6e4871pn7I5NSqe9TmXOn/p1 dblnaCeCqQMNlaHHISKkS2XcXwira4tItyA8dXUdPXPHaf3Zp8GZ94dsOu3n5o07IsCdLjJ35jT uPkR64RzPkCB4kjOsiHUqNIUct/bgF/aJ+VIhydqyH+CzAlJWGbmJCO7Xdu4MndhIzA== X-Received: by 2002:a05:6214:1cc7:b0:4af:6573:c056 with SMTP id g7-20020a0562141cc700b004af6573c056mr3585595qvd.103.1664473882769; Thu, 29 Sep 2022 10:51:22 -0700 (PDT) X-Received: by 2002:a05:6214:1cc7:b0:4af:6573:c056 with SMTP id g7-20020a0562141cc700b004af6573c056mr3585578qvd.103.1664473882417; Thu, 29 Sep 2022 10:51:22 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id n19-20020a05620a295300b006ced5d3f921sm24409qkp.52.2022.09.29.10.51.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 10:51:21 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: check DECL_INITIAL for constexpr Date: Thu, 29 Sep 2022 13:51:20 -0400 Message-Id: <20220929175120.1916164-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745327441531742886?= X-GMAIL-MSGID: =?utf-8?q?1745327441531742886?= Tested x86_64-pc-linux-gnu, applying to trunk. -- >8 -- We were overlooking non-potentially-constant bits in variable initializer because we didn't walk into DECL_INITIAL. gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Look into DECL_INITIAL. Use location wrappers. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-local4.C: Expect error sooner. * g++.dg/cpp2a/consteval24.C: Likewise. * g++.dg/cpp2a/consteval7.C: Likewise. * g++.dg/cpp2a/inline-asm3.C: Likewise. --- gcc/cp/constexpr.cc | 7 +++++-- gcc/testsuite/g++.dg/cpp1y/constexpr-local4.C | 4 ++-- gcc/testsuite/g++.dg/cpp2a/consteval24.C | 2 +- gcc/testsuite/g++.dg/cpp2a/consteval7.C | 2 +- gcc/testsuite/g++.dg/cpp2a/inline-asm3.C | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) base-commit: af9034827e8f06f10767064e9fc7443b94e08184 prerequisite-patch-id: b1512f7473cce4cc8f21dbc772d07bd59c632e5e prerequisite-patch-id: f3aeb477456e3d56d2d570d4bad334cb45e6bccf diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 10639876d9c..ed41d755269 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8892,7 +8892,10 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, { tree from = TREE_OPERAND (t, 0); if (location_wrapper_p (t)) - return (RECUR (from, want_rval)); + { + iloc_sentinel ils = loc; + return (RECUR (from, want_rval)); + } if (INDIRECT_TYPE_P (TREE_TYPE (t))) { STRIP_ANY_LOCATION_WRAPPER (from); @@ -9348,7 +9351,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, (tmp, /*constexpr_context_p=*/true, flags)) return false; } - return RECUR (tmp, want_rval); + return RECUR (DECL_INITIAL (tmp), want_rval); case TRY_FINALLY_EXPR: return (RECUR (TREE_OPERAND (t, 0), want_rval) diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-local4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-local4.C index bef62488579..647b5dcd7cd 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-local4.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-local4.C @@ -10,8 +10,8 @@ const A a = 42; constexpr int f() { - const int j = a.i; // { dg-message "'a'" } + const int j = a.i; // { dg-error "'a'" } return j; } -static_assert (f() == 42,""); // { dg-error "non-constant" } +static_assert (f() == 42,""); // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval24.C b/gcc/testsuite/g++.dg/cpp2a/consteval24.C index 6d0c63c749b..6d7034c5515 100644 --- a/gcc/testsuite/g++.dg/cpp2a/consteval24.C +++ b/gcc/testsuite/g++.dg/cpp2a/consteval24.C @@ -27,4 +27,4 @@ bar () return fn1 () + fn2 () + (s.*fn3) () + (s.*fn4) () + fn5 () + (s.*fn6) () + (s.*fn7) (); } -auto a = bar (); +auto a = bar (); // { dg-error "bar" } diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval7.C b/gcc/testsuite/g++.dg/cpp2a/consteval7.C index 23f3d25a39e..74996d31a82 100644 --- a/gcc/testsuite/g++.dg/cpp2a/consteval7.C +++ b/gcc/testsuite/g++.dg/cpp2a/consteval7.C @@ -10,4 +10,4 @@ consteval int qux () { S s = baz (); return s.b + s.c (); } consteval int quux () { constexpr S s = baz (); return s.b + s.c (); } // { dg-error "immediate evaluation returns address of immediate function 'consteval int foo\\(\\)'" } constexpr auto d = baz (); // { dg-error "immediate evaluation returns address of immediate function 'consteval int foo\\(\\)'" } constexpr auto e = qux (); -constexpr auto f = quux (); +constexpr auto f = quux (); // { dg-error "quux" } diff --git a/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C b/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C index a7476b1d9d1..a6f612e2447 100644 --- a/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C +++ b/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C @@ -9,4 +9,4 @@ foo () return i; } -constexpr int i = foo (); +constexpr int i = foo (); // { dg-error "foo" }