This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2948. Late ambiguity for partial template specialization

Section: 13.7.6.1  [temp.spec.partial.general]     Status: open     Submitter: Mauro Russo     Date: 2024-11-01

If a partial specialization is introduced later than where it would have been used, the program is ill-formed, no diagnostic required. The same should apply if the late declaration would have caused an ambiguity.

Also consider removing the redundancy between 13.4.4 [temp.arg.template] paragraph 2 and 13.7.6.1 [temp.spec.partial.general] paragraph 1 for that matter.

Possible resolution:

  1. Change in 13.4.4 [temp.arg.template] paragraph 2 as follows:

    Any partial specializations (13.7.6 [temp.spec.partial]) associated with the primary template are considered when a specialization based on the template template-parameter is instantiated. If a specialization is not reachable from the point of instantiation, and it would have been selected had it been reachable, the program is ill-formed, no diagnostic required. [ Note: A partial specialization cannot be introduced after its first potential use (13.7.6.1 [temp.spec.partial.general]). -- end note ]
  2. Change in 13.7.6.1 [temp.spec.partial.general] paragraph 1 as follows:

    A partial specialization of a template provides an alternative definition of the template that is used instead of the primary definition when the arguments in a specialization match those given in the partial specialization (13.7.6.2 [temp.spec.partial.match]). A declaration of the primary template shall precede any partial specialization of that template. A partial specialization shall be reachable from any use of a template specialization that would make use of the partial specialization as the result of an implicit or explicit point of instantiation where that partial specialization would have been selected or would have contributed to ambiguity; no diagnostic is required.