The following function compiles without warning at optimization level -O2 or below. With -Wall -O3, gcc says: noreturn.c: In function `this_function_never_returns': noreturn.c:5: warning: no return statement in function returning non-void This happens with gcc 3.2.2 - 3.3.1, at least. int this_function_never_returns () { for (;;); } This is an extremely stripped down version of a problem with XEmacs and Fcommand_loop_1, which must be declared to return a Lisp_Object (since it is a Lisp-visible function), but which contains an infinite loop. The obvious solution of putting a return statement at the end causes some compilers to complain about unreachable code. Adding __attribute__ ((noreturn)) did not make the warning go away.
This should not warn at -O3, I think this is related to the control flow graph some how.
This problem does not seem to occur with gcc-3.4 20031124.
I can still reproduce it with the mainline (20031124).
The problem is that -O3, DECL_INLINE for the function decl becomes true because -O3 enables -finline-functions. So it looks like a different check is needed for the C front-end.
I am also getting this warning about no return statement for methods in C++. While a global function int noret() { for (;;); } does not fire the warning, the same in a method does (3.2.3).
*** Bug 30794 has been marked as a duplicate of this bug. ***
No warning in GCC 4.4 with any of those: -O0 -Wall -Wextra -Wreturn-type -Wunreachable-code -O1 -Wall -Wextra -Wreturn-type -Wunreachable-code -O2 -Wall -Wextra -Wreturn-type -Wunreachable-code -O3 -Wall -Wextra -Wreturn-type -Wunreachable-code -O3 -finline -Wall -Wextra -Wreturn-type -Wunreachable-code If you can reproduce the problem in a recent GCC, let us know. I will add the testcase to the testsuite before closing this.
Subject: Bug 12603 Author: manu Date: Mon Oct 20 18:26:21 2008 New Revision: 141244 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141244 Log: 2008-10-20 Manuel López-Ibáñez <manu@gcc.gnu.org> PR 12603 * gcc.dg/pr12603.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/pr12603.c Modified: trunk/gcc/testsuite/ChangeLog
This got fixed somehow. There is a testcase in the testsuite to make sure we do not regress.
(In reply to comment #9) > This got fixed somehow. There is a testcase in the testsuite to make sure we do > not regress. This was most likely fixed by: 2008-09-17 Jan Hubicka <jh@suse.cz> PR c++/18071 * tree.h (DECL_INLINE): remove. (DECL_DECLARED_INLINE_P): Update docs. (DECL_NO_INLINE_WARNING_P): new. (tree_function_decl): Replace inline_flag by no_inline_warning_flag. * tree-inline.c (inlinable_function_p): Set DECL_NO_INLINE_WARNING_P. :) Which removed DECL_INLINE. As I mentioned in comment #4 DECL_INLINE was the issue.