Title
Value-dependent structured bindings
Status
open
Section
13.8.3.4 [temp.dep.constexpr]
Submitter
Michael Park

Created on 2025-01-14.00:00:00 last changed 3 months ago

Messages

Date: 2025-02-24.22:00:51

Consider:

  struct S { int x; };

  template <S s>
  void f() {
   constexpr auto [x] = s;
   constexpr bool b = (x == 0); // x ought to be value-dependent
  }

The rules in 13.8.3.4 [temp.dep.constexpr] do not seem to cover the case of structured bindings.

Possible resolution (January, 2025) [SUPERSEDED]:

Change in 13.8.3.4 [temp.dep.constexpr] paragraph 2 as follows:

An id-expression is value-dependent if
  • it is a concept-id and any of its arguments are dependent,
  • it is type-dependent,
  • it is the name of a non-type template parameter,
  • it names a static data member that is a dependent member of the current instantiation and is not initialized in a member-declarator,
  • it names a static member function that is a dependent member of the current instantiation, or
  • it names a potentially-constant variable (7.7 [expr.const]) that is initialized with an expression that is value-dependent. , or
  • it names a structured binding whose associated variable (9.7 [dcl.struct.bind]) is value-dependent.

Possible resolution (February, 2025):

  1. Change in 13.8.3.4 [temp.dep.constexpr] paragraph 2 as follows:

    An id-expression is value-dependent if
    • it is a concept-id and any of its arguments are dependent,
    • it is type-dependent,
    • it is the name of a non-type template parameter,
    • it names a static data member that is a dependent member of the current instantiation and is not initialized in a member-declarator,
    • it names a static member function that is a dependent member of the current instantiation, or
    • it names a potentially-constant variable (7.7 [expr.const]) that is initialized with an expression that is value-dependent. , or
    • it names a structured binding whose structured binding declaration (9.7 [dcl.struct.bind]) has a brace-or-equal-initializer that is value-dependent.
  2. Add after 13.8.3.4 [temp.dep.constexpr] paragraph 6 as follows:

    ... An expression of the form &cast-expression is also value-dependent if evaluating cast-expression as a core constant expression (7.7 [expr.const]) succeeds and the result of the evaluation refers to a templated entity that is an object with static or thread storage duration or a member function.

    A braced-init-list is value-dependent if any element is value-dependent or is a pack expansion.

History
Date User Action Args
2025-01-14 00:00:00admincreate