Title
`constant_of(^^v)` for variable `v` of reference to array/function type produces reflection of pointer constant
Status
new
Section
[meta.reflection.queries]
Submitter
S. B. Tam

Created on 2026-05-18.00:00:00 last changed 3 days ago

Messages

Date: 2026-09-18.12:32:21

Proposed resolution:

This wording is relative to N5054.

  1. Modify [meta.reflection.queries] as indicated:

    consteval info constant_of(info r);
    

    -7- Let R be a constant expression of type `info` such that R == r is `true`. If `r` represents an annotation, then let C be its underlying constant.

    -8- Effects: Equivalent to:

    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::exception` unless either `r` represents an annotation or [: R :] is a valid splice-expression ([expr.prim.splice]).

Date: 2026-09-15.00:00:00

[ 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.

Date: 2026-08-15.00:00:00

[ 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.

Date: 2026-05-18.00:00:00

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.

History
Date User Action Args
2026-09-18 12:32:21adminsetmessages: + msg16613
2026-09-18 12:32:21adminsetmessages: + msg16612
2026-09-10 14:03:08adminsetmessages: + msg16582
2026-05-18 00:00:00admincreate