https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80458
Bug ID: 80458 Summary: [-Wreturn-type] false negative on missing return statement in a member function Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: skvadrik at gmail dot com Target Milestone: --- On the following example (missing return statement in a member function) GCC emits no warning: $ cat 1.cc #include <stdlib.h> // exit extern void *f(); class Bag { void *g() { void *p = f(); if (!p) exit(1); } }; $ g++ -c -Wall -Wextra -O2 1.cc $ If I comment out class definition, GCC emits warning: $ cat 1.cc #include <stdlib.h> // exit extern void *f(); //class Bag { void *g() { void *p = f(); if (!p) exit(1); } //}; $ g++ -c -Wall -Wextra -O2 1.cc 1.cc: In function ‘void* g()’: 1.cc:7:5: warning: control reaches end of non-void function [-Wreturn-type] } ^ $