From: Ondřej Surý Date: Thu, 19 May 2022 19:40:24 +0000 (+0200) Subject: Use C2x [[fallthrough]] when supported by LLVM/clang X-Git-Tag: v9.19.2~24^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=14c8d4386397adbb826e94c4dfe9b7364dab8c75;p=thirdparty%2Fbind9.git Use C2x [[fallthrough]] when supported by LLVM/clang Clang added support for the gcc-style fallthrough attribute (i.e. __attribute__((fallthrough))) in version 10. However, __has_attribute(fallthrough) will return 1 in C mode in older versions, even though they only support the C++11 fallthrough attribute. At best, the unsupported attribute is simply ignored; at worst, it causes errors. The C2x fallthrough attribute has the advantages of being supported in the broadest range of clang versions (added in version 9) and being easy to check for support. Use C2x [[fallthrough]] attribute if possible, and fall back to not using an attribute for clang versions that don't have it. Courtesy of Joshua Root --- diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 4494bbbdeb0..32086b2b763 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -35,6 +35,10 @@ #define __has_attribute(x) 0 #endif /* if !defined(__has_attribute) */ +#if !defined(__has_c_attribute) +#define __has_c_attribute(x) 0 +#endif /* if !defined(__has_c_attribute) */ + #if !defined(__has_feature) #define __has_feature(x) 0 #endif /* if !defined(__has_feature) */ @@ -61,7 +65,9 @@ #define ISC_NONSTRING #endif /* __GNUC__ */ -#if __GNUC__ >= 7 || __has_attribute(fallthrough) +#if __has_c_attribute(fallthrough) +#define FALLTHROUGH [[fallthrough]] +#elif __GNUC__ >= 7 && !defined(__clang__) #define FALLTHROUGH __attribute__((fallthrough)) #else /* clang-format off */