下面的代碼片段是由鐺拒絕:異常規範和模板
template <typename T> void foo() noexcept {}
template <typename T> void bar() throw() {}
template void foo<int>();
template void bar<int>();
隨着clang++ -std=c++1z -c
我得到:
compat.ii:3:15: error: explicit instantiation of 'foo' does not refer to a function template, variable template, member function, member class, or static data member
template void foo<int>();
^
compat.ii:1:28: note: candidate template ignored: could not match 'void() noexcept' against 'void()'
template <typename T> void foo() noexcept {}
^
compat.ii:4:15: error: explicit instantiation of 'bar' does not refer to a function template, variable template, member function, member class, or static data member
template void bar<int>();
^
compat.ii:2:28: note: candidate template ignored: could not match 'void() throw()' against 'void()'
template <typename T> void bar() throw() {}
^
2 errors generated.
GCC主幹接受與-std=c++1z
的代碼。 哪個編譯器是正確的?
我假設鏗鏘工作,如果你添加'noexcept'到'void foo'和'throw()'到'void bar ''? –
ildjarn
我的中繼gcc拒絕這樣的代碼。 wandbox也是如此。 – krzaq