下面的代码片段是由铛拒绝:异常规范和模板
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