2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

chg: dev: 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.

Merge branch 'ondrej/rename-ISC_CONSTEXPR-to-constexpr-shim' into 'main'

See merge request isc-projects/bind9!9924
This commit is contained in:
Ondřej Surý 2024-12-25 14:22:27 +00:00
commit 1fea227ab8
3 changed files with 13 additions and 13 deletions

View 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.
#

View File

@ -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

View File

@ -18,18 +18,17 @@
#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