这个 clang-tidy 命令行有什么问题?
What is wrong with this clang-tidy command line?
我正在尝试使用 clang-tidy 来分析我的项目。我正在使用以下命令行。
"C:\Program Files\LLVM\bin\clang-tidy.exe" -p G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp --extra-arg=-D_DLL --extra-arg=-D_MT --extra-arg=-fms-compatibility-version=19.10 --extra-arg=-Wall --extra-arg=-Wmicrosoft --extra-arg=-Wno-invalid-token-paste --extra-arg=-Wno-unknown-pragmas --extra-arg=-Wno-unused-value "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" --extra-arg=-cxx-isystemD:\vcpkg\installed\x64-windows\include --extra-arg=-cxx-isystemD:\vcpkg\installed\x86-windows\include "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" --extra-arg=-isystemD:\vcpkg\installed\x64-windows\include --extra-arg=-isystemD:\vcpkg\installed\x86-windows\include G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp\TTSApp.cpp
我对 isystem 命令行参数的理解是它向 SYSTEM 包含搜索路径添加了一个目录。我对 clang-tidy 的理解是,如果您不使用 -system-headers 命令行参数,它将不会包含来自系统 header 文件的问题。另外,我的理解是系统header文件是位于isystem列表中的任何目录中的目录或isystem列表中目录下的任何目录中的文件。
我遇到了位于 "D:\vcpkg\installed\x64-windows\include\boost..." 下的 Boost headers 的许多问题。问题是目录 "D:\vcpkg\installed\x64-windows" 在我的 isystem 列表中,目录 "D:\vcpkg\installed\x64-windows\include\boost..." 在 "D:\vcpkg\installed\x64-windows."
下
如果我对 clang-tidy 的理解和 isystem 命令行参数的目的是正确的,clang-tidy 应该不会因为这些问题而困扰我。
我还尝试了以下命令行参数。
"C:\Program Files\LLVM\bin\clang-tidy.exe" -p G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp\TTSApp.cpp -- -D_DLL -D_MT -fms-compatibility-version=19.10 -Wall -Wmicrosoft -Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-value -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" -cxx-isystem "C:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" -cxx-isystem D:\vcpkg\installed\x64-windows\include -cxx-isystem D:\vcpkg\installed\x86-windows\include -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" -isystem "C:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" -isystem "C:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" -isystem D:\vcpkg\installed\x64-windows\include -isystem D:\vcpkg\installed\x86-windows\include
结果是一样的
我明白了。事实证明,无论是命令行还是我对 isystem 命令行参数预期功能的理解都没有问题。
问题是我没有意识到 Clang-Tidy 识别出两种不同类型的问题,警告和错误。
Clang-Tidy 不会打扰您在系统包含中发现的 警告,除非您使用 -system-headers 命令行参数。然而,没有什么可以抑制错误。令我恼火的与 Boost 相关的问题是错误。具体来说,有多个实例出现以下错误。
error: conflicting types for '${FunctionName}'
几个 Windows API 函数发生了这些错误。可以通过定义 BOOST_USE_WINDOWS_H.
来防止这些错误
我正在尝试使用 clang-tidy 来分析我的项目。我正在使用以下命令行。
"C:\Program Files\LLVM\bin\clang-tidy.exe" -p G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp --extra-arg=-D_DLL --extra-arg=-D_MT --extra-arg=-fms-compatibility-version=19.10 --extra-arg=-Wall --extra-arg=-Wmicrosoft --extra-arg=-Wno-invalid-token-paste --extra-arg=-Wno-unknown-pragmas --extra-arg=-Wno-unused-value "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" "--extra-arg=-cxx-isystemC:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" --extra-arg=-cxx-isystemD:\vcpkg\installed\x64-windows\include --extra-arg=-cxx-isystemD:\vcpkg\installed\x86-windows\include "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" "--extra-arg=-isystemC:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" "--extra-arg=-isystemC:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" --extra-arg=-isystemD:\vcpkg\installed\x64-windows\include --extra-arg=-isystemD:\vcpkg\installed\x86-windows\include G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp\TTSApp.cpp
我对 isystem 命令行参数的理解是它向 SYSTEM 包含搜索路径添加了一个目录。我对 clang-tidy 的理解是,如果您不使用 -system-headers 命令行参数,它将不会包含来自系统 header 文件的问题。另外,我的理解是系统header文件是位于isystem列表中的任何目录中的目录或isystem列表中目录下的任何目录中的文件。
我遇到了位于 "D:\vcpkg\installed\x64-windows\include\boost..." 下的 Boost headers 的许多问题。问题是目录 "D:\vcpkg\installed\x64-windows" 在我的 isystem 列表中,目录 "D:\vcpkg\installed\x64-windows\include\boost..." 在 "D:\vcpkg\installed\x64-windows."
下如果我对 clang-tidy 的理解和 isystem 命令行参数的目的是正确的,clang-tidy 应该不会因为这些问题而困扰我。
我还尝试了以下命令行参数。
"C:\Program Files\LLVM\bin\clang-tidy.exe" -p G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp G:\src\svn\SnKOpen\cpp\TTSApp\trunk\TTSApp\TTSApp.cpp -- -D_DLL -D_MT -fms-compatibility-version=19.10 -Wall -Wmicrosoft -Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-value -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" -cxx-isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" -cxx-isystem "C:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" -cxx-isystem "C:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" -cxx-isystem D:\vcpkg\installed\x64-windows\include -cxx-isystem D:\vcpkg\installed\x86-windows\include -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\include" -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Tools\MSVC.25.28610\atlmfc\include" -isystem "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\VS\include" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\ucrt" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\winrt" -isystem "C:\Program Files (x86)\Windows Kits\Include.0.18362.0\cppwinrt" -isystem "C:\Program Files (x86)\Windows Kits\NETFXSDK.7.2\Include\um" -isystem "C:\Program Files (x86)\Microsoft SDKs\Speech\v11.0\Include" -isystem D:\vcpkg\installed\x64-windows\include -isystem D:\vcpkg\installed\x86-windows\include
结果是一样的
我明白了。事实证明,无论是命令行还是我对 isystem 命令行参数预期功能的理解都没有问题。
问题是我没有意识到 Clang-Tidy 识别出两种不同类型的问题,警告和错误。
Clang-Tidy 不会打扰您在系统包含中发现的 警告,除非您使用 -system-headers 命令行参数。然而,没有什么可以抑制错误。令我恼火的与 Boost 相关的问题是错误。具体来说,有多个实例出现以下错误。
error: conflicting types for '${FunctionName}'
几个 Windows API 函数发生了这些错误。可以通过定义 BOOST_USE_WINDOWS_H.
来防止这些错误