CWG Issue 727 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-04-13
727. In-class explicit specializations
Section: 13.9.4 [temp.expl.spec]Status: C++17Submitter: Faisal ValiDate: 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):
- Change 13.7.6.1 [temp.spec.partial.general] paragraph 6 as follows:
A class template partial specialization may be declared
or redeclaredin anynamespacescope 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 struct A { struct C { template struct B { }; template struct B<T2**> { }; // partial specialization #1 }; };
// partial specialization of A::C::B template template struct A::C::B<T2*> { }; // #2
A::C::B<int*> absip; // uses partial specialization #2
—_end example_]
- Change 13.9.4 [temp.expl.spec] paragraph 2 as follows:
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.9.2 [namespace.def]), any namespace from its enclosing namespace set. Such a declaration may also be a definitionmay 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]).