]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Bump minimal c++ version to c++20
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 4 Sep 2025 07:33:11 +0000 (09:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 12 Nov 2025 08:09:27 +0000 (09:09 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
configure.ac
m4/ax_cxx_compile_stdcxx.m4
m4/ax_cxx_compile_stdcxx_20.m4 [new file with mode: 0644]
meson.build
pdns/dnsdistdist/configure.ac
pdns/dnsdistdist/m4/ax_cxx_compile_stdcxx_20.m4 [new symlink]
pdns/dnsdistdist/meson.build
pdns/recursordist/configure.ac
pdns/recursordist/m4/ax_cxx_compile_stdcxx_20.m4 [new symlink]
pdns/recursordist/meson.build

index c2f969a7950f9f665a7e0c99baa02f5328d2d757..07bc4d78d50af58fec8c9cf8ecf1f4d94b154c20 100644 (file)
@@ -35,7 +35,7 @@ PDNS_CHECK_FLEX
 # Warn when pkg.m4 is missing
 m4_pattern_forbid([^_?PKG_[A-Z_]+$], [*** pkg.m4 missing, please install pkg-config])
 
-AX_CXX_COMPILE_STDCXX_17([noext], [mandatory])
+AX_CXX_COMPILE_STDCXX_20([noext], [mandatory])
 LT_PREREQ([2.2.2])
 LT_INIT([disable-static dlopen])
 
index 2aef96dd5b02486763199f44323eb001fd0f930e..8edf5152ec7a91bea5858436ae70bb6e877689a4 100644 (file)
 #
 #   Check for baseline language coverage in the compiler for the specified
 #   version of the C++ standard.  If necessary, add switches to CXX and
-#   CXXCPP to enable support.  VERSION may be '11' (for the C++11 standard)
-#   or '14' (for the C++14 standard).
+#   CXXCPP to enable support.  VERSION may be '11', '14', '17', or '20' for
+#   the respective C++ standard version.
 #
 #   The second argument, if specified, indicates whether you insist on an
 #   extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
 #   -std=c++11).  If neither is specified, you get whatever works, with
-#   preference for an extended mode.
+#   preference for no added switch, and then for an extended mode.
 #
 #   The third argument, if specified 'mandatory' or if left unspecified,
 #   indicates that baseline support for the specified C++ standard is
 #   Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
 #   Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
 #   Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
+#   Copyright (c) 2020 Jason Merrill <jason@redhat.com>
+#   Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
 #
 #   Copying and distribution of this file, with or without modification, are
 #   permitted in any medium without royalty provided the copyright notice
 #   and this notice are preserved.  This file is offered as-is, without any
 #   warranty.
 
-#serial 11
+#serial 18
 
 dnl  This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
 dnl  (serial version number 13).
@@ -50,6 +52,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
   m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
         [$1], [14], [ax_cxx_compile_alternatives="14 1y"],
         [$1], [17], [ax_cxx_compile_alternatives="17 1z"],
+        [$1], [20], [ax_cxx_compile_alternatives="20"],
         [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
   m4_if([$2], [], [],
         [$2], [ext], [],
@@ -62,6 +65,16 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
   AC_LANG_PUSH([C++])dnl
   ac_success=no
 
+  m4_if([$2], [], [dnl
+    AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
+                  ax_cv_cxx_compile_cxx$1,
+      [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+        [ax_cv_cxx_compile_cxx$1=yes],
+        [ax_cv_cxx_compile_cxx$1=no])])
+    if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
+      ac_success=yes
+    fi])
+
   m4_if([$2], [noext], [], [dnl
   if test x$ac_success = xno; then
     for alternative in ${ax_cxx_compile_alternatives}; do
@@ -91,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
     dnl HP's aCC needs +std=c++11 according to:
     dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
     dnl Cray's crayCC needs "-h std=c++11"
+    dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
     for alternative in ${ax_cxx_compile_alternatives}; do
-      for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
-        cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+      for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
+        if test x"$switch" = xMSVC; then
+          dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
+          dnl with -std=c++17.  We suffix the cache variable name with _MSVC to
+          dnl avoid this.
+          switch=-std:c++${alternative}
+          cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
+        else
+          cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+        fi
         AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
                        $cachevar,
           [ac_save_CXX="$CXX"
@@ -140,7 +162,6 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
   _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
 )
 
-
 dnl  Test body for checking C++14 support
 
 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
@@ -148,12 +169,24 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
   _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
 )
 
+dnl  Test body for checking C++17 support
+
 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
   _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
   _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
   _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
 )
 
+dnl  Test body for checking C++20 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
+  _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+  _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+  _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
+  _AX_CXX_COMPILE_STDCXX_testbody_new_in_20
+)
+
+
 dnl  Tests for new features in C++11
 
 m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
@@ -165,7 +198,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
 
 #error "This is not a C++ compiler"
 
-#elif __cplusplus < 201103L
+// MSVC always sets __cplusplus to 199711L in older versions; newer versions
+// only set it correctly if /Zc:__cplusplus is specified as well as a
+// /std:c++NN switch:
+// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
+#elif __cplusplus < 201103L && !defined _MSC_VER
 
 #error "This is not a C++11 compiler"
 
@@ -456,7 +493,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
 
 #error "This is not a C++ compiler"
 
-#elif __cplusplus < 201402L
+#elif __cplusplus < 201402L && !defined _MSC_VER
 
 #error "This is not a C++14 compiler"
 
@@ -580,7 +617,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
 
 #error "This is not a C++ compiler"
 
-#elif __cplusplus < 201703L
+#elif __cplusplus < 201703L && !defined _MSC_VER
 
 #error "This is not a C++17 compiler"
 
@@ -595,7 +632,8 @@ namespace cxx17
 
   namespace test_constexpr_lambdas
   {
-    [[maybe_unused]] constexpr int foo = [](){return 42;}();
+
+    constexpr int foo = [](){return 42;}();
 
   }
 
@@ -945,6 +983,36 @@ namespace cxx17
 
 }  // namespace cxx17
 
