Similar bug is also reported in 20624 and 20681. But here I give a much simpler test case. Compile with -Wall. Problem exists in 4.1 from CVS too (detailed below).
---- test case begin ---- struct A { A(); ~A(); }; int *f(char const *p) { A a; if (p[0]=='_' && p[1]=='_') return new int; else return 0; } ---- test case end ---- # error message: $ g++ -c -Wall w.cxx w.cxx: In function ‘B* f(const char*)’: w.cxx:10: warning: control reaches end of non-void function # 4.0 version: $ g++ -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc/configure --prefix=/lvm/fred/gcc/4.0/install-20050409 --enable-static --enable-shared --enable-languages=c,c++,f95 --with-mpfr=/lvm/fred/pkg/gmp/install Thread model: posix gcc version 4.0.0 20050409 (prerelease) # 4.1 version: $ g++ -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc/configure --prefix=/lvm/fred/gcc/cvs/install-20050305 --enable-static --enable-shared --enable-languages=c,c++,f95 --with-mpfr=/lvm/fred/pkg/gmp/install Thread model: posix gcc version 4.1.0 20050305 (experimental) -- Summary: unwarranted warning "control reaches end of non-void- function" Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fsm at robots dot ox dot ac dot uk CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20918