Skip to content

Commit

Permalink
Changes to compile with C++20 (#1505)
Browse files Browse the repository at this point in the history
* switch compilation to C++20

* fixed C++20 detection code

* fixed compile errors with C++20

* further changes to support C++20 compilation

* removed temporarily added compile-time assertion

* added comments regarding dependency library upgrades for the future

* Switched compilation to C++20 for BDB too
  • Loading branch information
gevorgvoskanyan authored Dec 23, 2024
1 parent b87d044 commit bf535ad
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 36,878 deletions.
64 changes: 64 additions & 0 deletions build-aux/m4/ax_cxx_compile_stdcxx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 2a"],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
Expand Down Expand Up @@ -154,6 +155,13 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
)

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], [[
Expand Down Expand Up @@ -949,3 +957,59 @@ namespace cxx17
#endif // __cplusplus < 201703L
]])

dnl Tests for new features in C++20

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
// If the compiler admits that it is not ready for C++20, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 202002L
#error "This is not a C++20 compiler"
#else
#include <concepts>
#include <compare>
#include <vector>
#include <algorithm>
namespace cxx20
{
namespace test_concepts {
template<typename T>
concept Integral = std::is_integral<T>::value;
static_assert(Integral<int>, "int should be integral");
}
namespace test_ranges {
void f() {
std::vector<int> v = {5, 2, 4, 3, 1};
std::ranges::sort(v);
}
}
namespace test_spaceship {
struct A {
int value;
auto operator<=>(const A&) const = default;
};
int f() {
A a{1}, b{2};
return (a <=> b) == std::strong_ordering::less ? 0 : 1;
}
}
} // namespace cxx20
#endif // __cplusplus < 202002L
]])
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ case $host in
lt_cv_deplibs_check_method="pass_all"
;;
esac
dnl Require C++17 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory], [nodefault])
dnl Require C++20 compiler (no GNU extensions)
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory], [nodefault])
dnl Check if -latomic is required for <std::atomic>
CHECK_ATOMIC

Expand Down
Loading

0 comments on commit bf535ad

Please sign in to comment.