相关疑难解决方法(0)

在clang-tidy中忽略系统头

tldr;>如何在clang-tidy中隐藏系统头文件中的警告?

我有以下最小示例源文件,它会在系统标头中触发一个铿锵有力的警告:

#include <future>

int main() {
  std::promise<int> p;
  p.set_value(3);
}
Run Code Online (Sandbox Code Playgroud)

在Ubuntu 17.04上使用clang-tidy 4.0.0使用libstdc ++ 7.0.1调用它:

$ clang-tidy main.cpp -extra-arg=-std=c++14
Run Code Online (Sandbox Code Playgroud)

产量

Running without flags.
1 warning generated.
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: warning: Address of stack memory associated with local variable '__callable' is still referred to by the global variable '__once_callable' upon returning to the caller.  This will be a dangling reference [clang-analyzer-core.StackAddressEscape]
    }
    ^
/home/user/main.cpp:5:3: note: Calling 'promise::set_value'
  p.set_value(3);
  ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:1094:9: note: Calling '_State_baseV2::_M_set_result'
      { _M_future->_M_set_result(_State::__setter(this, std::move(__r))); }
        ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:401:2: note: Calling 'call_once' …
Run Code Online (Sandbox Code Playgroud)

c++ clang clang-static-analyzer libtooling clang-tidy

19
推荐指数
2
解决办法
5460
查看次数

clang-tidy - 忽略第三方标题代码

我正在为我的项目使用 CMake,我想为项目引入 clang-tidy 检查。

我使用这个目的CMAKE_CXX_CLANG_TIDY.clang-tidy文件检查设置。

我想使用警告作为错误在 CI 中有可靠的方法来检查提交是否引入了一些新的违规行为。不幸的是,由于 3rd 方库,我在启用检查时遇到了一些问题。例如,我使用Eigenwhich 是仅标头库。由于这个事实,我在我的代码中收到了一些警告,例如。“a_file.cpp”

/snap/cmake/301/bin/cmake -E __run_co_compile --tidy="clang-tidy;--extra-arg-before=--driver-mode=g++" --source=../../a_file.cpp -- /usr/bin/clang++ -DEIGEN_MPL2_ONLY -DEIGEN_STACK_ALLOCATION_LIMIT=16384 -I../../SomePath -I../../SomePath2 -isystem ../../path_to/include/Eigen -m64 -stdlib=libc++ -g -fPIC -std=c++11 -MD -MT a_file.cpp.o -MF a_file.cpp.o.d -o a_file.cpp.o -c a_file.cpp                                                                            
../../path_to/include/Eigen/Eigen/src/Core/Swap.h:89:36: error: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign,-warnings-as-errors] 
a_file.cpp:279:5: note: Loop condition is true.  Entering loop body                            
    for( unsigned int i = 0; i < 100; ++i )                                                                                                                                                                                                                         
    ^                                                                                                                                                                                                                                                                 
a_file.cpp:282:13: note: Calling move assignment operator …
Run Code Online (Sandbox Code Playgroud)

c++ cmake clang clang-tidy

14
推荐指数
1
解决办法
2228
查看次数

是否可以使用 clang-tidy 忽略标头

我想包含来自外部项目的标头,但 clang-tidy 对此非常不满意,并生成了大量警告列表。为了解决这个问题,我尝试禁用来自此标头的所有诊断。

我试过:

// NOLINTBEGIN
// NOLINTNEXTLINE
#include <bad.hpp> // NOLINT
// NOLINTEND
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这不起作用。

电子邮件线程建议使用-header-filter(HeaderFilterRegex) 选项。

HeaderFilterRegex: '^((?!bad.hpp).)*$'
Run Code Online (Sandbox Code Playgroud)

但这会导致所有标头被忽略,因为 clang tidy使用POSIX 正则表达式语法。这不支持负面展望。

正如这个答案所建议的那样,我还考虑使用线路过滤器,但配置文件没有这样的选项。

有可能吗?

clang-tidy

11
推荐指数
1
解决办法
7969
查看次数

Clang-Tidy“抑制 X 警告”是什么意思?

这是我的扫描命令(使用 .clang-tidy 配置):

clang-tidy <source_file> -- <a_bunch_of_include_files> <a_bunch_of_libraries>
Run Code Online (Sandbox Code Playgroud)

我看到了源代码的输出,这很好。在最底部我看到:

Suppressed 30000 (30000 in non-user code). warnings
Run Code Online (Sandbox Code Playgroud)

源代码使用多个标头,源文件是一个非常大且复杂的系统的一小部分。clang-tidy 是否也会扫描包含文件和库?这 30,000 个警告从何而来?

c++ clang-tidy

4
推荐指数
1
解决办法
1219
查看次数