clang-tools 22.0.0git
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
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 functionDecl(hasTrailingReturn(),
23 unless(anyOf(returns(decltypeType()),
24 hasParent(cxxRecordDecl(isLambda())),
25 cxxDeductionGuideDecl())))
26 .bind("decl"),
27 this);
28}
29
30void 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
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override