clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
fuchsia
TrailingReturnCheck.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
9
#include "
TrailingReturnCheck.h
"
10
#include "clang/ASTMatchers/ASTMatchFinder.h"
11
#include "clang/ASTMatchers/ASTMatchersInternal.h"
12
13
using namespace
clang::ast_matchers
;
14
15
namespace
clang::tidy::fuchsia
{
16
17
void
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
functionDecl(hasTrailingReturn(),
23
unless(anyOf(returns(decltypeType()),
24
hasParent(cxxRecordDecl(isLambda())),
25
cxxDeductionGuideDecl())))
26
.bind(
"decl"
),
27
this
);
28
}
29
30
void
TrailingReturnCheck::check
(
const
MatchFinder::MatchResult &Result) {
31
if
(
const
auto
*D = Result.Nodes.getNodeAs<FunctionDecl>(
"decl"
))
32
diag(D->getBeginLoc(),
33
"a trailing return type is disallowed for this function declaration"
);
34
}
35
36
}
// namespace clang::tidy::fuchsia
TrailingReturnCheck.h
clang::tidy::fuchsia::TrailingReturnCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
TrailingReturnCheck.cpp:30
clang::tidy::fuchsia::TrailingReturnCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
TrailingReturnCheck.cpp:17
clang::ast_matchers
Definition
AbseilMatcher.h:13
clang::tidy::fuchsia
Definition
DefaultArgumentsCallsCheck.cpp:13
Generated on
for clang-tools by
1.14.0