struct X{};
template<class T>
decltype(X() == int()) f(T const&){ return true; }
int main(void) {
X x;
f(x);
}
なぜ、なぜ?どこoperator==
にも定義されていません!
MS Connectの詳細なバグレポートを提供するために、ここで何が起こっているのかを本当に理解したいと思います。狂気への私の旅は、このあたりのラウンジ<C++>チャットルームで始まりました...
(注:GCCもClangもこのコードを受け入れません。)
ああ、ところで、プライベートX(int)
ctorを追加すると、コンパイルが失敗します。
struct X{
X(){}
private:
X(int);
};
template<class T>
decltype(X() == int()) f(T const&){ return true; }
int main(void) {
X x;
f(x);
}
出力:
1>src\main.cpp(12): error C2248: 'X::X' : cannot access private member declared in class 'X'
1> src\main.cpp(4) : see declaration of 'X::X'
1> src\main.cpp(1) : see declaration of 'X'