Title
`constant_of(^^v)` for variable `v` of array type produces reflection of pointer constant
Status
resolved
Section
[meta.reflection.queries]
Submitter
Tomasz Kamiński

Created on 2025-10-29.00:00:00 last changed 1 week ago

Messages

Date: 2025-11-11.12:45:27

Proposed resolution:

This wording is relative to N5014.

  1. Modify [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 :]);
    }
    
Date: 2025-11-15.00:00:00

[ 2025-11-11; Resolved by CWG 3111, approved in Kona. Status changed: New → Resolved. ]

Date: 2025-11-07.19:19:35

[ Kona 2025-11-07; Will be resolved by CWG 3111. ]

Date: 2025-10-29.00:00:00

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.

History
Date User Action Args
2025-11-11 12:45:27adminsetmessages: + msg15714
2025-11-11 12:45:27adminsetstatus: new -> resolved
2025-11-07 19:19:35adminsetmessages: + msg15594
2025-10-31 11:11:35adminsetmessages: + msg15475
2025-10-29 00:00:00admincreate