Title
Use of placeholders affecting name mangling
Status
drwp
Section
6.4.1 [basic.scope.scope]
Submitter
Hubert Tong

Created on 2023-07-05.00:00:00 last changed 1 month ago

Messages

Date: 2023-09-15.21:23:20

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.
Date: 2023-11-15.00:00:00

[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; }

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.
History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-11-10 14:27:11adminsetstatus: tentatively ready -> ready
2023-09-15 21:23:20adminsetstatus: review -> tentatively ready
2023-08-26 21:49:54adminsetmessages: + msg7405
2023-08-26 21:49:54adminsetstatus: open -> review
2023-07-05 00:00:00admincreate