A follow-up question to this one
We have the following code:
#include <iostream>
struct A
{
static int n;
};
int A::n = 5;
int main()
{
A* a; //uninitialized on purpose
std::cout << a->n; //UB?
}
Is such access an Undefined Behaviour? On one side, no object is needed to access static class members, on the other, operator->
on uninitialized pointer is asking for trouble.
Note: GCC and MSVC compiles this code without any warnings, Clang complains about uninitialized usage. https://godbolt.org/z/Gy5fR2