From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664473893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JAgDgGhsSuMui6rNVzLfffSGfFifxl4EVLIDEOmuB+0=; b=E0cG4N9j4CUrBVLNOPgACelREyKNPOGK0ocWKVJWWQLNo/XLGgP+IYdXmdJRVcwjF2q/YF BBelvL1qJZyDS+JMdY2UmMWf/visw7CgYV5Il05w/+a72JjSZ63nJ1JuC8mLY7m/MRsP25 o7DMC82PgWjpT/6bzrz7cmHT5VmHv38= 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-Google-Smtp-Source: AMsMyM58L2CEamre3anxYGFCaOQWYQiB4buB6FDTXQ72H+lCfAdm1X+LvLpF0hOILKQiMQccrFaoEw== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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(-) 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" } base-commit: af9034827e8f06f10767064e9fc7443b94e08184 prerequisite-patch-id: b1512f7473cce4cc8f21dbc772d07bd59c632e5e prerequisite-patch-id: f3aeb477456e3d56d2d570d4bad334cb45e6bccf -- 2.31.1