Can I compile using C++ 20?
-
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 ? -
@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 ?
-
@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.