I am trying to use C++20 with Qt, but no matter what I do, it always defaults to C++17.
Here is the relevant part of the output after configuration:
# head config.summary
Build type: linux-g++ (x86_64, CPU features: mmx sse sse2)
Compiler: gcc 13.1.0
Configuration: sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f
avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi
avx512vl compile_examples enable_new_dtags f16c largefile precompile_header
rdrnd rdseed shani x86SimdAlways shared shared rpath release
c++11 c++14 c++17 c++1z concurrent dbus reduce_exports reduce_relocations stl
Build options:
Using C standard ....................... C11
Using C++ standard ..................... C++17
Dockerfile. I am running the following in a Docker container:
FROM ubuntu:18.04
# Install gcc-13 PPA
RUN echo "deb [trusted=yes] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic main" > /etc/apt/sources.list.d/ubuntu-toolchain-r-test.list && \
apt update && \
apt install -y --no-install-recommends gcc-13 g++-13 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
WORKDIR /opt/build
RUN sed -i 's|# deb|deb|' /etc/apt/sources.list && \
apt update && \
apt install -y --no-install-recommends git libedit-dev libopenal-data libsndio-dev libopenal1 libopenal-dev pulseaudio libpthread-workqueue-dev && \
apt build-dep -y qtbase-opensource-src && \
apt-get purge -y gcc-7 g++-7 cpp-7 gcc-7-base && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100 && \
apt install -y wget xz-utils && \
wget -P /opt/ https://cdimage.debian.org/mirror/qt.io/qtproject/archive/qt/5.15/5.15.16/single/qt-everywhere-opensource-src-5.15.16.tar.xz && \
tar -xf /opt/qt-everywhere-opensource-src-5.15.16.tar.xz -C /opt/
Build Steps. After starting the container, I run the following commands:
docker run -it --rm IAMGENAME bash
export CXXFLAGS="-std=c++20"
../qt-everywhere-src-5.15.16/configure -bundled-xcb-xinput -xcb -xcb-xlib -pulseaudio -alsa -opensource -confirm-license -recheck-all -v -nomake tests -nomake examples
However, the configuration always defaults to C++17, as shown in the config.summary file.
How can I configure to use the C++20 standard?
Any help would be greatly appreciated!
This should work
../qt-everywhere-src-5.15.16/configure -c++std c++2b -bundled-xcb-xinput -xcb -xcb-xlib -pulseaudio -alsa -opensource -confirm-license -recheck-all -v -nomake tests -nomake examples
qtbase/configure.json sets the supported C++ standards:
"cxx14": {
"label": "C++14 support",
"type": "compile",
"test": {
"head": [
"#if __cplusplus > 201103L",
"// Compiler claims to support C++14, trust it",
"#else",
"# error __cplusplus must be > 201103L (the value of C++11)",
"#endif"
],
"qmake": "CONFIG += c++11 c++14"
}
},
"cxx17": {
"label": "C++17 support",
"type": "compile",
"test": {
"head": [
"#if __cplusplus > 201402L",
"// Compiler claims to support C++17, trust it",
"#else",
"# error __cplusplus must be > 201402L (the value for C++14)",
"#endif",
"#include <map> // https://bugs.llvm.org//show_bug.cgi?id=33117",
"#include <variant>"
],
"main": [
"std::variant<int> v(42);",
"int i = std::get<int>(v);",
"std::visit([](const auto &) { return 1; }, v);"
],
"qmake": "CONFIG += c++11 c++14 c++17"
}
},
"cxx2a": {
"label": "C++2a support",
"type": "compile",
"test": {
"head": [
"#if __cplusplus > 201703L",
"// Compiler claims to support experimental C++2a, trust it",
"#else",
"# error __cplusplus must be > 201703L (the value for C++17)",
"#endif"
],
"qmake": "CONFIG += c++11 c++14 c++17 c++2a"
}
},
"cxx2b": {
"label": "C++2b support",
"type": "compile",
"test": {
"head": [
"#if __cplusplus > 202002L",
"// Compiler claims to support experimental C++2b, trust it",
"#else",
"# error __cplusplus must be > 202002L (the value for C++20)",
"#endif"
],
"qmake": "CONFIG += c++11 c++14 c++17 c++2a c++2b"
}
},