1b06b248aSChris Cotter //===--- AvoidReferenceCoroutineParametersCheck.cpp - clang-tidy ----------===// 2b06b248aSChris Cotter // 3b06b248aSChris Cotter // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b06b248aSChris Cotter // See https://llvm.org/LICENSE.txt for license information. 5b06b248aSChris Cotter // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b06b248aSChris Cotter // 7b06b248aSChris Cotter //===----------------------------------------------------------------------===// 8b06b248aSChris Cotter 9b06b248aSChris Cotter #include "AvoidReferenceCoroutineParametersCheck.h" 10b06b248aSChris Cotter #include "clang/AST/ASTContext.h" 11b06b248aSChris Cotter #include "clang/ASTMatchers/ASTMatchFinder.h" 12b06b248aSChris Cotter 13b06b248aSChris Cotter using namespace clang::ast_matchers; 14b06b248aSChris Cotter 157d2ea6c4SCarlos Galvez namespace clang::tidy::cppcoreguidelines { 16b06b248aSChris Cotter registerMatchers(MatchFinder * Finder)17b06b248aSChris Cottervoid AvoidReferenceCoroutineParametersCheck::registerMatchers( 18b06b248aSChris Cotter MatchFinder *Finder) { 19*0e2c5cdaSPiotr Zegar Finder->addMatcher( 20*0e2c5cdaSPiotr Zegar functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt())) 21*0e2c5cdaSPiotr Zegar .bind("fnt"), 22b06b248aSChris Cotter this); 23b06b248aSChris Cotter } 24b06b248aSChris Cotter check(const MatchFinder::MatchResult & Result)25b06b248aSChris Cottervoid AvoidReferenceCoroutineParametersCheck::check( 26b06b248aSChris Cotter const MatchFinder::MatchResult &Result) { 27*0e2c5cdaSPiotr Zegar const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("fnt"); 28*0e2c5cdaSPiotr Zegar for (const ParmVarDecl *Param : Function->parameters()) { 29*0e2c5cdaSPiotr Zegar if (!Param->getType().getCanonicalType()->isReferenceType()) 30*0e2c5cdaSPiotr Zegar continue; 31*0e2c5cdaSPiotr Zegar 32b06b248aSChris Cotter diag(Param->getBeginLoc(), "coroutine parameters should not be references"); 33b06b248aSChris Cotter } 34b06b248aSChris Cotter } 35b06b248aSChris Cotter 367d2ea6c4SCarlos Galvez } // namespace clang::tidy::cppcoreguidelines 37