bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] stdnoreturn: new module


From: Paul Eggert
Subject: Re: [PATCH] stdnoreturn: new module
Date: Wed, 29 Feb 2012 01:50:28 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 02/28/2012 07:46 PM, Bruno Haible wrote:
> Eric Blake wrote:
>> I'm leaning towards "#define noreturn /**/" as well.
> 
> Me too. It's the most reliable, will not give us surprises.

Thanks, I pushed this:


>From 44cc63109021dd9aa88d1736536581cf08fce29a Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Wed, 29 Feb 2012 01:48:18 -0800
Subject: [PATCH] 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.
---
 ChangeLog                          |    9 +++++++++
 doc/posix-headers/stdnoreturn.texi |    8 ++++++++
 lib/stdnoreturn.in.h               |   14 +++++++++++++-
 3 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2294d7c..37ad125 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-02-29  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        doc: Mention new glibc headers and functions.
diff --git a/doc/posix-headers/stdnoreturn.texi 
b/doc/posix-headers/stdnoreturn.texi
index f49d663..a7dab0f 100644
--- a/doc/posix-headers/stdnoreturn.texi
+++ b/doc/posix-headers/stdnoreturn.texi
@@ -21,4 +21,12 @@ Portability problems not fixed by Gnulib:
 @item
 You cannot assume that @code{_Noreturn} is a reserved word;
 it might be a macro.
address@hidden
+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
address@hidden
 @end itemize
diff --git a/lib/stdnoreturn.in.h b/lib/stdnoreturn.in.h
index 5ca3063..ab9202e 100644
--- 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
-- 
1.7.6.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]