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

2024-04-18


2498. Partial specialization failure and the immediate context

Section: 13.10.3.1  [temp.deduct.general]     Status: open     Submitter: Daveed Vandevoorde     Date: 2021-06-15

Consider the following example:

  template<typename T, typename U> struct S {};
  template<typename T> struct S<T, T> {};
  template<typename T, typename U> struct S<T*, U*> {};
  template<typename... Ts> using V = void;
  template<typename T, typename U = void> struct X {};
  template<typename T> struct X<T, V<typename S<T, T>::type>>;
  X<int*> xpi;

Determining whether the partial specialization of X matches X<int*> requires determining whether one of the partial specializations of S matches S<int*,int*>. The partial specializations of S are ambiguous for this case. The question is whether that ambiguity should be considered in the “immediate context” of the type (SFINAE) or whether it should result in a hard error. There is implementation divergence on the handling of this example.

Notes from the November, 2021 teleconference:

A similar example can be constructed involving overload resolution instead of partial specialization:

  template<typename T, typename U> struct S {};
  template<typename T> struct S<T, T> {};
  template<typename T, typename U> struct S<T*, U*> {};

  template<class T>
  bool f(T, typename S<T, T>::type = 0);
  bool f(...);

  int x;
  bool b = f(&x);  // hard error with gcc, ok with clang