aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-09-20 17:12:29 -0400
committerJason Merrill <jason@redhat.com>2022-09-29 13:50:54 -0400
commit73d9b0e5947e162386f7e25d3851097cee1bb366 (patch)
tree4ba1a5ad4680256996b60ca0e0f58fa8e965656a /gcc/cp
parentbbdb5612f6661f2c64b0c0f1d2291cb59fde2b40 (diff)
downloadgcc-73d9b0e5947e162386f7e25d3851097cee1bb366.zip
gcc-73d9b0e5947e162386f7e25d3851097cee1bb366.tar.gz
gcc-73d9b0e5947e162386f7e25d3851097cee1bb366.tar.bz2
c++: check DECL_INITIAL for constexpr
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.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/constexpr.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 1063987..ed41d75 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)