'Is a diagnostic required for unused member templates with ill formed default template parameters?

Consider the following class template:

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

Is it ill formed to instantiate S with template parameters T, for which auto = T() is ill formed?

int main()
{
    S<int> a;    // ok
    S<int&> b;   // error
    S<int()> c;  // gcc ok, clang error
}

This seems to be the case, but the issue is with c, where S is instantiated with a function type. gcc is ok with this, while clang says:

error: cannot create object of function type 'int ()'

which makes sense. Since gcc does diagnose the instantiation with int&, I suspect this is a gcc bug. Is that right, or is a diagnostic not required for this code?



Solution 1:[1]

This is CWG1635:

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

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1