From 7b26becec02a8e18428b05de1e388af00b9aa8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 18 Dec 2024 11:53:48 +0100 Subject: [PATCH] Detect and possibly define constexpr using Autoconf 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 | 7 +++++++ lib/isc/include/isc/attributes.h | 6 ------ lib/isc/include/isc/time.h | 13 ++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 4ac7264ab4..53f67d50f8 100644 --- a/configure.ac +++ b/configure.ac @@ -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. # diff --git a/lib/isc/include/isc/attributes.h b/lib/isc/include/isc/attributes.h index 4ed540f5a8..eb1bb53e2e 100644 --- a/lib/isc/include/isc/attributes.h +++ b/lib/isc/include/isc/attributes.h @@ -102,9 +102,3 @@ #else #define ISC_ATTR_UNUSED __attribute__((__unused__)) #endif - -#if __STDC_VERSION__ >= 202311L -#define ISC_CONSTEXPR constexpr -#else -#define ISC_CONSTEXPR static const -#endif diff --git a/lib/isc/include/isc/time.h b/lib/isc/include/isc/time.h index 0ba40129fa..9fa025c9f4 100644 --- a/lib/isc/include/isc/time.h +++ b/lib/isc/include/isc/time.h @@ -18,18 +18,17 @@ #include #include -#include #include /* * 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