]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use C23 attributes if available, add ISC_ATTR_UNUSED
authorOndřej Surý <ondrej@isc.org>
Mon, 27 Feb 2023 13:09:26 +0000 (14:09 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 30 Mar 2023 20:43:39 +0000 (22:43 +0200)
Use C23 attribute styles if available:

  * Add new ISC_ATTR_UNUSED attribute macro that either expands to C23's
    [[maybe_unused]] or __attribute__((__unused__));

  * Add default expansion of the `noreturn` to [[noreturn]] if available;

  * Move the FALLTHROUGH from <isc/util.h> to <isc/attributes.h>

lib/isc/include/isc/attributes.h
lib/isc/include/isc/util.h

index abe615223e9f8de7c285d31430ead1f8f49fc556..812f136c8ba839a054e9721b7ec5c3811a1e36bd 100644 (file)
 
 #pragma once
 
-#ifdef HAVE_STDNORETURN_H
+/***
+ *** Clang Compatibility Macros
+ ***/
+
+#if !defined(__has_c_attribute)
+#define __has_c_attribute(x) 0
+#endif /* if !defined(__has_c_attribute) */
+
+#if __has_c_attribute(noreturn)
+#define noreturn [[noreturn]]
+#elif defined(HAVE_STDNORETURN_H)
 #include <stdnoreturn.h>
 #elif HAVE_FUNC_ATTRIBUTE_NORETURN
 #define noreturn __attribute__((noreturn))
 #define ISC_ATTR_MALLOC_DEALLOCATOR(deallocator)
 #define ISC_ATTR_MALLOC_DEALLOCATOR_IDX(deallocator, idx)
 #endif /* HAVE_FUNC_ATTRIBUTE_MALLOC */
+
+#if __has_c_attribute(fallthrough)
+#define FALLTHROUGH [[fallthrough]]
+#elif __GNUC__ >= 7 && !defined(__clang__)
+#define FALLTHROUGH __attribute__((fallthrough))
+#else
+/* clang-format off */
+#define FALLTHROUGH do {} while (0) /* FALLTHROUGH */
+/* clang-format on */
+#endif
+
+#if __has_c_attribute(maybe_unused)
+#define ISC_ATTR_UNUSED [[maybe_unused]]
+#else
+#define ISC_ATTR_UNUSED __attribute__((__unused__))
+#endif
index 65835920b66edec10a58de7b19ff05dbc06cc531..9c5c5c50245908859606afa927680f5bc2f40f56 100644 (file)
  * ISC_ or isc_ to the name.
  */
 
+#include <isc/attributes.h>
+
 /***
  *** Clang Compatibility Macros
  ***/
 
-#if !defined(__has_attribute)
-#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) */