Skip to content

Commit 5288ecd

Browse files
committed
Merge TASK-001: Bump C++ standard floor to C++20
First task in the v2.0 milestone series (M1-Foundation). Raises the project's C++ standard floor from C++17 to C++20.
2 parents d8b055e + 14188fa commit 5288ecd

6 files changed

Lines changed: 141 additions & 55 deletions

File tree

.github/workflows/verify-build.yml

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,7 @@ jobs:
108108
debug: debug
109109
coverage: nocoverage
110110
shell: bash
111-
- test-group: extra
112-
os: ubuntu-latest
113-
os-type: ubuntu
114-
build-type: none
115-
compiler-family: gcc
116-
c-compiler: gcc-9
117-
cc-compiler: g++-9
118-
debug: nodebug
119-
coverage: nocoverage
120-
shell: bash
111+
# gcc-9 dropped: lacks full C++20 support (no concepts library, no std::span, no <bit> features).
121112
- test-group: extra
122113
os: ubuntu-latest
123114
os-type: ubuntu
@@ -168,26 +159,7 @@ jobs:
168159
debug: nodebug
169160
coverage: nocoverage
170161
shell: bash
171-
- test-group: extra
172-
os: ubuntu-22.04
173-
os-type: ubuntu
174-
build-type: none
175-
compiler-family: clang
176-
c-compiler: clang-11
177-
cc-compiler: clang++-11
178-
debug: nodebug
179-
coverage: nocoverage
180-
shell: bash
181-
- test-group: extra
182-
os: ubuntu-22.04
183-
os-type: ubuntu
184-
build-type: none
185-
compiler-family: clang
186-
c-compiler: clang-12
187-
cc-compiler: clang++-12
188-
debug: nodebug
189-
coverage: nocoverage
190-
shell: bash
162+
# clang-11 and clang-12 dropped: incomplete C++20 support (concepts/<bit>/<span> gaps).
191163
- test-group: extra
192164
os: ubuntu-22.04
193165
os-type: ubuntu
@@ -662,7 +634,7 @@ jobs:
662634
# IWYU always return an error code. If it returns "2" it indicates a success so we manage this within the function below.
663635
function safe_make_iwyu() {
664636
{
665-
make -k CXX='/usr/local/bin/include-what-you-use -Xiwyu --mapping_file=${top_builddir}/../custom_iwyu.imp' CXXFLAGS="-std=c++11 -DHTTPSERVER_COMPILATION -D_REENTRANT $CXXFLAGS" ;
637+
make -k CXX='/usr/local/bin/include-what-you-use -Xiwyu --mapping_file=${top_builddir}/../custom_iwyu.imp' CXXFLAGS="-std=c++20 -DHTTPSERVER_COMPILATION -D_REENTRANT $CXXFLAGS" ;
666638
} || {
667639
if [ $? -ne 2 ]; then
668640
return 1;

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Version 0.20.0
22

3+
Raised minimum C++ standard to C++20. Build now requires gcc >= 10
4+
or clang >= 13 (Apple Clang from Xcode 15+). Updated
5+
AX_CXX_COMPILE_STDCXX macro (m4/ax_cxx_compile_stdcxx.m4) to
6+
serial 25 to support C++20 detection. Pruned CI matrix rows
7+
(gcc-9, clang-11, clang-12) that lack full C++20 support.
38
Raised minimum libmicrohttpd requirement to 1.0.0.
49
Migrated Basic Auth to v3 API (MHD_basic_auth_get_username_password3,
510
MHD_queue_basic_auth_required_response3) with UTF-8 support.

README.CentOS-7

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## Cent OS 7 / RHEL 7
22

3-
CentOS 7 has a lower version of gcc (4.8.7) that is barely C++11 capable and this library
4-
needs a better compiler. We recommend at least gcc 5+
3+
CentOS 7's stock gcc (4.8.7) is far too old: this library requires a C++20 compiler
4+
(gcc >= 10 or clang >= 13).
55

6-
We recommend installing devtoolset-8
7-
https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/
6+
Install gcc-toolset-14 (or newer) from the RHEL/CentOS Software Collections and
7+
`source /opt/rh/gcc-toolset-14/enable` before configuring. The same workaround applies
8+
to RHEL 9 systems whose stock gcc-11 lacks some C++20 library features.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ Additionally, clients can specify resource limits on the overall number of conne
8787
libhttpserver can be used without any dependencies aside from libmicrohttpd.
8888

8989
The minimum versions required are:
90-
* g++ >= 5.5.0 or clang-3.6
91-
* C++17 or newer
90+
* g++ >= 10 or clang >= 13 (Apple Clang from Xcode 15+)
91+
* C++20 or newer
9292
* libmicrohttpd >= 1.0.0
9393
* [Optionally]: for TLS (HTTPS) support, you'll need [libgnutls](http://www.gnutls.org/).
9494
* [Optionally]: to compile the code-reference, you'll need [doxygen](http://www.doxygen.nl/).
9595

96+
On RHEL 9 (and derivatives), the stock GCC 11 is too old for some C++20 library features the build relies on; install the `gcc-toolset-14` package and `source /opt/rh/gcc-toolset-14/enable` before configuring.
97+
9698
Additionally, for MinGW on windows you will need:
9799
* libwinpthread (For MinGW-w64, if you use thread model posix then you have this)
98100

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ AC_LANG([C++])
4444
AC_SYS_LARGEFILE
4545

4646
# Minimal feature-set required
47-
AX_CXX_COMPILE_STDCXX([17])
47+
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
4848

4949
native_srcdir=$srcdir
5050

@@ -221,7 +221,7 @@ AM_LDFLAGS="-lstdc++"
221221

222222
if test x"$debugit" = x"yes"; then
223223
AC_DEFINE([DEBUG],[],[Debug Mode])
224-
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wextra -Werror -pedantic -std=c++17 -Wno-unused-command-line-argument -O0"
224+
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wextra -Werror -pedantic -Wno-unused-command-line-argument -O0"
225225
AM_CFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wextra -Werror -pedantic -Wno-unused-command-line-argument -O0"
226226
else
227227
AC_DEFINE([NDEBUG],[],[No-debug Mode])

m4/ax_cxx_compile_stdcxx.m4

Lines changed: 122 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#
1111
# Check for baseline language coverage in the compiler for the specified
1212
# version of the C++ standard. If necessary, add switches to CXX and
13-
# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
14-
# or '14' (for the C++14 standard).
13+
# CXXCPP to enable support. VERSION may be '11', '14', '17', '20', or
14+
# '23' for the respective C++ standard version.
1515
#
1616
# The second argument, if specified, indicates whether you insist on an
1717
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
@@ -36,13 +36,15 @@
3636
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
3737
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
3838
# Copyright (c) 2020 Jason Merrill <jason@redhat.com>
39+
# Copyright (c) 2021, 2024 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
40+
# Copyright (c) 2015, 2022, 2023, 2024 Olly Betts
3941
#
4042
# Copying and distribution of this file, with or without modification, are
4143
# permitted in any medium without royalty provided the copyright notice
4244
# and this notice are preserved. This file is offered as-is, without any
4345
# warranty.
4446

45-
#serial 12
47+
#serial 25
4648

4749
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
4850
dnl (serial version number 13).
@@ -51,6 +53,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
5153
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
5254
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
5355
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
56+
[$1], [20], [ax_cxx_compile_alternatives="20"],
57+
[$1], [23], [ax_cxx_compile_alternatives="23"],
5458
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
5559
m4_if([$2], [], [],
5660
[$2], [ext], [],
@@ -102,9 +106,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
102106
dnl HP's aCC needs +std=c++11 according to:
103107
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
104108
dnl Cray's crayCC needs "-h std=c++11"
109+
dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
105110
for alternative in ${ax_cxx_compile_alternatives}; do
106-
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
107-
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
111+
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
112+
if test x"$switch" = xMSVC; then
113+
dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
114+
dnl with -std=c++17. We suffix the cache variable name with _MSVC to
115+
dnl avoid this.
116+
switch=-std:c++${alternative}
117+
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
118+
else
119+
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
120+
fi
108121
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
109122
$cachevar,
110123
[ac_save_CXX="$CXX"
@@ -148,23 +161,44 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
148161
dnl Test body for checking C++11 support
149162

150163
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
151-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
164+
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11]
152165
)
153166

154-
155167
dnl Test body for checking C++14 support
156168

157169
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
158-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
159-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
170+
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
171+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14]
160172
)
161173

174+
dnl Test body for checking C++17 support
175+
162176
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
163-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
164-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
165-
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
177+
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
178+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
179+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17]
180+
)
181+
182+
dnl Test body for checking C++20 support
183+
184+
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
185+
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
186+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
187+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
188+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20]
166189
)
167190

191+
dnl Test body for checking C++23 support
192+
193+
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_23],
194+
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
195+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
196+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
197+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20
198+
_AX_CXX_COMPILE_STDCXX_testbody_new_in_23]
199+
)
200+
201+
168202
dnl Tests for new features in C++11
169203

170204
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
@@ -176,7 +210,21 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
176210
177211
#error "This is not a C++ compiler"
178212
179-
#elif __cplusplus < 201103L
213+
// MSVC always sets __cplusplus to 199711L in older versions; newer versions
214+
// only set it correctly if /Zc:__cplusplus is specified as well as a
215+
// /std:c++NN switch:
216+
//
217+
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
218+
//
219+
// The value __cplusplus ought to have is available in _MSVC_LANG since
220+
// Visual Studio 2015 Update 3:
221+
//
222+
// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
223+
//
224+
// This was also the first MSVC version to support C++14 so we can't use the
225+
// value of either __cplusplus or _MSVC_LANG to quickly rule out MSVC having
226+
// C++11 or C++14 support, but we can check _MSVC_LANG for C++17 and later.
227+
#elif __cplusplus < 201103L && !defined _MSC_VER
180228
181229
#error "This is not a C++11 compiler"
182230
@@ -467,7 +515,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
467515
468516
#error "This is not a C++ compiler"
469517
470-
#elif __cplusplus < 201402L
518+
#elif __cplusplus < 201402L && !defined _MSC_VER
471519
472520
#error "This is not a C++14 compiler"
473521
@@ -591,7 +639,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
591639
592640
#error "This is not a C++ compiler"
593641
594-
#elif __cplusplus < 201703L
642+
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
595643
596644
#error "This is not a C++17 compiler"
597645
@@ -957,8 +1005,66 @@ namespace cxx17
9571005
9581006
} // namespace cxx17
9591007
960-
#endif // __cplusplus < 201703L
1008+
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
1009+
1010+
]])
1011+
1012+
1013+
dnl Tests for new features in C++20
1014+
1015+
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
1016+
1017+
#ifndef __cplusplus
1018+
1019+
#error "This is not a C++ compiler"
1020+
1021+
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
1022+
1023+
#error "This is not a C++20 compiler"
1024+
1025+
#else
1026+
1027+
#include <version>
1028+
1029+
namespace cxx20
1030+
{
1031+
1032+
// As C++20 supports feature test macros in the standard, there is no
1033+
// immediate need to actually test for feature availability on the
1034+
// Autoconf side.
1035+
1036+
} // namespace cxx20
1037+
1038+
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
9611039
9621040
]])
9631041

9641042

1043+
dnl Tests for new features in C++23
1044+
1045+
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_23], [[
1046+
1047+
#ifndef __cplusplus
1048+
1049+
#error "This is not a C++ compiler"
1050+
1051+
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
1052+
1053+
#error "This is not a C++23 compiler"
1054+
1055+
#else
1056+
1057+
#include <version>
1058+
1059+
namespace cxx23
1060+
{
1061+
1062+
// As C++23 supports feature test macros in the standard, there is no
1063+
// immediate need to actually test for feature availability on the
1064+
// Autoconf side.
1065+
1066+
} // namespace cxx23
1067+
1068+
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
1069+
1070+
]])

0 commit comments

Comments
 (0)