Title
Required diagnostic for partial specialization after first use
Status
drafting
Section
13.7.6.1 [temp.spec.partial.general]
Submitter
John Spicer

Created on 2015-10-12.00:00:00 last changed 87 months ago

Messages

Date: 2022-06-11.20:21:09

According to 13.7.6.1 [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.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: open -> drafting
2015-10-12 00:00:00admincreate