Open Rush10233 opened 1 week ago
@llvm/issue-subscribers-clang-frontend
Author: None (Rush10233)
Clang does reject if you try to instantiate the default argument: https://godbolt.org/z/nno7G7v65 GCC instead rejects if you instantiate the class. Testcase reduces to:
template <typename T> struct S {
friend void foo (S, int a = T::error) {}
};
// GCC rejects this instantiation, Clang accepts
S<int> t;
// Clang rejects this instantiation
void f() { foo(t); }
So the question is, is this default argument expression supposed to be instantiated with the class or not?
As far as I can see, GCC is right here: delayed instantiation of default arguments applies only to member functions and function templates (see also here), and a friend function of a class template is neither, so its default arguments should be instantiated with the class.
Interestingly, the same applies to noexcept-specifiers, which GCC gets wrong like Clang: https://godbolt.org/z/vE3o8Pb6d
The following code contains an invalid type conversion:
In line 4 , the default argument value of the integer variable
a
is set to a nested lambda expression with the inner one returning an integer and the outer one returning nothing. The code compiles well in clang, while GCC outputs the following error message:Please note that if we replace the template class
S
with a non-template one, clang rejects the code by giving a similar error message with GCC.https://godbolt.org/z/v1Gs3Kcf6