Consider the following code:
#include <cstddef>
class A
{
public:
struct B
{
int M;
};
static void StaticFunc();
};
void A::StaticFunc()
{
const std::size_t s0 = sizeof(::A::B::M);
const std::size_t s1 = sizeof(A::B::M);
const std::size_t s2 = sizeof(B::M);
}
int main()
{
const std::size_t s3 = sizeof(A::B::M);
return 0;
}
GCC compiles it, just warning about the unused variables.
Visual C++ 2015 however fails to compile it with:
error C2326: 'void A::StaticFunc(void)': function cannot access 'A::B::M'
on the lines
const std::size_t s0 = sizeof(::A::B::M);
const std::size_t s1 = sizeof(A::B::M);
in StaticFunc()
.
The other line s2 = ...
, and s3 = ...
in main()
compile fine.
Is this a bug in MSVC, or do I miss something basic here?