brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 7ef1e2b Raw
36 lines · cpp
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-exception6//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      functionDecl(unless(parameterCountIs(0)), hasBody(coroutineBodyStmt()))20          .bind("fnt"),21      this);22}23 24void AvoidReferenceCoroutineParametersCheck::check(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::cppcoreguidelines36