public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38851]  New: Compiler warns about uninitialized variable that is an object with a constructor
@ 2009-01-14 21:04 nvachhar at google dot com
  2009-01-14 21:05 ` [Bug c++/38851] " nvachhar at google dot com
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: nvachhar at google dot com @ 2009-01-14 21:04 UTC (permalink / raw)
  To: gcc-bugs

Compiling the following program:

int printf(const char *fmt, ...);

class MyCompare {
 public:
  MyCompare() { }
  bool operator() (const int a, const int b) const {
    return a > b;
  }
};

template<class Comp>
class Other {
 public:
  Other (const Comp &c) : c_(c) { }
  void* doSomething();

 private:
  Comp c_;
};

template<class Comp>
void* Other<Comp>::doSomething() {
  return &c_;
}

int main(int argc, char **argv) {
  MyCompare c;
  Other<MyCompare> other(c);
  printf("%p\n", other.doSomething());
  return 0;
}

yields the following warning:

test.cc: In function 'int main(int, char**)':
test.cc:14: warning: 'c' is used uninitialized in this function
test.cc:27: note: 'c' was declared here

when compiled with the following command line:

g++ -Wall -c -O2 test.cc

However, c is initialized by the no argument constructor (further class
MyCompare does not actually have any member variables to initialize).


-- 
           Summary: Compiler warns about uninitialized variable that is an
                    object with a constructor
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nvachhar at google dot com
 GCC build triplet: i686-unknown-linux-gnu
  GCC host triplet: i686-unknown-linux-gnu
GCC target triplet: i686-unknown-linux-gnu


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


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

end of thread, other threads:[~2009-01-30 17:32 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-14 21:04 [Bug c++/38851] New: Compiler warns about uninitialized variable that is an object with a constructor nvachhar at google dot com
2009-01-14 21:05 ` [Bug c++/38851] " nvachhar at google dot com
2009-01-14 21:58 ` pinskia at gcc dot gnu dot org
2009-01-21 22:19 ` [Bug middle-end/38851] [4.3 regression] " bkoz at gcc dot gnu dot org
2009-01-21 22:41 ` [Bug middle-end/38851] [4.4 " bkoz at gcc dot gnu dot org
2009-01-21 22:49 ` [Bug c++/38851] " rguenth at gcc dot gnu dot org
2009-01-21 22:59 ` [Bug middle-end/38851] " pinskia at gcc dot gnu dot org
2009-01-23 19:32 ` bangerth at dealii dot org
2009-01-24  9:22 ` rguenth at gcc dot gnu dot org
2009-01-24  9:27 ` rguenth at gcc dot gnu dot org
2009-01-24 10:06 ` rguenth at gcc dot gnu dot org
2009-01-24 14:23 ` rguenth at gcc dot gnu dot org
2009-01-24 14:24 ` rguenth at gcc dot gnu dot org
2009-01-25 18:02 ` rguenth at gcc dot gnu dot org
2009-01-25 19:45 ` mmitchel at gcc dot gnu dot org
2009-01-25 20:00 ` rguenther at suse dot de
2009-01-25 20:04 ` mark at codesourcery dot com
2009-01-25 20:45 ` rguenther at suse dot de
2009-01-25 22:03 ` rguenth at gcc dot gnu dot org
2009-01-26  9:53 ` rguenth at gcc dot gnu dot org
2009-01-26  9:53 ` rguenth at gcc dot gnu dot org
2009-01-30 17:32 ` hjl 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).