Skip to content

AST Matcher varDecl() in lambda bug #141493

Open
@segoon

Description

@segoon

In test program:

  int Mov{};
  auto Lambda = [=]() mutable {
    Mov = 1;
  };
  Lambda();
}

AST matcher declRefExpr(to(varDecl().bind("decl"))).bind("expr") matches:

Match #2:

/home/segoon/projects/llvm-project/build/../clang-tools-extra/test/clang-tidy/checkers/performance/lambda.cpp:2:3: note: "decl" binds here
    2 |   int Mov{};
      |   ^~~~~~~~~
/home/segoon/projects/llvm-project/build/../clang-tools-extra/test/clang-tidy/checkers/performance/lambda.cpp:4:5: note: "expr" binds here
    4 |     Mov = 1;
      |   

I would expect varDecl of Mov inside of lambda to be equal to lambda's catched parameter, not the outer variable that was the source of catched parameter. If it is expected varDecl() behaviour (IOW, it's not a bug), then how can I catch lambda's Mov field?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions