1//===--- TrailingReturnCheck.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 "TrailingReturnCheck.h"
10#include "clang/ASTMatchers/ASTMatchFinder.h"
11#include "clang/ASTMatchers/ASTMatchersInternal.h"
12
13using namespace clang::ast_matchers;
14
15namespace clang::tidy::fuchsia {
16
17void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
18 // Functions that have trailing returns are disallowed, except for those
19 // using decltype specifiers and lambda with otherwise unutterable
20 // return types.
21 Finder->addMatcher(
22 NodeMatch: functionDecl(hasTrailingReturn(),
23 unless(anyOf(returns(InnerMatcher: decltypeType()),
24 hasParent(cxxRecordDecl(isLambda())),
25 cxxDeductionGuideDecl())))
26 .bind(ID: "decl"),
27 Action: this);
28}
29
30void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) {
31 if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>(ID: "decl"))
32 diag(D->getBeginLoc(),
33 "a trailing return type is disallowed for this function declaration");
34}
35
36} // namespace clang::tidy::fuchsia
37

Provided by KDAB

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

source code of clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp