Apologies if this is a duplicate, but I can't find another quite like this...
<blockquote> struct Class { // undefined void Method(); }; template < typename w_type > struct NoPtr { // inline NoPtr( bool = false ) : m_ptr( 0 ) { } // inline; calls a method ~NoPtr() { if ( m_ptr ) m_ptr->Method(); } // undefined w_type *Get(); w_type *m_ptr; }; void f() { bool cond = true; // a named NoPtr< Class > initialized from a ternary expression // with an if-expr that refers to any named object, // plus a then-expr that contains an rvalue of type NoPtr< Class > NoPtr< Class > named( cond ? NoPtr< Class >().Get() : 0 ); } </blockquote> $ /usr/bin/g++-4.2 -c -o/dev/null -xc++ -Wuninitialized -O file.cpp $ /usr/bin/g++-4.2 -dumpversion 4.2.4 $ g++-4 -c -o/dev/null -xc++ -Wuninitialized -O file.cpp file.cpp: In function 'void f()': file.cpp:14: warning: 'named.NoPtr<Class>::m_ptr' may be used uninitialized in this function file.cpp:30: note: 'named.NoPtr<Class>::m_ptr' was declared here $ g++-4 -dumpversion 4.3.2 $ /usr/bin/g++-4.3 -c -o/dev/null -xc++ -Wuninitialized -O file.cpp file.cpp: In function 'void f()': file.cpp:14: warning: 'named.NoPtr<Class>::m_ptr' may be used uninitialized in this function file.cpp:30: note: 'named.NoPtr<Class>::m_ptr' was declared here $ /usr/bin/g++-4.3 -dumpversion 4.3.3 $ /usr/bin/g++-4.4 -c -o/dev/null -xc++ -Wuninitialized -O file.cpp file.cpp: In function 'void f()': file.cpp:14: warning: 'named.NoPtr<Class>::m_ptr' may be used uninitialized in this function file.cpp:30: note: 'named.NoPtr<Class>::m_ptr' was declared here $ /usr/bin/g++-4.4 -dumpversion 4.4.0 If it helps, that's 4.2.4 on Debian; 4.3.2 on Cygwin; 4.3.3 and 4.4.0 on both Solaris and Debian. -- Summary: bogus "may be used uninitialized in this function" warning Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: shane dot beasley at aleri dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40695