Is there a `clang++:-Wunused-lambda-capture` equivalent warning in/being developed for GCC?

旧城冷巷雨未停 提交于 2021-01-05 07:58:46

问题


Background

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]{}();
}

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.

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

Question(s)

  • Is there indeed currently no equivalent for GCC?
  • If not, is that a feature that is currently planned to be implemented / currently being implemented?

回答1:


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?

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.



来源:https://stackoverflow.com/questions/51616378/is-there-a-clang-wunused-lambda-capture-equivalent-warning-in-being-develop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!