开发者

MSVC10 SFINAE causing fatal error rather than substitution failure

开发者 https://www.devze.com 2023-03-06 05:58 出处:网络
I\'ve got a (relatively) brief code sample here. #include <type_traits> template&开发者_运维问答lt;typename T> class function;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消