I have the following code:
#include <iostream>
template<int I>
class A
{
public:
inline constexpr static int size() { return I; }
};
template<typename T>
inline constexpr auto size(const T& arg) noexcept -> decltype(arg.size())
{
return arg.size();
}
template<typename T>
inline constexpr void twoLevel(const T& arg) noexcept
{
static_assert(size(arg) > 0);
}
int main()
{
A<5> a;
static_assert(size(a)>0); //this works
twoLevel(a); // this does not
return 0;
}
Which fails to compile on msvc with the error expression did not evaluate to a constant
, but works with gcc. Is it gcc accepting something that's undefined behaviour? Or is it a compiler bug on msvc's part?
Here's a demo: godbolt code