This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Don't warn about missing noreturn for main
- To: gcc-patches at gcc dot gnu dot org
- Subject: Don't warn about missing noreturn for main
- From: Andreas Jaeger <aj at suse dot de>
- Date: 30 Dec 2000 21:30:13 +0100
It's quite common to end main with exit (0) instead of a return
value. But if you do this, and use -Wmissing-noreturn you get:
t.c: In function `main':
t.c:7: warning: function might be possible candidate for attribute `noreturn'
Here's a patch (together with a corresponding testcase and
documentation update) to suppress the warning. IMO there's no sense
to warn about this for main.
What do you think? Is it ok to install?
Bootstrapped and passed make check on i686-linux-gnu.
Andreas
2000-12-30 Andreas Jaeger <aj@suse.de>
* gcc.dg/noreturn-3.c: New test.
2000-12-30 Andreas Jaeger <aj@suse.de>
* flow.c (check_function_return_warnings): Don't warn for main.
* invoke.texi (Warning Options): Document this.
============================================================
Index: gcc/flow.c
--- gcc/flow.c 2000/12/29 17:48:08 1.363
+++ gcc/flow.c 2000/12/30 15:16:51
@@ -530,6 +530,7 @@
{
if (warn_missing_noreturn
&& !TREE_THIS_VOLATILE (cfun->decl)
+ && !MAIN_NAME_P (DECL_NAME (cfun->decl))
&& EXIT_BLOCK_PTR->pred == NULL)
warning ("function might be possible candidate for attribute `noreturn'");
============================================================
Index: gcc/testsuite/gcc.dg/noreturn-3.c
--- gcc/testsuite/gcc.dg/noreturn-3.c created
+++ gcc/testsuite/gcc.dg/noreturn-3.c Sat Dec 30 16:15:04 2000 1.1
@@ -0,0 +1,10 @@
+/* Check for no "noreturn" warning in main. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wmissing-noreturn" } */
+extern void exit (int) __attribute__ ((__noreturn__));
+
+int
+main (void)
+{
+ exit (0);
+}
============================================================
Index: gcc/invoke.texi
--- gcc/invoke.texi 2000/12/28 18:48:03 1.250
+++ gcc/invoke.texi 2000/12/30 15:21:01
@@ -2175,7 +2175,7 @@
Note these are only possible candidates, not absolute ones. Care should
be taken to manually verify functions actually do not ever return before
adding the @code{noreturn} attribute, otherwise subtle code generation
-bugs could be introduced.
+bugs could be introduced. You will not get a warning for @code{main}.
@item -Wmissing-format-attribute
If @samp{-Wformat} is enabled, also warn about functions which might be
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj