This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
constant_of(^^v) for variable v of reference to array/function type produces reflection of pointer constantSection: 21.4.7 [meta.reflection.queries] Status: New Submitter: S. B. Tam Opened: 2026-05-18 Last modified: 2026-09-18
Priority: 2
View other active issues in [meta.reflection.queries].
View all other issues in [meta.reflection.queries].
View all issues with New status.
Discussion:
After CWG 3111, constant_of uses
reflect_constant_array and reflect_function for arrays and functions respectively. But since
it inspects type_of(r) and not remove_reference(type_of(r)), variables of reference types will
still decay to pointers. It's unclear to me whether this is intended.
[2026-08-27; Reflector poll.]
Set priority to 2 after reflector poll.
May not be possible to avoid decay for array/function references in constant_of, since copies of non-constant arrays can't be constants.
[2026-09-18; Tomasz provides proposed resolution.]
Clarifying behavior of constant_of and reflect_constant_array for objects
which values cannot be accessed at compile is left to be handled in separate
issues.
Proposed resolution:
This wording is relative to N5054.
Modify 21.4.7 [meta.reflection.queries] as indicated:
consteval info constant_of(info r);-7- Let
-8- Effects: Equivalent to:Rbe a constant expression of typeinfosuch thatR == ristrue. Ifrrepresents an annotation, then letCbe its underlying constant.if constexpr (is_annotation(R)) { return C; } else if constexpr (is_array_type(remove_reference(type_of(R)))) { return reflect_constant_array([: R :]); } else if constexpr (is_function_type(remove_reference(type_of(R)))) { return reflect_function([: R :]); } else { return reflect_constant([: R :]); }-9- Throws:
meta::exceptionunless eitherrrepresents an annotation or[: R :]is a valid splice-expression (7.5.9 [expr.prim.splice]).