G++ issues -Wuninitialized for uninitialized private const data or reference members of classes with no constructors because there is no other way to initialize them. However, G++ neglects to issue the same warning when an uninitialized public const data or reference member is defined in a base class that is privately derived by a class without constructors, even though such a member also cannot be initialized. In addition, the C++ warning is not entirely correctly documented. The manual states that: In C++, warn if a non-static reference or non-static const member appears in a class without constructors. However, G++ only issues the warning when the member is inaccessible (private or protected). $ cat y.C && gcc -S -Wall -Wextra y.C struct A1 { private: const int i; }; // warning, good struct B1 { const int j; }; // no warning, good struct C1: private B1 { }; // bug: missing warning struct A2 { private: const int &i; }; // warning, good struct B2 { const int &j; }; // no warning, good struct C2: private B2 { }; // bug: missing warning y.C:1:32: warning: non-static const member ‘const int A1::i’ in class without a constructor [-Wuninitialized] struct A1 { private: const int i; }; // warning, good ^ y.C:8:33: warning: non-static reference ‘const int& A2::i’ in class without a constructor [-Wuninitialized] struct A2 { private: const int &i; }; // warning, good ^
Confirmed.
cc-ing Manu since he is pretty knowledgeable about -Wuninitialized
This should be easy to do since at the point of warning (which happens in the FE), all information needed is available.
No progress in GCC 11.