cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2738 [expr.prim.id.unqual] What id-expression denotes a destructor is underspecified #313

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

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

The original issue is https://github.com/cplusplus/draft/issues/5449, which is confirmed by @opensdh in https://github.com/cplusplus/draft/issues/5346#issuecomment-1072949401, it should be a CWG issue.

jensmaurer commented 1 year ago

CWG2738

xmh0511 commented 10 months ago

The proposal wording may have an issue here

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

What if the type-name is a template name?

template<class T>
struct A{};

int main(){
   auto ptr = new A<int>;
   ptr->~A();
}

In this case the type-name A is not a type, instead, it is a template name. It may need to be changed to

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

jensmaurer commented 10 months ago

A template doesn't have a destructor, only class types do.

Also, don't you get member name lookup for this case, finding the injected-class-name "A" (which is a type name, not a template name)?

opensdh commented 10 months ago

A template doesn't have a destructor, only class types do.

CTAD enters the chat

One could easily imagine extending its logic to destructors, but fortunately the ordinary interpretation is what we want here.