1

I'm linting a project with clang-tidy and I'm getting errors from files which are not included in the project. These files are for example:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xstddef
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility

A shortened error message looks like this:

[build] FAILED: CMakeFiles/Xchange.dir/src/CsvReader.cpp.obj 
[build] "C:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --tidy=clang-tidy;-checks=*,-llvm-*,-llvmlibc-*,-fuchsia-*,-modernize-use-trailing-return-type;--extra-arg-before=--driver-mode=g++ --source=../src/CsvReader.cpp -- C:\Qt\Tools\mingw810_64\bin\g++.exe -DLOGFILE_NAME=\"DwgImport.log\" -DWIN64 -D_WIN64 -D_WINDOWS -I../include -I_deps/geometry-src/include -I_deps/dwgimport-src/include -I../include/windows -I../src -I../src/Dwg -I../src/List -I_deps/mongoc-build/src/libmongoc/src -I_deps/mongoc-build/src/libmongoc/src/mongoc -I_deps/mongoc-src/src/libmongoc/src -I_deps/mongoc-src/src/libmongoc/src/mongoc -I_deps/mongoc-src/src/libmongoc/../../src/common -I_deps/mongoc-build/src/libmongoc/../../src -I_deps/mongoc-build/src/libmongoc/../../src/common -I_deps/mongoc-build/src/libbson/src -I_deps/mongoc-build/src/libbson/src/bson -I_deps/mongoc-src/src/libbson/src -I_deps/mongoc-src/src/libbson/src/bson -I_deps/mongoc-src/src/libbson/../../src/common -I_deps/mongoc-build/src/libbson/../../src -I_deps/mongoc-build/src/libbson/../../src/common -g -std=gnu++11 -MD -MT CMakeFiles/Xchange.dir/src/CsvReader.cpp.obj -MF CMakeFiles\Xchange.dir\src\CsvReader.cpp.obj.d -o CMakeFiles/Xchange.dir/src/CsvReader.cpp.obj -c ../src/CsvReader.cpp
[build] error: too many errors emitted, stopping now [clang-diagnostic-error]
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xstddef:285:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension [clang-diagnostic-error]
[build] _NODISCARD constexpr auto _Unfancy(_Ptrty _Ptr) noexcept { // converts from a fancy pointer to a plain pointer
[build]                      ^
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility:196:15: error: deduced return types are a C++14 extension [clang-diagnostic-error]
[build]     constexpr decltype(auto) operator()(_Args&&... _Vals) { // forward function call operator
[build]               ^
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility:1264:16: error: constexpr function's return type 'void' is not a literal type [clang-diagnostic-error]
[build] constexpr void _Adl_verify_range(const _Iter& _First, const _Sentinel& _Last) {
[build]                ^
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility:1300:22: error: deduced return types are a C++14 extension [clang-diagnostic-error]
[build] _NODISCARD constexpr decltype(auto) _Get_unwrapped(_Iter&& _It) {
[build]                      ^
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xutility:1347:22: error: deduced return types are a C++14 extension [clang-diagnostic-error]
[build] _NODISCARD constexpr decltype(auto) _Get_unwrapped_unverified(_Iter&& _It) {
[build]                      ^

…

This are the build environment details:

  • Win 10 64 bit
  • MinGW
  • GCC 8.1.0
  • CMake 3.18.4
  • clang 11.0.0
  • CMake
    • clang-tidy variable: set(CMAKE_CXX_CLANG_TIDY clang-tidy "-checks=*,-llvm-*,-llvmlibc-*,-fuchsia-*,-modernize-use-trailing-return-type")
    • Using C++11 via set(CMAKE_CXX_STANDARD 11)

Obviously some of the stuff in xstddef and xutility isn't compatible to C++11. However I'm not including these files anywhere in my build. It seems that clang-tidy is pulling them in for analysis for some reason.

Isn't it possible to properly use clang-tidy with a project using MinGW/GCC?

marcel
  • 25
  • 6
  • 1
    Those are headers that are part of the Microsoft implementation of the standard library, and are included by other standard headers. Looks like you need to tell clang-tidy the proper path to the include files you're using, and/or enable C++11 (or later) for it. – 1201ProgramAlarm Mar 01 '21 at 15:41
  • The thing is that the mentioned files are not even used if I disable clang-tidy. I verified that by putting an `#error foo` in the xutility file and building without clang-tidy. No 'error foo' reported. If I enable clang-tidy however 'error foo' is breaking the build. – marcel Mar 01 '21 at 20:04

0 Answers0