This code:
void foo(int);
int main() {
const int i = 0;
auto l = [i](){foo(i);};
}
(godbolt)
Will issue a compiler error when compiled by clang with
-std=c++17 -Werror -Wunused-lambda-capture
The error message is error: lambda capture 'i' is not required to be captured for this use.
The error is correct: i could be implicitly captured here, explicitly capturing it is not necessary. However, a) the warning is poorly named, since i is used but the warning is for unused lambda captures, and b) I would just not like this to be an error. I want to error for actually unused lambda captures, but not error for used explicitly captured variables that could have been implicitly captured.
Is there a clang setting that does this? Or do I have to squelch the error using pragma diagnostic push/pop?