gpt4 book ai didi

c++ - 在 Linux 上使用 CMake 时如何告诉 PVS-Studio 忽略第三方库中的所有文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:02:25 26 4
gpt4 key购买 nike

我在 Linux 上将 PVS-Studio 与 CMake 结合使用。我最近在我的项目中添加了一个第三方库。

PVS-Studio 正在标记第三方库的头文件中可能存在的问题。在分析我的代码时,如何让 PVS-Studio 忽略整个第三方库?在 Windows 上将 PVS-Studio 与 Visual Studio 结合使用时,我能够使用 Visual Studio 中的 PVS-Studio 扩展来执行此操作。在 Linux 上我没有那个。

我已将我的 CMakeLists.txt 文件附加到该项目(非常简单)以及 PVS-Studio 发出的警告列表。

CMakeLists.txt

cmake_minimum_required(VERSION 3.15.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
project(my_project)
include_directories($ENV{HOME}/code/repo/other/GSL/include)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(proj_srcs main.cpp notes.txt)
add_executable(${PROJECT_NAME} ${proj_srcs})
include($ENV{HOME}/code/repo/other/pvs-studio-cmake-examples/PVS-Studio.cmake)
pvs_studio_add_target(TARGET ALL COMPILE_COMMANDS OUTPUT FORMAT errorfile)

警告

.../other/GSL/include/gsl/multi_span:663:1: warning: V547 Expression is always true.
.../other/GSL/include/gsl/multi_span:1163:1: warning: V560 A part of conditional expression is always true: totalSize <= (9223372036854775807L).
.../other/GSL/include/gsl/string_span:118:1: warning: V547 Expression 'cur != nullptr' is always true.

我仍然无法让它正常工作。

在 CMakeLists.txt 中我有:

# The header files for the C++ Standard Library are located in /usr/include.
# Unfortunately ARGS --exclude-path /usr/include does not suppress the warnings
# generated by Clang.
pvs_studio_add_target(TARGET ALL COMPILE_COMMANDS OUTPUT FORMAT errorfile ARGS --exclude-path /usr/include)

使用 Clang 12.0.0 x86_64-pc-linux-gnu 构建时,PVS Studio 会生成数百行警告。例如,

--- snip ---
/include/c++/10/bits/stl_numeric.h:64:1: warning: V1061 Extending the 'std' namespace may result in undefined behavior.
/include/c++/10/numeric:80:1: warning: V1061 Extending the 'std' namespace may result in undefined behavior.
/include/c++/10/numeric:167:1: warning: V1061 Extending the 'std' namespace may result in undefined behavior.
/include/c++/10/numeric:226:1: warning: V1061 Extending the 'std' namespace may result in undefined behavior.
/include/c++/10/pstl/glue_numeric_defs.h:15:1: warning: V1061 Extending the 'std' namespace may result in undefined behavior.
--- snip ---

有人知道哪里出了问题吗?

谢谢,

最佳答案

你可以使用这个参数:

-e [DIR], --exclude-path [DIR]
Directory whose files are not necessary to check

CMakeLists.txt:

pvs_studio_add_target(TARGET ALL
COMPILE_COMMANDS
OUTPUT FORMAT errorfile
ARGS -e /path/to/third/party -e /path/to/tests)

关于c++ - 在 Linux 上使用 CMake 时如何告诉 PVS-Studio 忽略第三方库中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57303896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com