Can I compile using C++ 20?
-
wrote on 24 Feb 2021, 22:27 last edited by
I have an up-to-date installation of Qt. Is it possible to compile my code with the latest features in C++20? It seems C++17 is the latest Qt supports. I saw a post that suggested putting
CONFIG += c++2a
in my .pro file, but that doesn't seem to do anything for me. -
Hi,
Which version of Qt are you using ?
With which compiler ?
On which OS ? -
wrote on 25 Feb 2021, 00:11 last edited by
Qt Version 5.15.0
mingw-32 compiler
Windows 10 -
wrote on 25 Feb 2021, 02:36 last edited by Bonnie
Qt will add
-std=gnu++2a
to CXXFLAGS after addingCONFIG+=c++2a
in your case.
But the final effect is depending on your compiler. -
@kitfox well does your compiler support c++20 ?
Where did you get it, and when (last update)
if you make a simple c++ program with
#include <iostream> using namespace std; int main() { #if __cplusplus >= 202002L // C++20 (and later) code cout << "C++20 (and later)" << endl; #endif return 0; }
Does it then print something ?
-
@kitfox well does your compiler support c++20 ?
Where did you get it, and when (last update)
if you make a simple c++ program with
#include <iostream> using namespace std; int main() { #if __cplusplus >= 202002L // C++20 (and later) code cout << "C++20 (and later)" << endl; #endif return 0; }
Does it then print something ?
wrote on 25 Feb 2021, 14:43 last edited by@J-Hilk
I presume so since it is the mingw that comes with Qt 5.15.0. However, I do not know what the configuration options are that I need to get it to compile for C++20.When I compile with
CONFIG += c++2a
, __cplusplus gives the string201709
.CONFIG += c++17
gives201703
andCONFIG += c++20
gives201402
. I'm not sure what to pass to indicate a different version of C++.If my compiler does not support c++ 20, how would I get one that does?
-
@kitfox said in Can I compile using C++ 20?:
If my compiler does not support c++ 20, how would I get one that does?
GCC 8 does not support more than 201709L I would guess according to the documentation. Therefore you need to upgrade it. MinGW64 does not provide a later compiler than gcc8: http://mingw-w64.org/doku.php/versions
-
AFAIK, on Windows, the best compiler on Windows with C++20 support is currently VS2019.
1/8