https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115657
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:53283c3231a7b94e728619cccbf21170fb36b2a8 commit r15-3027-g53283c3231a7b94e728619cccbf21170fb36b2a8 Author: Marek Polacek <pola...@redhat.com> Date: Thu Aug 15 18:47:29 2024 -0400 c++: ICE with enum and conversion fn in template [PR115657] Here we initialize an enumerator with a class prvalue with a conversion function. When we fold it in build_enumerator, we create a TARGET_EXPR for the object, and subsequently crash in tsubst_expr, which should not see such a code. Normally, we fix similar problems by using an IMPLICIT_CONV_EXPR but here I may get away with not using the result of fold_non_dependent_expr unless the result is a constant. A TARGET_EXPR is not constant. PR c++/115657 gcc/cp/ChangeLog: * decl.cc (build_enumerator): Call maybe_fold_non_dependent_expr instead of fold_non_dependent_expr. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-recursion2.C: New test. * g++.dg/template/conv21.C: New test.