]> Savannah Git Hosting - gnulib.git/commitdiff
snippet/_Noreturn: port to pedantic clang
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Jan 2021 22:17:32 +0000 (14:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Jan 2021 22:18:07 +0000 (14:18 -0800)
Problem reported by Joe Nelson in:
https://lists.gnu.org/r/bug-gnulib/2021-01/msg00152.html
* doc/noreturn.texi: Improve.
* lib/_Noreturn.h (_Noreturn):
* m4/gnulib-common.m4 (gl_COMMON_BODY):
Do not assume _Noreturn works as-is when __STRICT_ANSI__ is
defined, unless __STDC_VERSION__ indicates C11 or later.
* lib/_Noreturn.h (_Noreturn): Fall back on __attribute__
((__noreturn__)) if Clang; this merges the
2020-08-10T23:53:13Zbruno@clisp.org patch to m4/gnulib-common.m4.

ChangeLog
doc/noreturn.texi
lib/_Noreturn.h
m4/gnulib-common.m4

index b713bedb4fe3b32d49a91ae9e21711d278bc51a2..4329b81d9bd9e4d821f9f3d7579e728ebaadb713 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-01-09  Paul Eggert  <eggert@cs.ucla.edu>
+
+       snippet/_Noreturn: port to pedantic clang
+       Problem reported by Joe Nelson in:
+       https://lists.gnu.org/r/bug-gnulib/2021-01/msg00152.html
+       * doc/noreturn.texi: Improve.
+       * lib/_Noreturn.h (_Noreturn):
+       * m4/gnulib-common.m4 (gl_COMMON_BODY):
+       Do not assume _Noreturn works as-is when __STRICT_ANSI__ is
+       defined, unless __STDC_VERSION__ indicates C11 or later.
+       * lib/_Noreturn.h (_Noreturn): Fall back on __attribute__
+       ((__noreturn__)) if Clang; this merges the
+       2020-08-10T23:53:13Zbruno@clisp.org patch to m4/gnulib-common.m4.
+
 2021-01-09  Darshit Shah  <darnir@gnu.org>
 
        Allow setting CVS username for gnu-web-doc-update.
index e119ff88a6df8d7ce8897414ad9ad4611d462e31..86bcc351e0756d60c9f61b47c628398ffc398ef6 100644 (file)
@@ -23,17 +23,14 @@ declared with a @code{void} return type.
 It helps the compiler's ability to emit sensible warnings, following
 data-flow analysis, to declare which functions are non-returning.
 
+To decorate function declarations and function definitions, you can
+use the @code{_Noreturn} keyword.  No modules are needed, as Gnulib
+arranges for @code{<config.h>} to define @code{_Noreturn} to an
+appropriate replacement on platforms lacking it.
+
 Gnulib has two modules that support such a declaration:
 
 @itemize @bullet
-@item
-The @samp{stdnoreturn} module.  It provides a way to put this
-declaration at function declarations and function definitions, but not
-in function pointer types.  The identifier to use is @code{_Noreturn}
-or @code{noreturn}; @code{_Noreturn} is to be preferred because
-@code{noreturn} is a no-op on some platforms.  The include file is
-@code{<stdnoreturn.h>}.
-
 @item
 The @samp{noreturn} module.  It provides a way to put this declaration
 at function declarations, at function definitions, and in function
@@ -47,6 +44,13 @@ definitions.
 @end itemize
 @noindent
 The include file is @code{<noreturn.h>}.
+
+@item
+The @samp{stdnoreturn} module.  This can improve readability by
+letting you use @code{noreturn} instead of @code{_Noreturn};
+unfortunately, @code{noreturn} is a no-op on some platforms even
+though @code{_Noreturn} works on them.  The include file is
+@code{<stdnoreturn.h>}.
 @end itemize
 
 Which of the two modules to use?  If the non-returning functions you
index f5003b9befc650d93987ec9ed7ea9a739e53edc7..cb72f2620604406c9552d7bb5f8ffe578a3aadef 100644 (file)
        AIX system header files and several gnulib header files use precisely
        this syntax with 'extern'.  */
 #  define _Noreturn [[noreturn]]
-# elif ((!defined __cplusplus || defined __clang__)                     \
-        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
-            || 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
-            || (defined __apple_build_version__ \
-                ? 6000000 <= __apple_build_version__ \
-                : 3 < __clang_major__ + (5 <= __clang_minor__))))
+# elif ((!defined __cplusplus || defined __clang__) \
+        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
+            || (!defined __STRICT_ANSI__ \
+                && (__4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
+                    || (defined __apple_build_version__ \
+                        ? 6000000 <= __apple_build_version__ \
+                        : 3 < __clang_major__ + (5 <= __clang_minor__))))))
    /* _Noreturn works as-is.  */
-# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
+# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
+        || 0x5110 <= __SUNPRO_C)
 #  define _Noreturn __attribute__ ((__noreturn__))
 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
 #  define _Noreturn __declspec (noreturn)
index 535359b2cf6b202f41125cedb2420a75472308ae..3d87fd840a4c9d5c63348df0f4637e56d6fcfad0 100644 (file)
@@ -39,11 +39,12 @@ AC_DEFUN([gl_COMMON_BODY], [
        this syntax with 'extern'.  */
 #  define _Noreturn [[noreturn]]
 # elif ((!defined __cplusplus || defined __clang__) \
-        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
-            || _GL_GNUC_PREREQ (4, 7) \
-            || (defined __apple_build_version__ \
-                ? 6000000 <= __apple_build_version__ \
-                : 3 < __clang_major__ + (5 <= __clang_minor__))))
+        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
+            || (!defined __STRICT_ANSI__ \
+                && (_GL_GNUC_PREREQ (4, 7) \
+                    || (defined __apple_build_version__ \
+                        ? 6000000 <= __apple_build_version__ \
+                        : 3 < __clang_major__ + (5 <= __clang_minor__))))))
    /* _Noreturn works as-is.  */
 # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
 #  define _Noreturn __attribute__ ((__noreturn__))