英文:
clang tidy emits errors about exceptions being disabled when the are enabled
问题
我已启用将clang-tidy集成到CMake项目的功能,如下所示:
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-header-filter=.;
--config-file=${MY_CLANG_TIDY_CONFIG_PATH};
)
在.clang-tidy配置文件中,只有检查命名规范的规则。
在生成项目并尝试构建其中一个目标后,我从clang中得到一个错误,声称即使已禁用异常,仍然在使用。
这是我运行的命令及其输出:
cmake --build --preset=ninja-wd --target=Eureka.Core
输出:
[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~222\COMMUN~1\VC\Tools\MSVC34~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).
就我所见,/EHsc标志已传递给cl.exe。然而,我从clang中得到错误,说
error: cannot use 'throw' with exceptions disabled [clang-diagnostic-error]
throw std::system_error(ec, "system error");
这里发生了什么?为什么clang-tidy在抱怨呢?
如果我禁用clang-tidy集成,项目就能正常构建。
英文:
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~222\COMMUN~1\VC\Tools\MSVC34~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.
答案1
得分: 1
clang-tidy 似乎无法识别 --
后面的 /EHsc
(传递给 cl.exe 的参数)。
您可以尝试手动将 --extra-args=/EHsc
添加到您的 CMAKE_CXX_CLANG_TIDY
中,以规避此问题。
https://gitlab.kitware.com/cmake/cmake/-/issues/20512 可能是这个问题。
英文:
Seems that clang-tidy fails to recognize the /EHsc
after --
(the parameters given to cl.exe).
You may try manually add a --extra-args=/EHsc
into your CMAKE_CXX_CLANG_TIDY
to bypass that issue.
https://gitlab.kitware.com/cmake/cmake/-/issues/20512 possibly the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论