-#endif  // __cplusplus < 201703L
+#endif  // __cplusplus < 201703L && !defined _MSC_VER
+
+]])
+
+
+dnl  Tests for new features in C++20
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 202002L && !defined _MSC_VER
+
+#error "This is not a C++20 compiler"
+
+#else
+
+#include <version>
+
+namespace cxx20
+{
+
+// As C++20 supports feature test macros in the standard, there is no
+// immediate need to actually test for feature availability on the
+// Autoconf side.
+
+}  // namespace cxx20
+
+#endif  // __cplusplus < 202002L && !defined _MSC_VER
 
 ]])
diff --git a/m4/ax_cxx_compile_stdcxx_20.m4 b/m4/ax_cxx_compile_stdcxx_20.m4
new file mode 100644 (file)
index 0000000..a12dbd2
--- /dev/null
@@ -0,0 +1,4 @@
+#serial 2
+
+AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
+AC_DEFUN([AX_CXX_COMPILE_STDCXX_20], [AX_CXX_COMPILE_STDCXX([20], [$1], [$2])])
index 695e50eb731eca02fbc0f71ba210f2f64a51892d..253ddfa284bdd74592ad7b826b8f032752e5ede7 100644 (file)
@@ -8,7 +8,7 @@ project(
   default_options: [
     'buildtype=debugoptimized',
     'warning_level=2',          # TODO Move this to 3 to enable -Wpedantic
-    'cpp_std=c++17',
+    'cpp_std=c++20',
   ],
 )
 
index 2297d1a78b27186ca5680083dd62d1ff80adbf67..2e507266f10d14424f9916fc67c902ab3ba05840 100644 (file)
@@ -148,7 +148,7 @@ PDNS_CHECK_LMDB
 PDNS_ENABLE_IPCIPHER
 PDNS_CHECK_AARCH64_UINT64X2_T
 
-AX_CXX_COMPILE_STDCXX_17([noext], [mandatory])
+AX_CXX_COMPILE_STDCXX_20([noext], [mandatory])
 
 AC_MSG_CHECKING([whether we will enable compiler security checks])
 AC_ARG_ENABLE([hardening],
diff --git a/pdns/dnsdistdist/m4/ax_cxx_compile_stdcxx_20.m4 b/pdns/dnsdistdist/m4/ax_cxx_compile_stdcxx_20.m4
new file mode 120000 (symlink)
index 0000000..434d925
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/ax_cxx_compile_stdcxx_20.m4
\ No newline at end of file
index 69e42d5b3bf8d3c706b5af98b2bcc2d1087064e7..8c248f70b4b1aa64b9d32aad80782df87d6d4798 100644 (file)
@@ -8,7 +8,7 @@ project(
   default_options: [
     'buildtype=debugoptimized',
     'warning_level=2',          # TODO Move this to 3 to enable -Wpedantic
-    'cpp_std=c++17',
+    'cpp_std=c++20',
     'b_pie=true',
   ],
 )
index 4e79b216461ba8b572ef63d37dafa750e924dacc..33779db9d117d811e646a1ce71a31bd9793915ba 100644 (file)
@@ -32,7 +32,7 @@ CPPFLAGS="-DRECURSOR $CPPFLAGS"
 # Warn when pkg.m4 is missing
 m4_pattern_forbid([^_?PKG_[A-Z_]+$], [*** pkg.m4 missing, please install pkg-config])
 
-AX_CXX_COMPILE_STDCXX_17([noext], [mandatory])
+AX_CXX_COMPILE_STDCXX_20([noext], [mandatory])
 PDNS_CHECK_CARGO([1.64])
 
 # Rust runtime used dlopen from its static lib
diff --git a/pdns/recursordist/m4/ax_cxx_compile_stdcxx_20.m4 b/pdns/recursordist/m4/ax_cxx_compile_stdcxx_20.m4
new file mode 120000 (symlink)
index 0000000..434d925
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/ax_cxx_compile_stdcxx_20.m4
\ No newline at end of file
index 84d75a38c8e770dc6cd2d7c9d9bb901bfc6b5285..0a81a05c1224a6687578e917b80f8d1c3fd1fc29 100644 (file)
@@ -8,7 +8,7 @@ project(
   default_options: [
     'buildtype=debugoptimized',
     'warning_level=2',          # TODO Move this to 3 to enable -Wpedantic
-    'cpp_std=c++17',
+    'cpp_std=c++20',
   ],
 )