diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-03-01 10:22:59 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-03-01 10:25:38 +0100 |
commit | b222e725f53231a0bd9799ca93892a79d592a5f3 (patch) | |
tree | 31e440cf0b9e5786df843a407e135b77f7140110 /gcc/cp/constexpr.cc | |
parent | 85203d52bfa4a84da5f50e0a242891308ffa8d83 (diff) | |
download | gcc-b222e725f53231a0bd9799ca93892a79d592a5f3.zip gcc-b222e725f53231a0bd9799ca93892a79d592a5f3.tar.gz gcc-b222e725f53231a0bd9799ca93892a79d592a5f3.tar.bz2 |
c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606]
The r13-2965-g73d9b0e5947e16 change changed the line touched in this patch
from
return RECUR (tmp, want_rval);
to
return RECUR (DECL_INITIAL (tmp), want_rval);
This is on DECL_EXPR handling code, where tmp can be lots of different
trees and DECL_INITIAL unfortunately also means different things on
different trees.
It is the initializer on VAR_DECL, DECL_ARG_TYPE on PARM_DECLs (though
those are unlikely to have DECL_EXPRs), for FUNCTION_DECLs the body,
..., USING_DECL_DECLS on USING_DECLs and DECL_FRIENDLIST on TYPE_DECLs.
The testcase below ICEs because we have a DECL_EXPR for TYPE_DECL
which has non-NULL DECL_FRIENDLIST and we certainly can't recurse on
the friend list.
The following patch will RECUR on DECL_INITIAL only for VAR_DECLs and
for anything else just return true.
2023-03-01 Jakub Jelinek <jakub@redhat.com>
PR c++/108606
* constexpr.cc (potential_constant_expression_1) <case DECL_EXPR>:
Only recurse on DECL_INITIAL (tmp) if tmp is a VAR_DECL, otherwise
just return true.
* g++.dg/cpp1y/pr108606.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r-- | gcc/cp/constexpr.cc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b4d3e95..89df7d76 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9699,7 +9699,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, (tmp, /*constexpr_context_p=*/true, flags)) return false; } - return RECUR (DECL_INITIAL (tmp), want_rval); + if (VAR_P (tmp)) + return RECUR (DECL_INITIAL (tmp), want_rval); + return true; case TRY_FINALLY_EXPR: return (RECUR (TREE_OPERAND (t, 0), want_rval) |