Open
Description
The following code is rejected by clang for the mismatch of the noexcept
specifier between the friend declaration and definition of func
:
template <typename T>
struct C {
template <int N>
friend void func() noexcept(N == 0);
};
template <int N>
void func() noexcept(N == 0) {}
int main() {
C<int> t;
return 0;
}
The diagnostic says that:
<source>:4:17: error: exception specification in declaration does not match the previous declaration
4 | friend void func() noexcept(N == 0);
| ^
<source>:11:12: note: in instantiation of template class 'C<int>' requested here
11 | C<int> t;
| ^
<source>:8:6: note: previous declaration is here
8 | void func() noexcept(N == 0) {}
That is quite unreasonable. It should be clear that the noexcept
expression of func
keeps identical between the friend declaration and definition statement. Removing the dependent name N
in the noexcept
expression or replacing template class C
with a non-template one can eliminate the diagnostic.