Title
In-class explicit specializations
Status
c++17
Section
13.9.4 [temp.expl.spec]
Submitter
Faisal Vali

Created on 2008-10-05.00:00:00 last changed 81 months ago

Messages

Date: 2017-03-15.00:00:00

Proposed resolution (March, 2017):

  1. Change 13.7.6.1 [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_.9.8.2.3 [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_.9.8.2.3 [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_.9.8.2.3 [namespace.memdef]).
Date: 2014-11-24.00:00:00

Additional note, November, 2014:

See also paper N4090.

Date: 2013-10-15.00:00:00

Additional note (October, 2013):

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

Date: 2017-02-15.00:00:00

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

History
Date User Action Args
2018-02-27 00:00:00adminsetmessages: + msg6171
2018-02-27 00:00:00adminsetstatus: drafting -> c++17
2014-11-24 00:00:00adminsetmessages: + msg5229
2014-03-03 00:00:00adminsetstatus: open -> drafting
2013-10-14 00:00:00adminsetmessages: + msg4668
2013-10-14 00:00:00adminsetstatus: extension -> open
2009-03-23 00:00:00adminsetstatus: open -> extension
2008-10-05 00:00:00admincreate