From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 21 Jan 2021 21:40:16 +0000 (-0800)
Subject: Port FALLTHROUGH to clang 3.4 and earlier
X-Git-Tag: v1.0~3131
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=605e20a698d3f7296cda18ac7dd84b1a8f388b50;p=gnulib.git

Port FALLTHROUGH to clang 3.4 and earlier

Problem reported by Akim Demaille in:
https://lists.gnu.org/r/bug-gnulib/2021-01/msg00241.html
* lib/cdefs.h (__glibc_has_attribute):
* m4/gnulib-common.m4 (gl_COMMON_BODY):
Do not trust __has_attribute in clang 3.4 and earlier, as
<https://releases.llvm.org/3.5.0/tools/clang/docs/ReleaseNotes.html>
says that __has_attribute is unreliable in these old versions.
---

diff --git a/ChangeLog b/ChangeLog
index 8c5a0a7579..8fa2e1535f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2021-01-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Port FALLTHROUGH to clang 3.4 and earlier
+	Problem reported by Akim Demaille in:
+	https://lists.gnu.org/r/bug-gnulib/2021-01/msg00241.html
+	* lib/cdefs.h (__glibc_has_attribute):
+	* m4/gnulib-common.m4 (gl_COMMON_BODY):
+	Do not trust __has_attribute in clang 3.4 and earlier, as
+	<https://releases.llvm.org/3.5.0/tools/clang/docs/ReleaseNotes.html>
+	says that __has_attribute is unreliable in these old versions.
+
 2021-01-20  Bruno Haible  <bruno@clisp.org>
 
 	gc-random: Fix link error in tests.
diff --git a/lib/cdefs.h b/lib/cdefs.h
index a22ae6db26..060a3d0689 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -38,7 +38,9 @@
        #if defined __has_attribute && __has_attribute (...)
    even though they do not need to evaluate the right-hand side of the &&.
    Similarly for __has_builtin, etc.  */
-#ifdef __has_attribute
+#if (defined __has_attribute \
+     && (!defined __clang_minor__ \
+         || 3 < __clang_major__ + (5 <= __clang_minor__)))
 # define __glibc_has_attribute(attr) __has_attribute (attr)
 #else
 # define __glibc_has_attribute(attr) 0
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 3d87fd840a..f2eff10de6 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -67,7 +67,9 @@ AC_DEFUN([gl_COMMON_BODY], [
 #endif])
   AH_VERBATIM([attribute],
 [/* Attributes.  */
-#ifdef __has_attribute
+#if (defined __has_attribute \
+     && (!defined __clang_minor__ \
+         || 3 < __clang_major__ + (5 <= __clang_minor__)))
 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
 #else
 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr