Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++14 support in QtCreator with Clang

How can I enable C++14 support in QtCreator 3.3 using Clang 3.5? I have added a Clang kit and I have added CONFIG += c++14 in my project file. However when using e.g. return type deduction I get the following error:

error: 'auto' return without trailing return type; deduced return types are a C++1y extension

like image 482
gartenriese Avatar asked Jan 09 '15 10:01

gartenriese


2 Answers

you can use CONFIG += c++14 in .pro file with Qt5.5

but there is a bug with clang, so we need to modify the Qt/5.5/clang_64/mkspecs/features/c++14.prf file, add this code beforeinclude(c++11.prf) :

contains(QMAKE_LFLAGS_CXX11, -stdlib=libc++) {
    QMAKE_CXXFLAGS_CXX11 += -stdlib=libc++
}
like image 159
mink365 Avatar answered Nov 10 '22 13:11

mink365


I had to go to the Makefile in the build folder and manually replace -std=c++11 with -std=c++14.

Thankfully the Makefile is only written once when you add the kit to the project. I only had to do this once and could build in QtCreator as often as I want.

So now I can use a Clang kit to use all the new c++14 features. As a bonus, I can also use all the c++17 features if I manually set -std=c++1z in the Makefile. Sweet!

like image 4
gartenriese Avatar answered Nov 10 '22 11:11

gartenriese