[Bug c++/80681] New: missing -Wuninitialized for const or reference member of a private base class
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon May 8 22:35:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80681
Bug ID: 80681
Summary: missing -Wuninitialized for const or reference member
of a private base class
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
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
^
More information about the Gcc-bugs
mailing list