Created on 2023-07-05.00:00:00 last changed 1 month ago
Proposed resolution (approved by CWG 2023-09-15):
Change in 6.4.1 [basic.scope.scope] paragraph 5 and add bullets as follows:
A declaration is name-independent if its name is _ and it declares
- a variable with automatic storage duration,
- a structured binding with no storage-class-specifier and not inhabiting a namespace scope,
- the variable introduced by an init-capture, or
- a non-static data member of other than an anonymous union.
Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:
Change in 6.4.1 [basic.scope.scope] paragraph 5 and add bullets as follows:
A class is name-dependent if it is an anonymous union declared at namespace scope or with a storage-class-specifier (11.5.2 [class.union.anon]). A declaration is name-independent if its name is _ and it declares
- a variable with automatic storage duration,
- a structured binding with no storage-class-specifier and not inhabiting a namespace scope,
- the variable introduced by an init-capture, or
- a non-static data member of other than a name-dependent class.
[Accepted as a DR at the November, 2023 meeting.]
Paper P2169R4 (A nice placeholder with no name), as approved by WG21 in Varna, added a placeholder facility. The intent was that the use of placeholders is sufficiently limited such that they never need to be mangled. Quote from 6.4.1 [basic.scope.scope] paragraph 5 as modified by the paper:
A declaration is name-independent if its name is _ and it declares a variable with automatic storage duration, a structured binding not inhabiting a namespace scope, the variable introduced by an init-capture, or a non-static data member.
The following example does not seem to follow that intent:
struct A { A(); };
inline void f() {
static union { A _{}; };
static union { A _{}; };
}
void g() { return f(); }
The preceding example needs handling similar to the following example, which is unrelated to the placeholder feature:
struct A { A(); };
inline void f() {
{ static union { A a{}; }; }
{ static union { A a{}; }; }
}
void g() { return f(); }
A similar problem may arise for static or thread_local structured bindings at block scope.
Finally, another example involving placeholders in anonymous unions:
static union { int _ = 42; };
int &ref = _;
int foo() { return 13; }
static union { int _ = foo(); };
int main() { return ref; }
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-11-06 23:04:52 | admin | set | messages: + msg8251 |
| 2025-09-12 22:42:26 | admin | set | status: open -> cd7 |
| 2025-09-12 22:42:26 | admin | set | status: drwp -> open |
| 2024-04-05 21:43:46 | admin | set | status: dr -> drwp |
| 2023-12-19 10:15:28 | admin | set | status: ready -> dr |
| 2023-11-10 14:27:11 | admin | set | status: tentatively ready -> ready |
| 2023-09-15 21:23:20 | admin | set | status: review -> tentatively ready |
| 2023-08-26 21:49:54 | admin | set | messages: + msg7405 |
| 2023-08-26 21:49:54 | admin | set | status: open -> review |
| 2023-07-05 00:00:00 | admin | create | |