When compiling the following code with gcc-2.96-70 no warning will be generated although it should be (older g++ do it): ----- warn.cc ------- struct foo { int bar() { } }; int main() { } ------------------- $ g++ warn.cc -Wall $ egcs++ warn.cc -Wall warn.cc: In method `int foo::bar()': warn.cc:5: warning: control reaches end of non-void function `foo::bar()' $
AFAIK neither ISO C++ nor ISO C99 mandate a warning in this case, and as the warning is output when working with function in RTL representation and g++ 2.96 (and in 2.97 now both C and C++) only issue functions as RTL when actually they will be output (inlining is done on TREE representation), there is not much which can be done about this, unless this case detection would be done on TREE representation.
Well, although C++ standard C.1.4 [diff.stat] 2 Change: It is now invalid to return (explicitly or implicitly) from a function which is declared to return a value without actually return- ing a value and 6.6.3 [stmt.return] 2 Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function. labels such a program as invalid and having an undefined behavior, you are right that there is not required a diagnostic. But let me reopen it as a documentation bug ;) : gcc.info, Options to Request or Suppress Warnings says: ------------------- `-W' Print extra warning messages for these events: * A function can return either with or without a value. (Falling off the end of the function body is considered returning without a value.) For example, this function would evoke such a warning: foo (a) { if (a > 0) return a; } ------------- Modifying foo::bar() that it has the body above won't produce a warning as said by the documentation. That why the doc or the compiler is erroneous.
This works fine with gcc-c++-3.3.2-1.