From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24837 invoked by alias); 14 Jan 2009 21:04:58 -0000 Received: (qmail 24210 invoked by uid 48); 14 Jan 2009 21:04:47 -0000 Date: Wed, 14 Jan 2009 21:04:00 -0000 Subject: [Bug c++/38851] New: Compiler warns about uninitialized variable that is an object with a constructor X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "nvachhar at google dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-01/txt/msg01534.txt.bz2 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 Other { public: Other (const Comp &c) : c_(c) { } void* doSomething(); private: Comp c_; }; template void* Other::doSomething() { return &c_; } int main(int argc, char **argv) { MyCompare c; Other 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