MSVC evaluating context (and erroring) without knowing types

Viewed 75

This code fails compilation on MSVC because the static_assert fails:

template<class MyType>
struct Test {
    static_assert(MyType(5) != MyType(6), "fails");
};

See: https://godbolt.org/z/vUSMHu

Any ideas how MSVC can evaluate this without even knowing what MyType is?

Even more obscure:

template<class MyType>
struct Test {
    static_assert(MyType(5) == MyType(6), "succeeds");
    static_assert(!(MyType(5) == MyType(6)), "fails");
};

See: https://godbolt.org/z/3631tu

And instantiating it (i.e. giving MyType a type) also doesn't help:

template<class MyType>
struct Test {
    static_assert(MyType(5) != MyType(6), "still fails");
};
Test<int> variable;

See: https://godbolt.org/z/yxF4h0

Or a bit more complex: https://godbolt.org/z/68g6yO

1 Answers

Yes, this strange error happens in MSVC 19.10, but it is already not reproducible in MSVC 19.14 and upward. Demo: https://gcc.godbolt.org/z/635Mxdazd

So it is reasonable to assume that it was just a compiler bug.

Related