1 //===--- AvoidReferenceCoroutineParametersCheck.cpp - clang-tidy ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "AvoidReferenceCoroutineParametersCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers
;
15 namespace clang::tidy::cppcoreguidelines
{
17 void AvoidReferenceCoroutineParametersCheck::registerMatchers(
18 MatchFinder
*Finder
) {
20 hasDescendant(expr(anyOf(coyieldExpr(), coreturnStmt(), coawaitExpr())));
21 Finder
->addMatcher(parmVarDecl(hasType(type(referenceType())),
22 hasAncestor(functionDecl(IsCoroMatcher
)))
27 void AvoidReferenceCoroutineParametersCheck::check(
28 const MatchFinder::MatchResult
&Result
) {
29 if (const auto *Param
= Result
.Nodes
.getNodeAs
<ParmVarDecl
>("param")) {
30 diag(Param
->getBeginLoc(), "coroutine parameters should not be references");
34 } // namespace clang::tidy::cppcoreguidelines