]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with GOTO_EXPR [PR118928]
authorMarek Polacek <polacek@redhat.com>
Wed, 19 Feb 2025 19:06:33 +0000 (14:06 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 27 Feb 2025 18:45:01 +0000 (13:45 -0500)
commit9792126ac769f2962c0f305991818c64f9e51221
treed5d6571f9ca052322255b8079873614c5408258a
parent3071eb2848a2e748cfd67e8c897890ce06c69d06
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>
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C [new file with mode: 0644]