[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
[llvm-project.git] / clang-tools-extra / clang-tidy / readability / ElseAfterReturnCheck.h
blob34860c2853ea8bedabea2a54bb6f1acd2bd3200e
1 //===--- ElseAfterReturnCheck.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "llvm/ADT/DenseMap.h"
15 namespace clang::tidy::readability {
17 /// Flags the usages of `else` after `return`.
18 ///
19 /// http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
20 class ElseAfterReturnCheck : public ClangTidyCheck {
21 public:
22 ElseAfterReturnCheck(StringRef Name, ClangTidyContext *Context);
24 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
25 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
26 Preprocessor *ModuleExpanderPP) override;
27 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29 std::optional<TraversalKind> getCheckTraversalKind() const override {
30 return TK_IgnoreUnlessSpelledInSource;
33 using ConditionalBranchMap =
34 llvm::DenseMap<FileID, SmallVector<SourceRange, 1>>;
36 private:
37 const bool WarnOnUnfixable;
38 const bool WarnOnConditionVariables;
39 ConditionalBranchMap PPConditionals;
42 } // namespace clang::tidy::readability
44 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H