stdnoreturn: port to newer GCCs
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 23 Aug 2012 23:40:05 +0000 (16:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 23 Aug 2012 23:42:35 +0000 (16:42 -0700)
* m4/stdnoreturn.m4 (gl_STDNORETURN_H): Avoid problems with
bleeding-edge GCC that complains about 'int _Noreturn foo (void);'.
Problem reported by Jim Meyering in
<http://lists.gnu.org/archive/html/bug-gnulib/2012-08/msg00121.html>.
Also, rename the 'test' function to a void a clash with the
already-supplied 'main' function; this fixes a bug that incorrectly
rejected GCC 4.7.1's <stdnoreturn.h>.
* doc/posix-headers/stdnoreturn.texi (stdnoreturn.h):
Document GCC problem.

ChangeLog
doc/posix-headers/stdnoreturn.texi
m4/stdnoreturn.m4

index 16b4540..b46a8bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-08-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stdnoreturn: port to newer GCCs
+       * m4/stdnoreturn.m4 (gl_STDNORETURN_H): Avoid problems with
+       bleeding-edge GCC that complains about 'int _Noreturn foo (void);'.
+       Problem reported by Jim Meyering in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2012-08/msg00121.html>.
+       Also, rename the 'test' function to a void a clash with the
+       already-supplied 'main' function; this fixes a bug that incorrectly
+       rejected GCC 4.7.1's <stdnoreturn.h>.
+       * doc/posix-headers/stdnoreturn.texi (stdnoreturn.h):
+       Document GCC problem.
+
 2012-08-22  Reuben Thomas  <rrt@sc3d.org>
 
        pipe-filter: fix comment typo
index a7dab0f..9b500cc 100644 (file)
@@ -28,5 +28,9 @@ directly.  Although the resulting code operates correctly, the
 compiler is not informed whether @code{noreturn} functions do not
 return, so it may generate incorrect warnings at compile-time, or code
 that is slightly less optimized.  This problem does not occur with
-@code{_Noreturn}.
+@item
+Circa 2012 bleeding-edge GCC with @code{-Werror=old-style-declaration}
+requires @code{_Noreturn} or @code{noreturn} before the returned type
+in a declaration, and therefore rejects valid but unusually-worded
+declarations such as @code{void _Noreturn foo (void);}.
 @end itemize
index 6e10b12..84027cb 100644 (file)
@@ -15,17 +15,16 @@ AC_DEFUN([gl_STDNORETURN_H],
        [AC_LANG_PROGRAM(
           [[#include <stdlib.h>
             #include <stdnoreturn.h>
-            void noreturn foo1 (void) { exit (0); }
-            void _Noreturn foo2 (void) { exit (0); }
-            noreturn void foo3 (void) { exit (0); }
-            _Noreturn void foo4 (void) { exit (0); }
-            int main (int argc, char **argv) {
+            /* Do not check for 'noreturn' after the return type.
+               C11 allows it, but it's rarely done that way
+               and circa-2012 bleeding-edge GCC rejects it when given
+               -Werror=old-style-declaration.  */
+            noreturn void foo1 (void) { exit (0); }
+            _Noreturn void foo2 (void) { exit (0); }
+            int testit (int argc, char **argv) {
               if (argc & 1)
                 return 0;
-              ((argv[0][0]
-                ? (argv[0][1] ? foo1 : foo2)
-                : (argv[0][1] ? foo3 : foo4))
-               ());
+              (argv[0][0] ? foo1 : foo2) ();
             }
           ]])],
        [gl_cv_header_working_stdnoreturn_h=yes],