public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
[parent not found: <bug-19808-4@http.gcc.gnu.org/bugzilla/>]
* [Bug c++/19808] New: miss a warning about uninitialized members in constructor
@ 2005-02-07 23:16 adl at gnu dot org
  2005-02-08  9:35 ` [Bug c++/19808] " bangerth at dealii dot org
  2005-02-08  9:59 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 23+ messages in thread
From: adl at gnu dot org @ 2005-02-07 23:16 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2014-09-29 14:35 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-19808-5329@http.gcc.gnu.org/bugzilla/>
2006-02-02 12:58 ` [Bug c++/19808] miss a warning about uninitialized members in constructor pinskia at gcc dot gnu dot org
2007-12-04 21:04 ` myselfhimself at free dot fr
2008-07-21 14:31 ` manu at gcc dot gnu dot org
2010-02-24 12:46 ` manu at gcc dot gnu dot org
2010-02-24 12:59 ` manu at gcc dot gnu dot org
2010-02-24 16:44 ` jason at gcc dot gnu dot org
2010-02-24 18:04 ` rguenth at gcc dot gnu dot org
2010-02-24 19:10 ` bart dot vanassche at gmail dot com
2010-02-24 19:45 ` manu at gcc dot gnu dot org
2010-02-24 20:13 ` jason at gcc dot gnu dot org
2010-02-24 20:15 ` manu at gcc dot gnu dot org
2010-02-24 20:22 ` rguenth at gcc dot gnu dot org
2010-02-24 20:30 ` manu at gcc dot gnu dot org
2010-02-24 20:44 ` jason at gcc dot gnu dot org
2010-02-24 20:45 ` jason at gcc dot gnu dot org
2010-02-25  7:01 ` bart dot vanassche at gmail dot com
2010-02-25  7:06 ` bart dot vanassche at gmail dot com
     [not found] <bug-19808-4@http.gcc.gnu.org/bugzilla/>
2013-07-17  9:26 ` redi at gcc dot gnu.org
2014-09-27 20:29 ` manu at gcc dot gnu.org
2014-09-29 13:06 ` jason at gcc dot gnu.org
2014-09-29 14:35 ` manu at gcc dot gnu.org
2005-02-07 23:16 [Bug c++/19808] New: " adl at gnu dot org
2005-02-08  9:35 ` [Bug c++/19808] " bangerth at dealii dot org
2005-02-08  9:59 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).