- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
tldr;> 如何在 clang-tidy 中隐藏来自系统 header 的警告?
我有以下最小示例源文件,它会在系统 header 中触发一个整洁的警告:
#include <future>
int main() {
std::promise<int> p;
p.set_value(3);
}
在 Ubuntu 17.04 上使用 clang-tidy 4.0.0 使用 libstdc++ 7.0.1 调用它:
$ 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
}
我想在系统标题中隐藏警告。我尝试了以下方法:
$ clang-tidy -extra-arg=-std=c++14 main.cpp -header-filter=$(realpath .) -system-headers=0
但警告仍然显示。
最佳答案
我也遇到了这个问题,并花了一些时间试图解决这个问题,但我看不到在 clang-tidy 中禁用此类警告的方法。
通过阅读 this discussion on the LLVM issue tracker regarding a similar issue ,我得到的印象是问题在于从 clang-tidy 的角度来看,警告实际上位于 main.cpp
,因为对 set_value
的调用是从那里开始的。
我的解决方法是禁用clang-tidy中的静态分析检查,并使用scan-build utility运行clang的静态分析,这似乎可以避免这些问题。例如,使用您的 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.
分析器在系统 header 中发现了相同的错误,但它足够聪明,不会将其包含在最终报告中。 (“未发现错误”)
如果您对样式指南类型的警告感兴趣,您仍然需要单独运行 clang-tidy,例如 modernize-*
或 readability-*
。
关于c++ - 忽略 clang-tidy 中的系统头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46638293/
使用 HTML5 中的新文档类型和元素,您如何获得 xdmp:tidy()识别 HTML5 中的那些? 如果我有一个包含以下内容的 html 页面: blah blah 然后尝试类
我有一些想要使用的 Django 模板文件 tidy清理。但是,它插入了我不想要的所有这些文档类型和标题垃圾。主要是,我只是想修复缩进。所有其他的东西都是额外的。 tidy 甚至可以处理像这样的部分文
我正在从 cmdline 使用 clang-tidy clang-tidy readability-implicit-bool-conversion ... " . 这个 clang-tidy 选项有
我有几个项目,我想解析很多标题,但有几个标题我不想用 clang-tidy 解析 我的文件夹层次结构如下 一种\ B\ C\ coco.h
clang-tidy --dump-config 命令产生如下内容: --- Checks: 'clang-diagnostic-*,clang-analyzer-*' Warnin
我正在使用 HTML Tidy,并且使用类似的东西 Link 它使 Link 我如何告诉 Tidy 保持链接的原样? 我的配置: 'output-xhtml' => true, 'numeric-en
我有一个 Maven 项目。当我运行该项目时,我收到错误。错误原因是 Caused by: java.lang.NoSuchMethodError: org.w3c.tidy.Tidy.setHide
我正在尝试从命令提示符运行 Maven 2 中内置的 java 应用程序 在命令提示符下,我执行了“mvn package”并在应用程序的目标文件夹中获取了 jar 然后我做了:- java -cp
我想配置我的 -line-filter= .clang-tidy 中的参数文件而不是在生成命令的 cmake 源文件中。添加 LineFilter文件的 key 只会让我出现“未知 key ”错误。这
我无法让 clang-tidy 读取我的编译数据库。如果我尝试: clang-tidy --config-file ./.clang-tidy -checks=* -p ./target 或 clan
我目前正在使用一个脚本,该脚本使用 tidy library 验证无效的 XML 文件或字符串。 测试其运行的示例代码: #include #include #include #include
命令 clang-tidy --export-fixes=fixes.yml 生成文件 fixes.yml像这样的姿势 --- Diagnostics: - DiagnosticName: mo
是否可以在 clang-tidy 中分析 C/C++ 文件,同时忽略其语法/编译错误? 我有一个很大的文件,有几个编译错误,但我仍然想用 clang-tidy 分析它。 我收到以下错误消息: 20 w
我从官方主页(http://sourceforge.net/projects/curlpas/files/)下载了最新版本(TidyPas_Delphi2010.zip)。 但是令我惊讶的是,单元中充
我在 docker container 中使用 php7 来运行基于 phpdocx 库的服务。它需要安装 tidy 和一些其他扩展并激活才能工作。我已经安装了 php-tidy 但是我收到以下警告。
自从在我们的CI服务器上使用ccache以来,我们发现构建时间方面的瓶颈现在是我们的静态分析过程,其中包括clang-tidy和其他工具。有谁知道用与常规编译器clang-tidy相似的方式来加速cc
我使用 Java 库 Tidy 来清理 html 代码。一些代码包含带有俄文字母的链接。例如 link with Russian letters 我知道必须对“Русский”进行转义,但我从用户那里
如果属性值周围缺少引号,我是否可以设置任何选项来整齐地向我显示警告?目前我运行整洁如下: tidy -xml -e test.html 在 test.html 中: 没有警告,但实际上 XML 需要
对于 C++ 的 HTML 代码,是否有等同于 tidy 的东西?我在互联网上搜索过,但除了用于 tidy 的 C++ 包装器之外,我什么也没找到...我认为关键字 tidy 是让我挂断电话的原因。
在将 xml 加载到 DomDocument 之前,我想使用 PHP Tidy 来确保它有效。 但是,我不希望 Tidy 改变我的格式 - 我只希望它修复标签不平衡等问题。 问题的一个例子可以在这个页
我是一名优秀的程序员,十分优秀!