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


2179. Required diagnostic for partial specialization after first use

Section:  [temp.spec.partial.general]     Status: drafting     Submitter: John Spicer     Date: 2015-10-12

According to [temp.spec.partial.general] paragraph 1,

A partial specialization shall be declared before the first use of a class template specialization that would make use of the partial specialization as the result of an implicit or explicit instantiation in every translation unit in which such a use occurs; no diagnostic is required.

There are two problems with this wording. First, the “no diagnostic required” provision is presumably to avoid mandating cross-translation-unit analysis, but there is no reason not to require the diagnostic if the rule is violated within a single translation unit. Also, “would make use” is imprecise; it could be interpreted as applying only when the partial specialization would have been selected by a previous specialization, but it should also apply to cases where the partial specialization would have made a previous specialization ambiguous.

Making these two changes would guarantee that a diagnostic is issued for the following example:

   template <class T1, class T2> class A;
   template <class T> struct A<T, void> { void f(); };
   template <class T> void g(T) { A<char, void>().f(); }   // #1
   template<typename T> struct A<char, T> {};
   A<char, void> f;   // #2

It is unspecified whether the reference to A<char, void> at #1 is the “first use” or not. If so, A<char, void> is bound to the first partial specialization and, under the current wording, an implementation is not required to diagnose the ambiguity resulting from the second partial specialization. If #2 is the “first use,” it is clearly ambiguous and must result in a diagnostic. There is implementation divergence on the handling of this example that would be addressed by the suggested changes.