-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unused lambda capture source ranges are slightly off #106445
Comments
@llvm/issue-subscribers-clang-frontend Author: Timm Baeder (tbaederr)
See: https://godbolt.org/z/MKjzsYb9b
int main() {
int a = 0, b = 0;
auto F = [&a, &b]() {
};
} The output is: <source>:7:16: warning: lambda capture 'a' is not used [-Wunused-lambda-capture]
7 | auto F = [&a, &b]() {
| ~^~
<source>:7:20: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
7 | auto F = [&a, &b]() {
| ~~~^
<source>:7:10: warning: unused variable 'F' [-Wunused-variable]
7 | auto F = [&a, &b]() {
| ^
The second point is especially fun when inserting some useless whitespace: auto F = [&a,
&b]() {
}; |
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@llvm/issue-subscribers-good-first-issue Author: Timm Baeder (tbaederr)
See: https://godbolt.org/z/MKjzsYb9b
int main() {
int a = 0, b = 0;
auto F = [&a, &b]() {
};
} The output is: <source>:7:16: warning: lambda capture 'a' is not used [-Wunused-lambda-capture]
7 | auto F = [&a, &b]() {
| ~^~
<source>:7:20: warning: lambda capture 'b' is not used [-Wunused-lambda-capture]
7 | auto F = [&a, &b]() {
| ~~~^
<source>:7:10: warning: unused variable 'F' [-Wunused-variable]
7 | auto F = [&a, &b]() {
| ^
The second point is especially fun when inserting some useless whitespace: auto F = [&a,
&b]() {
}; |
Note the source range for |
Hi, I would like to work on this. |
I believe the issue was introduced in 832f49b. Interpreting the source range as the fix-it range rather than the diagnostic range actually makes some kind of sense. |
So I’m wondering if this is the intended behavior. If we want to fix it, where should the changes be made? From the perspective of the fix-it suggestion, the comma still needs to be bound to a variable, either the former or the latter. |
Right, those aren't just ranges, but delete ranges from the fixme. In that case, I'm not sure what to do. 🙃 |
For https://godbolt.org/z/8zdKPxY6K int main() {
int a = 0, b = 0;
auto F = [&a, &b]() {
};
} The output is:
So, I assume the third warning output should be:
Because this matches the behavior for a lambda with a single unsued capture?
|
Kinda, yes. But the output is already correct as it is, when we consider that the source ranges aren't supposed to just highlight the unused parameter. They are fix-it hints that will remove the underlined text when applied. |
Hi, can this ticket be assigned to me? |
See: https://godbolt.org/z/MKjzsYb9b
The output is:
&a
includes the comma after it&b
includes both the comma and the whitespace between that and the captureThe second point is especially fun when inserting some useless whitespace:
auto F = [&a, &b]() { };
The text was updated successfully, but these errors were encountered: