Are Clang and MSVC being overly permissive if I use int instead of std::size_t as the template parameter here? [duplicate]

2 weeks ago 12
ARTICLE AD BOX

The following compiles on MSVC and Clang but not on GCC:

#include <iostream> #include <array> template <typename T> struct IsSTDArray : std::false_type {}; template <typename T, int N> struct IsSTDArray<std::array<T, N>> : std::true_type {}; int main() { static_assert(IsSTDArray<std::array<int, 3>>::value); }

Link here

I take it GCC is "technically" correct, right?

Although in my template class:

template <uint64_t N> struct MyClass {}; MyClass<unsigned char(0)> my_class; // THIS WORKS

But not in the first example I gave, that's more strict.

Interestingly, GCC and Clang fail to compile unsigned and signed mismatches (but accept integer width differences), but MSVC even accepts signed and unsigned mismatches, so I think the rules are all over the place with respect to each compiler.

template <uint64_t N> struct MyClass {}; MyClass<signed int(0)> my_class; // THIS WORKS ON MSVC BUT NOT ON CLANG AND GCC
Read Entire Article