[PATCH] D158665: [clang-tidy] Improve cppcoreguidelines-avoid-reference-coroutine-parameters check

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 21:44:48 PDT 2023


PiotrZSL added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp:20
+  Finder->addMatcher(
+      functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt()))
+          .bind("fnt"),
----------------
ccotter wrote:
> Can we do this by matching if any parameter is of reference type, rather than relying on the logic living in `check` (I wrote this originally, although perhaps this would be an improvement). Happy to take this up as a followup...
Matching functionDecl first is cheaper...
In theory using `hasParent` instead of `hasAncestor` should be sufficient, but I never trusted that relation.

Something like this should do a trick also:

```
functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt()), forEach(parmVarDecl(hasType(qualType(hasCanonicalType(	references(qualType()))))).bind("param"))
```

should also work, but I didn't test it.
Current code will do a same thing, not using matchers should even make it faster, and `check` method is called only for coroutines.

Personally I just prefer matcher to match nodes that we got less.
This also enable other thing, like providing 1 warning per coroutine and additional notes for every parameter with parameter name in it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158665



More information about the cfe-commits mailing list