diff options
author | Marek Polacek <polacek@redhat.com> | 2024-02-12 14:53:24 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-02-12 14:53:24 -0500 |
commit | 39d989022dd0eacf1a7b95b7b20621acbe717d70 (patch) | |
tree | a2ebcc74632f88c722b0e3e5e5ebeecfd9a65b54 /gcc/cp/constexpr.cc | |
parent | 9511b91c56f08b319b4a407608f85c96029ce7ce (diff) | |
download | gcc-39d989022dd0eacf1a7b95b7b20621acbe717d70.zip gcc-39d989022dd0eacf1a7b95b7b20621acbe717d70.tar.gz gcc-39d989022dd0eacf1a7b95b7b20621acbe717d70.tar.bz2 |
c++: ICE with reinterpret_cast and switch [PR113545]
Jason, this is the patch you proposed for PR113545. It looks very safe
so I'm posting it here so that it's not forgotten.
PR c++/113545
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_switch_expr): If the condition doesn't reduce
to an INTEGER_CST, consider it non-constant.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-reinterpret3.C: Remove dg-ice.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r-- | gcc/cp/constexpr.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 2ebb147..fa346fe 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7106,6 +7106,16 @@ cxx_eval_switch_expr (const constexpr_ctx *ctx, tree t, cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue, non_constant_p, overflow_p); VERIFY_CONSTANT (cond); + if (TREE_CODE (cond) != INTEGER_CST) + { + /* If the condition doesn't reduce to an INTEGER_CST it isn't a usable + switch condition even if it's constant enough for other things + (c++/113545). */ + gcc_checking_assert (ctx->quiet); + *non_constant_p = true; + return t; + } + *jump_target = cond; tree body |