[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / clang-tidy / fuchsia / TrailingReturnCheck.cpp
blob2902e34fe860f2baf0288a18f2dae82a9b845e8c
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 //===----------------------------------------------------------------------===//
9 #include "TrailingReturnCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/ASTMatchers/ASTMatchersInternal.h"
14 using namespace clang::ast_matchers;
16 namespace clang {
17 namespace tidy {
18 namespace fuchsia {
20 void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
21 // Functions that have trailing returns are disallowed, except for those
22 // using decltype specifiers and lambda with otherwise unutterable
23 // return types.
24 Finder->addMatcher(
25 functionDecl(hasTrailingReturn(),
26 unless(anyOf(returns(decltypeType()),
27 hasParent(cxxRecordDecl(isLambda())),
28 cxxDeductionGuideDecl())))
29 .bind("decl"),
30 this);
33 void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) {
34 if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"))
35 diag(D->getBeginLoc(),
36 "a trailing return type is disallowed for this function declaration");
39 } // namespace fuchsia
40 } // namespace tidy
41 } // namespace clang