Title
Vague restrictions for explicit instantiations of class templates
Status
review
Section
13.9.3 [temp.explicit]
Submitter
Richard Smith

Created on 2021-02-11.00:00:00 last changed 4 days ago

Messages

Date: 2025-09-14.05:51:33

CWG 2025-09-12

Instantiating a nested class is not supported with the syntax restriction in the resolution above. Instead, restrict on the naming of the injected-class-name.

Possible resolution (September, 2025):

Change in 13.9.3 [temp.explicit] paragraph 4 as follows:

If the declaration in an explicit instantiation is an elaborated-type-specifier, the explicit instantiation is for a class or member class, (possibly a nested class) and the elaborated-type-specifier in the declaration shall include a simple-template-id not name an injected-class-name; otherwise, the declaration shall be a simple-declaration whose init-declarator-list comprises a single init-declarator that does not have an initializer . If the explicit instantiation is for a variable template specialization, the unqualified-id in the declarator shall be a simple-template-id. ...
Date: 2025-09-14.05:51:33

Consider:

  template<typename T> struct X { };

  extern template struct X<int>;       // OK
  extern template struct X<int>::X;    // well-formed explicit instantiation of X<int> ?

At issue is the phrasing "shall include" in 13.9.3 [temp.explicit] paragraph 4:

If the explicit instantiation is for a class or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id; otherwise, the declaration shall be a simple-declaration whose init-declarator-list comprises a single init-declarator that does not have an initializer. ...

Possible resolution (March, 2025) [SUPERSEDED]:

Change in 13.9.3 [temp.explicit] paragraph 4 as follows:

If the declaration in an explicit instantiation is an elaborated-type-specifier, it shall be of the form
class-key nested-name-specifieropt templateopt simple-template-id
and the explicit instantiation is for a class template or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id; otherwise, the declaration shall be a simple-declaration whose init-declarator-list comprises a single init-declarator that does not have an initializer. ...
History
Date User Action Args
2025-09-14 05:51:33adminsetmessages: + msg8105
2025-09-14 05:51:33adminsetstatus: open -> review
2021-02-11 00:00:00admincreate