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?