I have recently updated gcc and g++ to version 7.2. I would like to try out std::experimental::any
and std::variant
in particular, and I am using Q
CONFIG += c++17
can be used with Qt 5.12 and later.
For Qt 5.11 and earlier, it is not a recognized QMake flag and you have to get your hands a bit dirty.
Adding QMAKE_CXXFLAGS += -std=c++17
does the job for GCC & Clang; for MSVC you will probably need to specify /std:c++17
or /std:c++latest
.
For Windows: I'm download qt-opensource-windows-x86-5.11.1, icncluded MinGW32. For MinGW64 I'm download qt-5.5.0-x64-mingw510r0-seh-rev0 and install only compiler. Configure QtCreator, as says here. Create new project and add QMAKE_CXXFLAGS += -std=gnu++1z to .pro file (gcc doc). For test, try compile this simple code:
#include <optional>
std::optional<int> foo()
{
return std::nullopt;
}
int main(int argc, char *argv[])
{
foo();
}
Edit 3/2019: You can use CONFIG += c++17
since Qt 5.12.
The actual flag is c++1z
, not c++17
. In short, to get C++17 support, you don't need to modify QMAKE_CXXFLAGS
and can instead simply use CONFIG += c++1z
.
Discussion on the reason why can be found in this bug report, but it pretty much amounts to "we implemented it as c++1z
before C++17 was standardized, and now we won't bother aliasing it."
Note: I realize you just needed a clean and rebuild. I'm answering the underlying question of "what flags do I need to use to enable C++17 support?"