考虑以下MCVE.
#include <type_traits>
struct A {
template<typename T, typename std::enable_if<std::is_same<T,int>::value,int>::type = 0>
operator T() const { return static_cast<T>(1); }
};
int main() {
int x = 1;
A a;
return x + a;
}
Run Code Online (Sandbox Code Playgroud)
clang汇编得很好.DEMO
但海湾合作委员会失败了:
error: no match for 'operator+' (operand types are 'int' and 'A')
return x + a;
~~^~~
Run Code Online (Sandbox Code Playgroud)
问题:谁是对的?为什么?