diff options
author | Marek Polacek <polacek@redhat.com> | 2025-02-19 14:06:33 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2025-02-27 13:45:01 -0500 |
commit | 9792126ac769f2962c0f305991818c64f9e51221 (patch) | |
tree | d5d6571f9ca052322255b8079873614c5408258a | |
parent | 3071eb2848a2e748cfd67e8c897890ce06c69d06 (diff) | |
download | gcc-9792126ac769f2962c0f305991818c64f9e51221.zip gcc-9792126ac769f2962c0f305991818c64f9e51221.tar.gz gcc-9792126ac769f2962c0f305991818c64f9e51221.tar.bz2 |
c++: ICE with GOTO_EXPR [PR118928]
In this PR we crash in cxx_eval_constant_expression/GOTO_EXPR on:
gcc_assert (cxx_dialect >= cxx23);
The code obviously doesn't expect to see a goto pre-C++23. But we can
get here with the new prvalue optimization. In this test we found
ourselves in synthesize_method for X::X(). This function calls:
a) finish_function, which does cp_genericize -> ... -> genericize_c_loops,
which creates the GOTO_EXPR;
b) expand_or_defer_fn -> maybe_clone_body -> ... -> cp_fold_function
where we reach the new maybe_constant_init call and crash on the
goto.
Since we can validly get to that assert, I think we should just remove
it. I don't see other similar asserts like this one.
PR c++/118928
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_constant_expression) <case GOTO_EXPR>: Remove
an assert.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-prvalue5.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r-- | gcc/cp/constexpr.cc | 1 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 59dd066..c68666c 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8691,7 +8691,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, *jump_target = TREE_OPERAND (t, 0); else { - gcc_assert (cxx_dialect >= cxx23); if (!ctx->quiet) error_at (loc, "%<goto%> is not a constant expression"); *non_constant_p = true; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C new file mode 100644 index 0000000..1f847bb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C @@ -0,0 +1,24 @@ +// PR c++/118928 +// { dg-do compile { target c++11 } } +// { dg-options "-O" } + +using size_t = decltype(sizeof(0)); + +namespace std { +template <typename T> struct initializer_list { + const T *_M_array; + size_t _M_len; +}; +struct S { + constexpr S(const char *); // { dg-warning "used but never defined" } +}; +struct vector { + constexpr vector(initializer_list<S>) {} +}; +} +struct Y { + std::vector v; +}; +struct X { + Y y{{""}}; +} x; |