On 1/8/21 8:31 PM, Joe Nelson wrote:
Hi, my project uses lib/_Noreturn.h, but gets a warning when compiled
with "-std=c99 -pedantic":
warning: _Noreturn functions are a C11-specific feature
-pedantic can be such a pain sometimes, as can Clang. Thanks for
reporting the problem, I guess. I installed the attached patch; please
give it a try.
>From 077ffc1e416a6be980dd45979547201e572962f6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 9 Jan 2021 14:17:32 -0800
Subject: [PATCH] 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:13zbr...@clisp.org patch to m4/gnulib-common.m4.
---
ChangeLog | 14 ++++++++++++++
doc/noreturn.texi | 20 ++++++++++++--------
lib/_Noreturn.h | 16 +++++++++-------
m4/gnulib-common.m4 | 11 ++++++-----
4 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b713bedb4..4329b81d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-01-09 Paul Eggert <egg...@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:13zbr...@clisp.org patch to m4/gnulib-common.m4.
+
2021-01-09 Darshit Shah <dar...@gnu.org>
Allow setting CVS username for gnu-web-doc-update.
diff --git a/doc/noreturn.texi b/doc/noreturn.texi
index e119ff88a..86bcc351e 100644
--- a/doc/noreturn.texi
+++ b/doc/noreturn.texi
@@ -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
diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h
index f5003b9be..cb72f2620 100644
--- a/lib/_Noreturn.h
+++ b/lib/_Noreturn.h
@@ -26,14 +26,16 @@
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)
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 535359b2c..3d87fd840 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -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__))
--
2.27.0