是否/正在为GCC开发“ clang ++:-Wunused-lambda-capture”等效警告? [英] Is there a `clang++:-Wunused-lambda-capture` equivalent warning in/being developed for GCC?

查看:395
本文介绍了是否/正在为GCC开发“ clang ++:-Wunused-lambda-capture”等效警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时会遇到使用以下虚拟lambda捕获的代码(而不是例如(void)x; ... foo(int / * x * /) ... foo([[maybe_unused]] int x) 在C ++ 17中),以纠正未使用的变量警告:

I sometimes run into code that use the following dummy lambda-capture (instead of e.g. (void)x;, ... foo(int /* x */) or ... foo([[maybe_unused]] int x) in C++17) in order to remedy an unused variable warning:

void foo(int x)
{
    [&x]{}();
}

现在,这并不是真正的补救方法,因为它通过了警告Lambda捕获的当前作用域取而代之,但是afaik,GCC没有诊断程序来标记此行为,而例如Clang(从5.0起)如果激活,则发出未使用的lambda捕获警告。

Now, this is not really a remedy, as it passes the warning over from the current scope to the lambda capture instead, but afaik, GCC has no diagnostic to flag this, whereas e.g. Clang (as of 5.0) emits the unused-lambda-capture warning, if activated.

$ clang++ -xc++ -std=c++11 -Wunused-lambda-capture - <<< "int main() { int x; [&x]{}(); }"

<stdin>:1:23: warning: lambda capture 'x' is not used [-Wunused-lambda-capture]
int main() { int x; [&x]{}(); }
                      ^
1 warning generated.

在GCC项目中,如果可能的话,我将能够在不诉诸Clang的情况下捕获上述结构。

In GCC projects, I would if possible be able to catch constructs as the one above without resorting to Clang.


  • GCC目前确实不存在?

  • 如果不是,那么该功能是否正在计划中/正在实施?

推荐答案

这是GCC的公开错误报告



This is an open bug report for GCC


当前确实没有等效功能

Is there indeed currently no equivalent for GCC?

确实如此,正如非常古老但仍未解决的错误报告所涵盖的:

This is indeed the case, as is covered by the very old but still open bug report:

  • Bug 52281 - No warnings generated for unused captures

如果不是,则该功能是否当前计划实施/正在实施?

If not, is that a feature that is currently planned to be implemented / currently being implemented?

基于对此错误报告未采取任何措施(在2012年报告了并得到确认,此后似乎没有发生太多的事情),这不是可能很快就会添加的东西。

Based on the lack of action on this bug report (reported and confirmed in 2012, seemingly not much happening since), this is not something that will likely be added soon.

这篇关于是否/正在为GCC开发“ clang ++:-Wunused-lambda-capture”等效警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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