This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/19808] New: miss a warning about uninitialized members in constructor
- From: "adl at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Feb 2005 17:40:56 -0000
- Subject: [Bug c++/19808] New: miss a warning about uninitialized members in constructor
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I just ran into bogus code similar to the following.
(The code is bogus, not GCC, but I believe GCC could have helped.)
// main.cc
#include <iostream>
struct A
{
A(int x) : x(x) {};
int call_me() { return x; }
int x;
};
struct B
{
B(A* a) : i(the_a->call_me()), the_a(a) {}
int i;
A* the_a;
};
int
main()
{
A a(20);
B b(&a);
std::cout << b.i << std::endl;
}
% g++ -O2 -Wall main.cc
% ./a.out
1328900
This displays 1328900 (or any other value) instead of 20 because
the_a->call_me() is invoked before the_a is initialized in
B's constructor.
It would be useful if g++ could diagnose such use of uninitialized
members in constructors, just like it does for local variables.
--
Summary: miss a warning about uninitialized members in
constructor
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: adl at gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19808