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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "llvm/ADT/DenseMap.h"
14
15namespace clang::tidy::readability {
16
17/// Flags the usages of `else` after `return`.
18///
19/// http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
20class ElseAfterReturnCheck : public ClangTidyCheck {
21public:
22 ElseAfterReturnCheck(StringRef Name, ClangTidyContext *Context);
23
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;
31 }
32
33 using ConditionalBranchMap =
34 llvm::DenseMap<FileID, SmallVector<SourceRange, 1>>;
35
36private:
37 const bool WarnOnUnfixable;
38 const bool WarnOnConditionVariables;
39 ConditionalBranchMap PPConditionals;
40};
41
42} // namespace clang::tidy::readability
43
44#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ELSEAFTERRETURNCHECK_H
45

source code of clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h