MSVC10 SFINAE causing fatal error rather than substitution failure
I've got a (relatively) brief code sample here.
#include <type_traits>
template&开发者_运维问答lt;typename T> class function;
template<typename Ret> class function<Ret()> {
public:
template<typename Func> function(Func f, typename std::enable_if<std::is_same<Ret, decltype(f())>::value, int>::type x = 0) {
}
};
template<typename Ret, typename A1> class function<Ret(A1)> {
public:
template<typename Func> function(Func f, typename std::enable_if<std::is_same<Ret, decltype(f(*((A1*)nullptr)))>::value, int>::type x = 0) {
}
};
namespace lols {
int x() { return 0; }
int y(int) { return 0; }
}
void func(function<int()>) {}
void func(function<int(int)>) {}
int main() {
func(&lols::x);
func(&lols::y);
}
MSVC throws on this, saying that type
is not a member of enable_if<false, int>
, which is kind of the point. What I don't get is why this causes a fatal error instead of just a substitution failure- on GCC this code behaves exactly as expected and compiles cleanly.
clang compiles and runs your code without complaint.
精彩评论