[PATCH] D158665: [clang-tidy] Improve cppcoreguidelines-avoid-reference-coroutine-parameters check
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 24 14:49:55 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e2c5cda3cc7: [clang-tidy] Improve cppcoreguidelines-avoid-reference-coroutine-parameters… (authored by PiotrZSL).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158665/new/
https://reviews.llvm.org/D158665
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-avoid-reference-coroutine-parameters %t
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-avoid-reference-coroutine-parameters %t --
// NOLINTBEGIN
namespace std {
@@ -82,3 +82,18 @@
auto WithReferences2 = [](int&) -> Coro { co_return; };
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
}
+
+void coroInFunctionWithReference(int&) {
+ auto SampleCoro = [](int x) -> Coro { co_return; };
+}
+
+Coro lambdaWithReferenceInCoro() {
+ auto SampleLambda = [](int& x) {};
+ co_return;
+}
+
+using MyIntegerRef = int&;
+Coro coroWithReferenceBehindTypedef(MyIntegerRef ref) {
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+ co_return;
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,12 @@
to ignore ``static`` variables declared within the scope of
``class``/``struct``.
+- Improved :doc:`cppcoreguidelines-avoid-reference-coroutine-parameters
+ <clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters>`
+ check to ignore false positives related to matching parameters of non
+ coroutine functions and increase issue detection for cases involving type
+ aliases with references.
+
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
ignore delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
@@ -16,17 +16,19 @@
void AvoidReferenceCoroutineParametersCheck::registerMatchers(
MatchFinder *Finder) {
- auto IsCoroMatcher =
- hasDescendant(expr(anyOf(coyieldExpr(), coreturnStmt(), coawaitExpr())));
- Finder->addMatcher(parmVarDecl(hasType(type(referenceType())),
- hasAncestor(functionDecl(IsCoroMatcher)))
- .bind("param"),
- this);
+ Finder->addMatcher(
+ functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt()))
+ .bind("fnt"),
+ this);
}
void AvoidReferenceCoroutineParametersCheck::check(
const MatchFinder::MatchResult &Result) {
- if (const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("param")) {
+ const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("fnt");
+ for (const ParmVarDecl *Param : Function->parameters()) {
+ if (!Param->getType().getCanonicalType()->isReferenceType())
+ continue;
+
diag(Param->getBeginLoc(), "coroutine parameters should not be references");
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158665.553272.patch
Type: text/x-patch
Size: 3552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/d257977b/attachment.bin>
More information about the cfe-commits
mailing list