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


1635. How similar are template default arguments to function default arguments?

Section: 13.2  [temp.param]     Status: drafting     Submitter: Richard Smith     Date: 2013-03-06

Default function arguments are instantiated only when needed. Is the same true of default template arguments? For example, is the following well-formed?

  #include <type_traits>

  template<class T>
  struct X {
    template<class U = typename T::type>
    static void foo(int){}
    static void foo(...){}
  };

  int main(){
    X<std::enable_if<false>>::foo(0);
  }

Also, is the effect on lookup the same? E.g.,

  struct S {
    template<typename T = U> void f();
    struct U {};
  };

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.