cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.7k stars 751 forks source link

[expr.prim.id.unqual] What id-expression denotes a destructor? CWG2738 #5449

Open xmh0511 opened 2 years ago

xmh0511 commented 2 years ago

In the current draft, we merely have a note that says

A type-name or decltype-specifier prefixed by ~ denotes the destructor of the type so named; see [expr.prim.id.dtor].

The note cross-references [expr.prim.id.dtor], however, in that subclause, we still cannot find a rule to specifies what id-expression denotes a destructor.

An id-expression that denotes the destructor of a type T names the destructor of T if T is a class type ([class.dtor]), otherwise the id-expression is said to name a pseudo-destructor.

Maybe, we should have a formal rule like that:

An unqualified-id with the form ~type-name or ~decltype-specifier denotes the destructor of a type denoted by the type-name or decltype-specifier([basic.lookup.qual.general]).

jensmaurer commented 2 years ago

The note is in [expr.prim.id.unqual] p1

xmh0511 commented 2 years ago

The note is in [expr.prim.id.unqual] p1

We expect a formal rule to clarify that an id-expression denotes a destructor. BTW, I cited the note in this issue.

frederick-vs-ja commented 2 years ago

It seems that we can just turn the note into a formal rule as-is.

xmh0511 commented 2 years ago

The note sounds good but it is not formal since the "so named" has no clear definition. I would prefer to use

A type-name or decltype-specifier prefixed by ~ denotes the destructor of the type denoted/referred to by it([basic.lookup], [dcl.type.decltype]).

xmh0511 commented 2 years ago

The note in [expr.prim.id.unqual]/1 suggests that [expr.prim.id.dtor] covers this (which might be why I missed it for P1787), but in fact the latter relies on "denotes the destructor" rather than defining it. This should perhaps be treated as a separate issue.

The separated issue as pointed out in https://github.com/cplusplus/draft/issues/5346#issuecomment-1072949401