假设我们有以下简单的代码:
#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);
}
Run Code Online (Sandbox Code Playgroud)
此代码使用 Clang 编译并打印“T”,但使用 GCC 时出现以下错误:
error: call of overloaded 'S(int)' is ambiguous
Run Code Online (Sandbox Code Playgroud)
我的问题是:GCC 还是 Clang 哪个编译器有 bug?