[PATCH] D72414: Add new AST matchers `hasAnyCapture` and `capturesThis`

Reid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 14:37:50 PST 2020


rhiro marked an inline comment as done.
rhiro added a comment.

Thanks for the review!  I regenerated the docs and switched the `this` capture case to be an override of `hasAnyCapture`.



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4056
+///   matches [this](){};
+AST_MATCHER(LambdaExpr, capturesThis) {
+  for (const LambdaCapture &Capture : Node.captures()) {
----------------
aaron.ballman wrote:
> I'm a bit less certain about the utility of this matcher. I would have assumed you could do `hasAnyCapture(cxxThisExpr())` to get the same behavior, but I am guessing that won't work -- though you may be able to add an overload to `hasAnyCapture()` to make that work. I think that might be a better approach, if it works.
Thanks for that idea, it does seem a bit cleaner.

It would be nice if we could write a Matcher<LambdaCapture>, so that the macro composition could be more generically nested. e.g. hasAnyCapture that just loops over the LambdaCaptures and passes them to the child matcher.  However, when I tried this, it became apparent that it is not a Node type that can be matched on, and would require nontrivial changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72414/new/

https://reviews.llvm.org/D72414





More information about the cfe-commits mailing list