]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: relax ICE for unexpected trees during constexpr [PR117925]
authorPatrick Palka <ppalka@redhat.com>
Thu, 9 Jan 2025 15:50:08 +0000 (10:50 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 9 Jan 2025 22:55:11 +0000 (17:55 -0500)
When we encounter an unexpected (likely templated) tree code during
constexpr evaluation we currently ICE even in release mode.  But it
seems more user-friendly to just gracefully treat the expression as
non-constant, which will be harmless most of the time (e.g. in the case
of warning-specific or speculative constexpr folding as in the PR), and
at worst will transform an ICE-on-valid bug into a rejects-valid bug.
This is also what e.g. tsubst_expr does when it encounters an unexpected
tree code.

PR c++/117925

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression) <default>:
Relax ICE when encountering an unexpected tree code into a
checking ICE guarded by flag_checking.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit eeedc54cc81c4dfb472ecbd6f14cfbf2dd035474)

gcc/cp/constexpr.cc

index c5cd5c87680f8a09387d116dca34a0a6852ea314..6025b4c29437e6fc8248eb4fe15ddebdd78a49e0 100644 (file)
@@ -8626,7 +8626,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
            error_at (EXPR_LOCATION (t),
                      "statement is not a constant expression");
        }
-      else
+      else if (flag_checking)
        internal_error ("unexpected expression %qE of kind %s", t,
                        get_tree_code_name (TREE_CODE (t)));
       *non_constant_p = true;