changeset 16508:72cfe53065d1

stdnoreturn: port to MSVC better MSVC standard headers use __declspec(noreturn), so #define noreturn to empty on that platform. Reported by Bruno Haible in <http://lists.gnu.org/archive/html/bug-gnulib/2012-02/msg00152.html>. * lib/stdnoreturn.in.h (noreturn): Define to empty on MSVC. * doc/posix-headers/stdnoreturn.texi (stdnoreturn.h): Document this.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 29 Feb 2012 01:48:18 -0800
parents a7ef52eff5fb
children d2a4b2dea076
files ChangeLog doc/posix-headers/stdnoreturn.texi lib/stdnoreturn.in.h
diffstat 3 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-02-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+	stdnoreturn: port to MSVC better
+	MSVC standard headers use __declspec(noreturn), so #define noreturn
+	to empty on that platform.  Reported by Bruno Haible in
+	<http://lists.gnu.org/archive/html/bug-gnulib/2012-02/msg00152.html>.
+	* lib/stdnoreturn.in.h (noreturn): Define to empty on MSVC.
+	* doc/posix-headers/stdnoreturn.texi (stdnoreturn.h): Document this.
+
 2012-02-28  Bruno Haible  <bruno@clisp.org>
 
 	doc: Mention new glibc headers and functions.
--- a/doc/posix-headers/stdnoreturn.texi
+++ b/doc/posix-headers/stdnoreturn.texi
@@ -21,4 +21,12 @@
 @item
 You cannot assume that @code{_Noreturn} is a reserved word;
 it might be a macro.
+@item
+On MSVC 9, @code{noreturn} expands to the empty token sequence, to avoid
+problems with standard headers that use @code{__declspec (noreturn)}
+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}.
 @end itemize
--- a/lib/stdnoreturn.in.h
+++ b/lib/stdnoreturn.in.h
@@ -28,7 +28,19 @@
 
 /* The definition of _Noreturn is copied here.  */
 
-#define noreturn _Noreturn
+#if 1200 <= _MSC_VER
+/* Standard include files on this platform contain declarations like
+   "__declspec (noreturn) void abort (void);".  "#define noreturn
+   _Noreturn" would cause this declaration to be rewritten to the
+   invalid "__declspec (__declspec (noreturn)) void abort (void);".
+   Instead, define noreturn to empty, so that such declarations are
+   rewritten to "__declspec () void abort (void);", which is
+   equivalent to "void abort (void);"; this gives up on noreturn's
+   advice to the compiler but at least it is valid code.  */
+# define noreturn /*empty*/
+#else
+# define noreturn _Noreturn
+#endif
 
 /* Did he ever return?
    No he never returned