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

2025-03-14


3006. Vague restrictions for explicit instantiations of class templates

Section: 13.9.3  [temp.explicit]     Status: open     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. ...

Furthermore, explicit instantiations with a nested-name-specifier do not seem to be declarative.

Possible resolution:

  1. 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. ...
  2. Change in 7.5.5.3 [expr.prim.id.qual] paragraph 2 as follows:

    A nested-name-specifier is declarative if it is part of
    • a class-head-name (11.1 [class.pre]),
    • an enum-head-name (9.7.1 [dcl.enum]),
    • a qualified-id that is the id-expression of a declarator-id (9.3.1 [dcl.decl.general]), or
    • an elaborated-type-specifier of an explicit instantiation (13.9.3 [temp.explicit]), or
    • a declarative nested-name-specifier.