c++/reflection: ICE with lifetime extension of consteval-only [PR124575]

Here we ICE in output_constant because we attempt to emit the temporary
created for lifetime extension of a consteval-only expression.  Like
other consteval-only variables, the temporary also has to be marked
DECL_EXTERNAL so that we don't emit it.

I tried to do the setting in make_temporary_var_for_ref_to_temp, but
then we ICE in set_decl_context_in_fn.

	PR c++/124575

gcc/cp/ChangeLog:

	* call.cc (set_up_extended_ref_temp): If var is consteval-only,
	mark it DECL_EXTERNAL.

gcc/testsuite/ChangeLog:

	* g++.dg/reflect/expr16.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
Marek Polacek
2026-03-19 09:33:15 -04:00
parent 95d2eb6fa0
commit d51a78f7a8
2 changed files with 9 additions and 0 deletions

View File

@@ -14351,6 +14351,10 @@ set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
/* Any reference temp has a non-trivial initializer. */
DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
/* Don't output reflection variables. */
if (consteval_only_p (var))
DECL_EXTERNAL (var) = true;
/* If the initializer is constant, put it in DECL_INITIAL so we get
static initialization and use in constant expressions. */
init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);

View File

@@ -0,0 +1,5 @@
// PR c++/124575
// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection" }
constexpr const decltype(^^::) &r = ^^int;