]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with enum and conversion fn in template [PR115657]
authorMarek Polacek <polacek@redhat.com>
Thu, 15 Aug 2024 22:47:29 +0000 (18:47 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 19 Aug 2024 17:29:30 +0000 (13:29 -0400)
commit53283c3231a7b94e728619cccbf21170fb36b2a8
tree9f00304d88d43edf2d57b55558e2711008272f51
parent8191f15022b0ea44fcb549449b0458d07ae02e0a
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.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1y/constexpr-recursion2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/conv21.C [new file with mode: 0644]