鉴于以下代码,
template <class> using void_t = void;
template <class C, class = void> struct X { enum { v = 0 }; };
template <class C> struct X<C, void_t<typename C::T> > { enum { v = 1 }; };
struct T { };
int main() { return X<T>::v; }
Run Code Online (Sandbox Code Playgroud)
什么应该主要回归?GCC和MSVC说1,Clang说0.
除非注释行被取消注释,否则以下代码无法编译:
template <class T> struct R { static T& r(); };
struct M {
static char m(M&);
template <class T> static int m(const T&);
};
template <class T> struct A;
template <class T>
struct B {
struct U { };
struct V { M& operator,(U); };
enum { v = sizeof(M::m((R<V>::r(), R<A<T>*>::r()))) };
};
template <class T> struct A { B<T> y; };
int main()
{
// A<int>(); // Works if uncommented.
B<int>();
}
Run Code Online (Sandbox Code Playgroud)
在逗号运算符中,编译器认为它需要A<int>完成,即使代码只是在流量中A<T>*.我不明白为什么.它与clang和g ++都失败了.克朗说 …