clang-tools 22.0.0git
AvoidReferenceCoroutineParametersCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12using namespace clang::ast_matchers;
13
15
17 MatchFinder *Finder) {
18 Finder->addMatcher(
19 functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt()))
20 .bind("fnt"),
21 this);
22}
23
25 const MatchFinder::MatchResult &Result) {
26 const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("fnt");
27 for (const ParmVarDecl *Param : Function->parameters()) {
28 if (!Param->getType().getCanonicalType()->isReferenceType())
29 continue;
30
31 diag(Param->getBeginLoc(), "coroutine parameters should not be references");
32 }
33}
34
35} // namespace clang::tidy::cppcoreguidelines
void check(const ast_matchers::MatchFinder::MatchResult &Result) override