On 2/3/20 3:00 PM, Jeffrey Walton wrote:
Or, you can use __has_attribute(_Noreturn). __has_attribute(_Noreturn) behaves as expected.
It isn't documented to work, and it doesn't work for me with clang version 9.0.0 (Fedora 9.0.0-1.fc31).
I would not worry about other software using __has_attribute. It is a reserved symbol due to the leading undersocres. Userland software should not have been using it in the first place.
Gnulib is userland software, so we cannot use your argument to justify putting "#define __has_attribute(x) 0" into Gnulib.
How about the attached (untested) patch instead? It looks at __apple_build_version__.
PS. I must say that Apple's hijacking and renumbering of __clang_major__ seems pretty antisocial, and breaks some already-existing code in Gnulib - what caused Apple to do that?
>From b5a5d22145cb3fa8c92e7b460710cb63e7bafb44 Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Mon, 3 Feb 2020 13:20:09 -0800 Subject: [PATCH] Port _Noreturn to older Clang Problem reported by Jeffery Walton in: https://lists.gnu.org/r/bug-gnulib/2020-02/msg00013.html * lib/_Noreturn.h (_Noreturn): * m4/gnulib-common.m4 (gl_COMMON_BODY): Assume _Noreturn works in Clang 3.5 and later. It is documented to work in Clang 3.5: http://releases.llvm.org/3.5.0/tools/clang/docs/AttributeReference.html and is not documented in Clang 3.4: https://releases.llvm.org/3.4/tools/clang/docs/LanguageExtensions.html Apple sets __clang_version__ to a different value, so use __apple_build_version__ there. See: https://lists.gnu.org/r/bug-gnulib/2020-02/msg00017.html --- ChangeLog | 16 ++++++++++++++++ lib/_Noreturn.h | 5 ++++- m4/gnulib-common.m4 | 7 +++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a86791a8..a753da8ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2020-02-03 Paul Eggert <egg...@cs.ucla.edu> + + Port _Noreturn to older Clang + Problem reported by Jeffery Walton in: + https://lists.gnu.org/r/bug-gnulib/2020-02/msg00013.html + * lib/_Noreturn.h (_Noreturn): + * m4/gnulib-common.m4 (gl_COMMON_BODY): + Assume _Noreturn works in Clang 3.5 and later. + It is documented to work in Clang 3.5: + http://releases.llvm.org/3.5.0/tools/clang/docs/AttributeReference.html + and is not documented in Clang 3.4: + https://releases.llvm.org/3.4/tools/clang/docs/LanguageExtensions.html + Apple sets __clang_version__ to a different value, so use + __apple_build_version__ there. See: + https://lists.gnu.org/r/bug-gnulib/2020-02/msg00017.html + 2020-02-02 Bruno Haible <br...@clisp.org> Document the new modules list-c++, set-c++, oset-c++, map-c++, omap-c++. diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h index 74ee9ad41..606e92f52 100644 --- a/lib/_Noreturn.h +++ b/lib/_Noreturn.h @@ -28,7 +28,10 @@ # define _Noreturn [[noreturn]] # elif ((!defined __cplusplus || defined __clang__) \ && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ - || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))) + || 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 # define _Noreturn __attribute__ ((__noreturn__)) diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 276ed1aff..b4795c18a 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 47 +# gnulib-common.m4 serial 48 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -31,7 +31,10 @@ AC_DEFUN([gl_COMMON_BODY], [ # define _Noreturn [[noreturn]] # elif ((!defined __cplusplus || defined __clang__) \ && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ - || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))) + || 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 # define _Noreturn __attribute__ ((__noreturn__)) -- 2.24.1