clang-tools 20.0.0git
UseTrailingReturnTypeCheck.h
Go to the documentation of this file.
1//===--- UseTrailingReturnTypeCheck.h - clang-tidy---------------*- C++ -*-===//
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#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "clang/Lex/Token.h"
14#include <optional>
15
16namespace clang::tidy::modernize {
17
19 Token T;
22};
23
24/// Rewrites function signatures to use a trailing return type.
25///
26/// For the user-facing documentation see:
27/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-trailing-return-type.html
29public:
31 : ClangTidyCheck(Name, Context) {}
32 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33 return LangOpts.CPlusPlus11;
34 }
35 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
37 Preprocessor *ModuleExpanderPP) override;
38 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
39
40private:
41 Preprocessor *PP = nullptr;
42
43 SourceLocation findTrailingReturnTypeSourceLocation(
44 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
45 const SourceManager &SM, const LangOptions &LangOpts);
46 std::optional<SmallVector<ClassifiedToken, 8>>
47 classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
48 const SourceManager &SM,
49 const LangOptions &LangOpts);
50 SourceRange findReturnTypeAndCVSourceRange(const FunctionDecl &F,
51 const TypeLoc &ReturnLoc,
52 const ASTContext &Ctx,
53 const SourceManager &SM,
54 const LangOptions &LangOpts);
55 void keepSpecifiers(std::string &ReturnType, std::string &Auto,
56 SourceRange ReturnTypeCVRange, const FunctionDecl &F,
57 const FriendDecl *Fr, const ASTContext &Ctx,
58 const SourceManager &SM, const LangOptions &LangOpts);
59};
60
61} // namespace clang::tidy::modernize
62
63#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRAILINGRETURNTYPECHECK_H
llvm::SmallString< 256U > Name
std::string ReturnType
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Rewrites function signatures to use a trailing return type.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.