https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117099
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>: https://gcc.gnu.org/g:f31b72b75ef7cde61469c774162db7b1cc4c3d03 commit r15-4959-gf31b72b75ef7cde61469c774162db7b1cc4c3d03 Author: Simon Martin <si...@nasilyan.com> Date: Tue Nov 5 10:44:34 2024 +0100 c++: Fix crash during NRV optimization with invalid input [PR117099, PR117129] PR117099 and PR117129 are ICEs upon invalid code that happen when NRVO is activated, and both due to the fact that we don't consistently set current_function_return_value to error_mark_node upon error in finish_return_expr. This patch fixes this inconsistency which fixes both cases since we skip calling finalize_nrv when current_function_return_value is error_mark_node. PR c++/117099 PR c++/117129 gcc/cp/ChangeLog: * typeck.cc (check_return_expr): Upon error, set current_function_return_value to error_mark_node. gcc/testsuite/ChangeLog: * g++.dg/parse/crash78.C: New test. * g++.dg/parse/crash78a.C: New test. * g++.dg/parse/crash79.C: New test.