This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 109b. See for the official list.


727. In-class explicit specializations

Section: 13.9.4  [temp.expl.spec]     Status: C++17     Submitter: Faisal Vali     Date: 5 October, 2008

[Adopted as a DR at the February/March, 2017 meeting.]

13.9.4 [temp.expl.spec] paragraph 2 requires that explicit specializations of member templates be declared in namespace scope, not in the class definition. This restriction does not apply to partial specializations of member templates; that is,

    struct A {
      template<class T> struct B;
      template <class T> struct B<T*> { }; // well-formed
      template <> struct B<int*> { }; // ill-formed

There does not seem to be a good reason for this inconsistency.

Additional note (October, 2013):

EWG has requested CWG to consider resolving this issue. See EWG issue 41.

Additional note, November, 2014:

See also paper N4090.

Proposed resolution (March, 2017):

  1. Change [temp.spec.partial.general] paragraph 6 as follows:

  2. A class template partial specialization may be declared or redeclared in any namespace scope in which the corresponding primary template may be defined (_N4868_. [namespace.memdef] and , 11.4 [class.mem], 13.7.3 [temp.mem]). [Example:

      template<class T> struct A {
        struct C {
          template<class T2> struct B { };
          template<class T2> struct B<T2**> { };  // partial specialization #1
      // partial specialization of A<T>::C::B<T2>
      template<class T> template<class T2>
        struct A<T>::C::B<T2*> { };    // #2
      A<short>::C::B<int*> absip; // uses partial specialization #2

    end example]

  3. Change 13.9.4 [temp.expl.spec] paragraph 2 as follows:

  4. An explicit specialization shall be declared in a namespace enclosing the specialized template. An explicit specialization whose declarator-id or class-head-name is not qualified shall be declared in the nearest enclosing namespace of the template, or, if the namespace is inline (9.8.2 [namespace.def]), any namespace from its enclosing namespace set. Such a declaration may also be a definition may be declared in any scope in which the corresponding primary template may be defined (_N4868_. [namespace.memdef], 11.4 [class.mem], 13.7.3 [temp.mem]). If the declaration is not a definition, the specialization may be defined later (_N4868_. [namespace.memdef]).