public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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; 3+ 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] 3+ messages in thread

* [Bug c++/19808] miss a warning about uninitialized members in constructor
  2005-02-07 23:16 [Bug c++/19808] New: miss a warning about uninitialized members in constructor adl at gnu dot org
@ 2005-02-08  9:35 ` bangerth at dealii dot org
  2005-02-08  9:59 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2005-02-08  9:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-02-07 21:53 -------
Confirmed. We should get a warning for this code, but don't: 
---------------------- 
struct S 
{ 
    int i, j; 
    S() : i(j), j(1) {} 
}; 
 
S s; 
----------------------- 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-07 21:53:37
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19808


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

* [Bug c++/19808] miss a warning about uninitialized members in constructor
  2005-02-07 23:16 [Bug c++/19808] New: miss a warning about uninitialized members in constructor 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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-08  9:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-07 21:56 -------
This is related to PR 2972 and PR 18016.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19808


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

end of thread, other threads:[~2005-02-07 21:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07 23:16 [Bug c++/19808] New: miss a warning about uninitialized members in constructor 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).