]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Detect and possibly define constexpr using Autoconf
authorOndřej Surý <ondrej@isc.org>
Wed, 18 Dec 2024 10:53:48 +0000 (11:53 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 25 Dec 2024 14:21:26 +0000 (15:21 +0100)
Previously, we had an ISC_CONSTEXPR macro that was expanded to either
`constexpr` or `static const`, depending on compiler support.  To make
the code cleaner, move `constexpr` support detection to Autoconf; if
`constexpr` support is missing from the compiler, define `constexpr` as
`static const` in config.h.

configure.ac
lib/isc/include/isc/attributes.h
lib/isc/include/isc/time.h

index 4ac7264ab41d2cc322d6bbb4903a8c4bbac51c4b..53f67d50f8733b83d2091307a036ec8c35ebf82d 100644 (file)
@@ -142,6 +142,13 @@ TEST_CFLAGS="-Wno-vla"
 # the compiler has a different built-in setting)
 STD_CPPFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
 
+#
+# Define constexpr if it is missing from the compiler
+#
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[constexpr int foo = 0;]])],
+                 [],
+                 [AC_DEFINE([constexpr],[static const],[Define compatibility shim for non-C23 compilers.])])
+
 #
 # Additional compiler settings.
 #
index 4ed540f5a8c262640899023580fdaa48a9b032b4..eb1bb53e2ede4de75e57b87e0052dc4801a65714 100644 (file)
 #else
 #define ISC_ATTR_UNUSED __attribute__((__unused__))
 #endif
-
-#if __STDC_VERSION__ >= 202311L
-#define ISC_CONSTEXPR constexpr
-#else
-#define ISC_CONSTEXPR static const
-#endif
index 0ba40129faa5be238db674d46f49a6c7e3de6ac3..9fa025c9f4a32f738316a66d8b7b01705c263368 100644 (file)
 #include <inttypes.h>
 #include <time.h>
 
-#include <isc/attributes.h>
 #include <isc/types.h>
 
 /*
  * Define various time conversion constants.
  */
-ISC_CONSTEXPR unsigned int MS_PER_SEC = 1000;
-ISC_CONSTEXPR unsigned int US_PER_MS = 1000;
-ISC_CONSTEXPR unsigned int NS_PER_US = 1000;
-ISC_CONSTEXPR unsigned int US_PER_SEC = 1000 * 1000;
-ISC_CONSTEXPR unsigned int NS_PER_MS = 1000 * 1000;
-ISC_CONSTEXPR unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
+constexpr unsigned int MS_PER_SEC = 1000;
+constexpr unsigned int US_PER_MS = 1000;
+constexpr unsigned int NS_PER_US = 1000;
+constexpr unsigned int US_PER_SEC = 1000 * 1000;
+constexpr unsigned int NS_PER_MS = 1000 * 1000;
+constexpr unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
 
 /*
  * ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially