Skip to content

Unused lambda capture source ranges are slightly off #106445

@tbaederr

Description

@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]() {
      |          ^
  1. The source range for &a includes the comma after it
  2. The source range for &b includes both the comma and the whitespace between that and the capture

The second point is especially fun when inserting some useless whitespace:

    auto F = [&a,         
    
     &b]() {

    };

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyquality-of-implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions