假设我们有如下简单的代码:
#include <iostream>
#include <type_traits>
struct S {
template <typename T> explicit S(T) noexcept requires std::is_signed<T>::value {
std::cout << "T\n";
}
template<typename T> explicit S(const T&) noexcept {
std::cout << "const T&\n";
}
};
int main() {
S s(4);
}
这段代码在使用Clang编译时可以顺利运行并输出'T',但在使用GCC编译时会出现以下错误:
error: call of overloaded 'S(int)' is ambiguous
我的问题是:GCC还是Clang编译器有bug?
requires
子句使得T
版本更加特殊,应该优先于constT&
版本。我认为gcc有个bug。 - Ted Lyngmo