This is an archive of the discontinued LLVM Phabricator instance.

Add `isInitCapture` and `forEachLambdaCapture` matchers.
ClosedPublic

Authored by jcking1034 on Nov 10 2021, 9:18 AM.

Details

Summary

This contributes follow-up work from https://reviews.llvm.org/D112491, which
allows for increased control over the matching of lambda captures. This also
updates the documentation for the lambdaCapture matcher.

Diff Detail

Event Timeline

jcking1034 requested review of this revision.Nov 10 2021, 9:18 AM
jcking1034 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2021, 9:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
fowles added inline comments.Nov 10 2021, 10:27 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
4224

it would be nice to be able to do something like

int main() {
  int x, y;
  float z;
  auto f = [=, z]() { return x+ y + z; };
}

lambdaExpr(forEachLambdaCapture(isImplicit()) matches x and y but not z

Add additional unit tests.

jcking1034 marked an inline comment as done.Nov 11 2021, 10:24 AM
jcking1034 added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
4224

I believe that this should be possible, I've gone ahead and added some unit tests to demonstrate (see the tests named MatchImplicitCapturesOnly and MatchExplicitCapturesOnly).

That is awesome! Thanks for much for the examples. Everything here LGTM.

ymandel accepted this revision.Nov 12 2021, 8:26 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
4235

nice catch! i would have overlooked that detail.

This revision is now accepted and ready to land.Nov 12 2021, 8:26 AM
This revision was landed with ongoing or failed builds.Nov 15 2021, 2:55 PM
This revision was automatically updated to reflect the committed changes.