I get an error about mismatched noexcept specifications when I use templates in conjunction with the noexcept
specifier. It compiles with various versions of clang I've used and fails in all versions of gcc.
struct Y
{
void h();
};
template<typename T>
struct X
{
void f() noexcept(noexcept(std::declval<Y>().h()));
};
template<typename T>
void X<T>::f() noexcept(noexcept(std::declval<Y>().h()))
{
}
int main()
{
}
Error:
g++ -std=c++1y -O2 -Wall -pthread main.cpp && ./a.out
main.cpp:15:56: error: declaration of 'void X<T>::f() noexcept (noexcept (declval<Y>().Y::f()))' has a different exception specifier
void X<T>::f() noexcept(noexcept(std::declval<Y>().f()))
^
main.cpp:11:10: error: from previous declaration 'void X<T>::f() noexcept (noexcept (declval<Y>().Y::f()))'
void f() noexcept(noexcept(std::declval<Y>().f()));
^
Is this a bug? Is there any way to get around it?