Title
Disambiguation of T x = delete("text")
Status
open
Section
9.5.1 [dcl.fct.def.general]
Submitter
Richard Smith

Created on 2024-03-22.00:00:00 last changed 3 weeks ago

Messages

Date: 2024-04-07.11:43:58

Suggested resolution:

Change and split in 9.1 [dcl.pre] paragraph 9 as follows:

Syntactic components beyond those found in the general form of simple-declaration are added to a function declaration to make a function-definition. A token sequence starting with = is treated as a function-body (9.5.1 [dcl.fct.def.general]) if the type of the declarator-id (9.3.4.1 [dcl.meaning.general]) is a function type, and is otherwise treated as a brace-or-equal-initializer (9.4.1 [dcl.init.general]). [ Note: If the declaration acquires a function type through template instantiation, the program is ill-formed; see 13.9.1 [temp.spec.general]. --end note ]

An object declaration, however, is also a definition unless it contains the extern specifier and has no initializer (6.2 [basic.def]). An object definition causes storage of appropriate size and alignment to be reserved and any appropriate initialization (9.4 [dcl.init]) to be done. [ Note: An object declaration is also a definition unless it contains the extern specifier and has no initializer (6.2 [basic.def]). ]

Date: 2024-04-07.11:45:18

P2573R2 (= delete("should have a reason");), adopted in Tokyo, does not disambiguate the following syntax:

  using T = void ();
  using U = int;

  T a = delete ("hello");
  U b = delete ("hello");

Either may be parsed as a (semantically ill-formed) simple-declaration whose initializer is a delete-expression or as a function-definition.

History
Date User Action Args
2024-04-07 11:43:58adminsetmessages: + msg7660
2024-03-22 00:00:00admincreate