【发布时间】:2018-09-14 03:15:53
【问题描述】:
考虑以下 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;
}
clang 编译得很好。 DEMO
但 GCC 失败:
error: no match for 'operator+' (operand types are 'int' and 'A')
return x + a;
~~^~~
问题:谁是对的,为什么?
【问题讨论】:
标签: c++ c++11 language-lawyer