忽略clang-tidy中的系统头 [英] Ignore system headers in clang-tidy

查看:440
本文介绍了忽略clang-tidy中的系统头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tldr;>如何在clang-tidy中隐藏系统标题中的警告?

我有以下最小示例源文件,会在系统标题中触发叮叮当当的警告:

I have the following minimal example source file, which triggers a clang-tidy warning in the system headers:

#include <future>

int main() {
  std::promise<int> p;
  p.set_value(3);
}

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

Calling it with libstdc++ 7.0.1 using clang-tidy 4.0.0 on Ubuntu 17.04:

$ clang-tidy main.cpp -extra-arg=-std=c++14

收益

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'
        call_once(_M_once, &_State_baseV2::_M_do_set, this,
        ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:691:11: note: Assuming '__e' is 0
      if (__e)
          ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:691:7: note: Taking false branch
      if (__e)
      ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: note: 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
    }

我想在系统标题中隐藏警告。我尝试了以下操作:

I want to hide warnings in system headers. I tried the following:

$ clang-tidy -extra-arg=-std=c++14 main.cpp -header-filter=$(realpath .) -system-headers=0

但警告仍然显示。

推荐答案

我也遇到了这个问题,并花了一些时间试图解决这个问题,但是我看不到在clang-tidy中禁用此类警告的方法。

I ran into this issue as well, and spent some time trying to figure it out, but I could not see a way to disable this type of warning in clang-tidy.

通过阅读有关LLVM问题跟踪器的有关类似的问题,我的印象是,从clang-tidy的角度来看,该警告实际上位于 main.cpp 中,因为对 set_value 是从那里来的。

From reading this discussion on the LLVM issue tracker regarding a similar issue, I get the impression that the problem is that from clang-tidy's perspective, the warning is actually located in main.cpp, because the call to set_value is from there.

我的解决方法是禁用clang-tidy中的静态分析检查,并使用扫描构建实用程序以运行clang的静态分析,这似乎避免了这些问题。例如,使用您的 main.cpp

My workaround has been to disable the static analysis checks in clang-tidy, and use the scan-build utility to run clang's static analysis, which seems to avoid these problems. For example, using your main.cpp:

$ scan-build-3.9 clang++ -std=c++14 main.cpp 
scan-build: Using '/usr/lib/llvm-3.9/bin/clang' for static analysis
In file included from main.cpp:1:
In file included from /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/future:39:
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/mutex:621:11: 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
      if (__e)
          ^~~
1 warning generated.
scan-build: Removing directory '/tmp/scan-build-2017-12-02-112018-13035-1' because it contains no reports.
scan-build: No bugs found.

分析器在系统标头中发现相同的错误,但是它足够聪明,不将其包含在总结报告。 (找不到错误)

The analyzer finds the same error in a system header, but it's smart enough not to include it in the final report. ("No bugs found")

如果您对样式指南类型的警告感兴趣,则仍需要单独运行clang-tidy,例如 modernize-* readability-*

You'll still need to run clang-tidy separately if you are interested in the style guide type warnings, like modernize-* or readability-*.

这篇关于忽略clang-tidy中的系统头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