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.

4437. constant_of(^^v) for variable v of array type produces reflection of pointer constant

Section: 21.4.7 [meta.reflection.queries] Status: New Submitter: Tomasz KamiƄski Opened: 2025-10-29 Last modified: 2025-10-31

Priority: Not Prioritized

View other active issues in [meta.reflection.queries].

View all other issues in [meta.reflection.queries].

View all issues with New status.

Discussion:

The unintended consequence of the late change of reflect_constant to accept its parameter by value is that constant_of(a) returns a reflection of the value &a[0] for a variable of array type.

For reference, constant_of is specified as:

if constexpr (is_annotation(R))  {
  return C;
} else { 
  return reflect_constant([: R :]);
}

In case when [: R :] is a reference to array, it will decay to a pointer to the first element when accepted by value. I believe this is unintended and we should return an reflection of an array object instead.

Proposed resolution:

This wording is relative to N5014.

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

    consteval info constant_of(info r);
    

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

    -7- Effects: Equivalent to:

    if constexpr (is_annotation(R)) {
      return C;
    } else if constexpr (is_array_type(type_of(R))) {
      return reflect_constant_array([: R :]);
    } else {
      return reflect_constant([: R :]);
    }