cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2910 [basic.def.odr] Effect of requirement-parameter-lists on odr-usability #561

Open hubert-reinterpretcast opened 1 week ago

hubert-reinterpretcast commented 1 week ago

Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong

Reference (section label): basic.def.odr

Link to reflector thread (if any): N/A

Issue description: Consider

bool f() {
  constexpr int z = 42;
  return requires {
    sizeof(int [*&z]);
  } && requires (int x) {
    sizeof(int [*&z]);
  };
}

According to https://wg21.link/basic.scope.param, a function parameter scope is produced for the second requires-expression.

This means that, under https://wg21.link/basic.def.odr#10, there is an intervening function parameter scope that prevents z from being odr-usable in the context where it is named in the second requires-expression. There does not appear to be a good reason for the two requires-expression‌s to behave differently.

Suggested resolution: Insert in https://eel.is/c++draft/basic.def.odr#10.2.2:

  • the intervening scope is the function parameter scope of a requires-expression or a lambda-expression [...]
jensmaurer commented 1 week ago

CWG2910