vendredi 29 mars 2019

C++: sizeof(member) in the definition of the class

Is the following code well-formed?

#include <cstddef>

struct Test
{
    int      member;
    static constexpr const size_t   Size1 = sizeof(member);
    static constexpr const size_t   Size2 = sizeof(decltype(member));
    static constexpr const size_t   Size3 = sizeof(Test::member);
};

The problem is sizeof(member) used in the definition of the class itself. All Size1, Size2 and Size3 initializers went fine with gcc, clang and newer MSVC. But MSVC 14 isn't happy with Size1 (the other two are ok). It says:

error C2327: 'Test::member': is not a type name, static, or enumerator

which baffles me, because member (whether qualified or not) seems a valid expression in the context of that class.

So, should I take this as a bug in older MSVC, or is such error message justified?

Aucun commentaire:

Enregistrer un commentaire