I use some C++14 features with Clang 3.8 in my project. The build system is CMake, so I run clang static analysis like this:
$ scan-build cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang \
/path/to/source
$ scan-build make
This way building and analysis work perfectly well, but I also want to use it from Qt Creator through GUI integration. When I press Analyze -> Clang Static Analyzer, clang stops on the first file using C++14 features with nonzero error code and errors like:
error: <a_cool_c++14_feature> is a C++14 extension
I added
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
to my topmost CMakeLists.txt
, but it didn't work. I also tried to set CXX_STANDARD
with set_property
command for all targets, but I got the same result in Qt Creator, while building by hand from console works well.
How to use C++14 in Clang Static Analyzer from Qt Creator GUI?
try to add -std=c++14
in Option > C++ > Code Model.
Mine is like this :
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-unused-macros -Wno-newline-eof -Wno-exit-time-destructors -Wno-global-constructors -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation -Wno-shadow -Wno-missing-prototypes -Wsuggest-override -std=c++14
Note : You have to reopen each file for it to take effect. If you can't edit it, you have to enable the plugin "Code model" first (help > about plugins...) and restart QtCreator