I enabled clang-tidy integration to a CMake project like so:
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-header-filter=.;
--config-file=${MY_CLANG_TIDY_CONFIG_PATH};
)
In the .clang-tidy config file, there are rules for checking naming conventions only.
After generating the project and trying to build one one of the targets, I get an error from clang claiming exceptions are used even though disabled.
This is the command I run and its output:
cmake --build --preset=ninja-wd --target=Eureka.Core
output:
[1/3] Building CXX object Libs\Eureka.Core\CMakeFiles\Eureka.Core.dir\system.cpp.obj
FAILED: Libs/Eureka.Core/CMakeFiles/Eureka.Core.dir/system.cpp.obj
"C:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --tidy=clang-tidy;-header-filter=.;--config-file=C:/workspace/Eureka/.clang-tidy;--extra-arg-before=--driver-mode=cl --source=C:\workspace\Eureka\Libs\Eureka.Core\system.cpp -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\cl.exe /nologo /TP -DBoost_NO_WARN_NEW_VERSIONS=1 -DEUREKA_NO_NVTOOLSEXT -DNOMINMAX -DPERFETTO_TRACING -DPROFILING_ENABLED -DWIN32_LEAN_AND_MEAN -IC:\workspace\Eureka -IC:\workspace\Eureka\Libs\Eureka.Core /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -MDd /permissive- /bigobj /W4 /EHsc -std:c++latest /showIncludes /FoLibs\Eureka.Core\CMakeFiles\Eureka.Core.dir\system.cpp.obj /FdLibs\Eureka.Core\CMakeFiles\Eureka.Core.dir\Eureka.Core.pdb /FS -c C:\workspace\Eureka\Libs\Eureka.Core\system.cpp
C:\workspace\Eureka\Libs\Eureka.Core\system.cpp:26:9: error: cannot use 'throw' with exceptions disabled [clang-diagnostic-error]
throw std::system_error(ec, "system error");
^
2823 warnings and 1 error generated.
Error while processing C:\workspace\Eureka\Libs\Eureka.Core\system.cpp.
Suppressed 2824 warnings (2823 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
As far as I can see, the /EHsc flag is passed to cl.exe. And yet I get the error from clang saying
error: cannot use 'throw' with exceptions disabled [clang-diagnostic-error]
throw std::system_error(ec, "system error");
What is going on here? why is clang-tidy complaining?
If I disable the clang-tidy integration, the project builds just fine.