1//===--- AvoidReferenceCoroutineParametersCheck.cpp - clang-tidy ----------===//
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
9#include "AvoidReferenceCoroutineParametersCheck.h"
10#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12using namespace clang::ast_matchers;
13
14namespace clang::tidy::cppcoreguidelines {
15
16void AvoidReferenceCoroutineParametersCheck::registerMatchers(
17 MatchFinder *Finder) {
18 Finder->addMatcher(
19 NodeMatch: functionDecl(unless(parameterCountIs(N: 0)), hasBody(InnerMatcher: coroutineBodyStmt()))
20 .bind(ID: "fnt"),
21 Action: this);
22}
23
24void AvoidReferenceCoroutineParametersCheck::check(
25 const MatchFinder::MatchResult &Result) {
26 const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>(ID: "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
36

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp