Why wouldn't this be valid for a static assert?
This is a stripped down version of what I'm doing. It gives the same error as the real one.
constexpr uint32_t AFlag = 0x01;
struct AStruct
{
const uint32_t m_AMember;
};
const AStruct Xyz
{
0x03
};
static_assert((Xyz.m_AMember & AFlag) != 0);
It seems like everything in there could be evaluated at compile time, since it's all const and constexpr. But Visual C++ complains that it didn't evaluate to a constant.
It's obviously related to it being a structure member. Does static_assert just not work on structure members even in this simple type of scenario in 17?
Posted May 20, 2020, 2:54 PM UTC
13
GCC:
constexpr AStruct Xyzfixes the problem.Ahh... You learn something every day. I wasn't even aware after all this time that structs could be constexpr. Thanks.
The type can not be
constexpr, but each instance can be.