Title
Names of constructors and destructors of templates
Status
nad
Section
6.5.5.2 [class.qual]
Submitter
Martin Sebor

Created on 2007-05-23.00:00:00 last changed 211 months ago

Messages

Date: 2007-07-15.00:00:00

Rationale (July, 2007):

The CWG noted that the suggested change would be confusing in the case where the class template had both template and non-template constructors.

Date: 2022-11-20.07:54:16

There is a discrepancy between the syntaxes allowed for defining a constructor and a destructor of a class template. For example:

    template <class> struct S { S(); ~S (); };
    template <class T> S<T>::S<T>() { }        // error
    template <class T> S<T>::~S<T>() { }       // okay

The reason for this is that 6.5.5.2 [class.qual] paragraph 2 says that S::S is “considered to name the constructor,” which is not a template and thus cannot accept a template argument list. On the other hand, the second S in S::~S finds the injected-class-name, which “can be used with or without a template-argument-list” (13.8.2 [temp.local] paragraph 1) and thus satisfies the requirement to name the destructor's class (11.4.7 [class.dtor] paragraph 1).

Would it make sense to allow the template-argument-list in the constructor declaration and thus make the language just a little easier to use?

History
Date User Action Args
2007-08-05 00:00:00adminsetmessages: + msg1530
2007-08-05 00:00:00adminsetstatus: open -> nad
2007-05-23 00:00:00admincreate