Problem reported by Helmut Eller <https://bugs.gnu.org/78903>. * lib/_Noreturn.h (_Noreturn): * m4/gnulib-common.m4 (gl_COMMON_BODY): Prefer __attribute__ ((__noreturn__)) to _Noreturn if __STDC_VERSION__ < 201112, to pacify gcc -std=gnu99 -Wpedantic. Simplify. Do not bother suggesting -D_GL_WORK_AROUND_LLVM_BUG_59792; suggest the equivalent -D_Noreturn= instead, and remove the test on _GL_WORK_AROUND_LLVM_BUG_59792. --- ChangeLog | 12 ++++++++++++ lib/_Noreturn.h | 38 +++++++++++++++----------------------- m4/gnulib-common.m4 | 41 ++++++++++++++++------------------------- 3 files changed, 43 insertions(+), 48 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 3acaa92d0a..317862e1ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2025-06-27 Paul Eggert <egg...@cs.ucla.edu> + + _Noreturn: pacify gcc -std=gnu99 -Wpedantic + Problem reported by Helmut Eller <https://bugs.gnu.org/78903>. + * lib/_Noreturn.h (_Noreturn): + * m4/gnulib-common.m4 (gl_COMMON_BODY): Prefer __attribute__ + ((__noreturn__)) to _Noreturn if __STDC_VERSION__ < 201112, to + pacify gcc -std=gnu99 -Wpedantic. Simplify. Do not bother + suggesting -D_GL_WORK_AROUND_LLVM_BUG_59792; suggest the + equivalent -D_Noreturn= instead, and remove the test on + _GL_WORK_AROUND_LLVM_BUG_59792. + 2025-06-27 Bruno Haible <br...@clisp.org> options: Fix typo in comment. diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h index 0d452649fb..8e63387914 100644 --- a/lib/_Noreturn.h +++ b/lib/_Noreturn.h @@ -14,33 +14,25 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* The _Noreturn keyword of C11. + Do not use [[noreturn]], because with it the syntax + extern _Noreturn void func (...); + would not be valid; such a declaration would be valid only with 'extern' + and '_Noreturn' swapped, or without the 'extern' keyword. However, some + AIX system header files and several gnulib header files use precisely + this syntax with 'extern'. So even though C23 deprecates _Noreturn, + it is currently more portable to prefer it to [[noreturn]]. + + Also, do not try to work around LLVM bug 59792 (clang 15 or earlier). + This rare bug can be worked around by compiling with 'clang -D_Noreturn=', + though the workaround may generate many false-alarm warnings. */ #ifndef _Noreturn -# if (defined __cplusplus \ - && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ - || (defined _MSC_VER && 1900 <= _MSC_VER)) \ - && 0) - /* [[noreturn]] is not practically usable, because with it the syntax - extern _Noreturn void func (...); - would not be valid; such a declaration would only be valid with 'extern' - and '_Noreturn' swapped, or without the 'extern' keyword. However, some - AIX system header files and several gnulib header files use precisely - this syntax with 'extern'. */ -# define _Noreturn [[noreturn]] -# elif (defined __clang__ && __clang_major__ < 16 \ - && defined _GL_WORK_AROUND_LLVM_BUG_59792) - /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around - that rare LLVM bug, though you may get many false-alarm warnings. */ -# define _Noreturn -# elif ((!defined __cplusplus || defined __clang__) \ - && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ - || (!defined __STRICT_ANSI__ \ - && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __clang__ \ - || (defined __apple_build_version__ \ - ? 6000000 <= __apple_build_version__ \ - : 3 < __clang_major__ + (5 <= __clang_minor__)))))) +# if 201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) /* _Noreturn works as-is. */ # elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \ || 0x5110 <= __SUNPRO_C) + /* Prefer __attribute__ ((__noreturn__)) to plain _Noreturn even if the + latter works, as 'gcc -std=gnu99 -Wpedantic' warns about _Noreturn. */ # 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 5d1944a4f5..d525d8b1fa 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,5 +1,5 @@ # gnulib-common.m4 -# serial 111 +# serial 112 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,33 +57,24 @@ AC_DEFUN([gl_COMMON_BODY], [ #endif ]) AH_VERBATIM([_Noreturn], -[/* The _Noreturn keyword of C11. */ +[/* The _Noreturn keyword of C11. + Do not use [[noreturn]], because with it the syntax + extern _Noreturn void func (...); + would not be valid; such a declaration would be valid only with 'extern' + and '_Noreturn' swapped, or without the 'extern' keyword. However, some + AIX system header files and several gnulib header files use precisely + this syntax with 'extern'. So even though C23 deprecates _Noreturn, + it is currently more portable to prefer it to [[noreturn]]. + + Also, do not try to work around LLVM bug 59792 (clang 15 or earlier). + This rare bug can be worked around by compiling with 'clang -D_Noreturn=', + though the workaround may generate many false-alarm warnings. */ #ifndef _Noreturn -# if (defined __cplusplus \ - && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ - || (defined _MSC_VER && 1900 <= _MSC_VER)) \ - && 0) - /* [[noreturn]] is not practically usable, because with it the syntax - extern _Noreturn void func (...); - would not be valid; such a declaration would only be valid with 'extern' - and '_Noreturn' swapped, or without the 'extern' keyword. However, some - AIX system header files and several gnulib header files use precisely - this syntax with 'extern'. */ -# define _Noreturn [[noreturn]] -# elif (defined __clang__ && __clang_major__ < 16 \ - && defined _GL_WORK_AROUND_LLVM_BUG_59792) - /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around - that rare LLVM bug, though you may get many false-alarm warnings. */ -# define _Noreturn -# elif ((!defined __cplusplus || defined __clang__) \ - && (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__)))))) +# if 201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) /* _Noreturn works as-is. */ # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C + /* Prefer __attribute__ ((__noreturn__)) to plain _Noreturn even if the + latter works, as 'gcc -std=gnu99 -Wpedantic' warns about _Noreturn. */ # define _Noreturn __attribute__ ((__noreturn__)) # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) # define _Noreturn __declspec (noreturn) -- 2.48.1