This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-09-14


3006. Vague restrictions for explicit instantiations of class templates

Section: 13.9.3  [temp.explicit]     Status: review     Submitter: Richard Smith     Date: 2021-02-11

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. ...

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. ...