This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-10-26


2517. Useless restriction on use of parameter in constraint-expression

Section: 7.5.8.5  [expr.prim.req.nested]     Status: C++23     Submitter: Richard Smith     Date: 2019-06-10

[Accepted as a DR at the February, 2023 meeting.]

According to 7.5.8.5 [expr.prim.req.nested] paragraph 2,

A local parameter shall only appear as an unevaluated operand (7.2.3 [expr.context]) within the constraint-expression. [Example 2:

  template<typename T> concept C = requires (T a) {
    requires sizeof(a) == 4; // OK
    requires a == 0; // error: evaluation of a constraint variable
  };

end example]

However, a can't be used in a constant expression in any event, so the restriction is meaningless, except for ruling out an expression like true ? true : a, but there seems no reason to have a special rule for such a case.

Proposed resolution (approved by CWG 2023-01-06):

Remove 7.5.8.5 [expr.prim.req.nested] paragraph 2, including its example:

A local parameter shall only appear as an unevaluated operand (7.2.3 [expr.context]) within the constraint-expression. [Example 2:

  template<typename T> concept C = requires (T a) {
    requires sizeof(a) == 4; // OK
    requires a == 0; // error: evaluation of a constraint variable
  };

Additional notes (February, 2023)

After adopting paper P2280, it is no longer accurate that any use of requirement parameters makes an expression non-constant. However, the resolution as adopted makes the treatment of examples like the following uniform in requirements and other constant expression contexts:

  template<typename ArrayType> concept LargeArray =
    requires (ArrayType my_array) { requires my_array.size() > 5; }