1bf50a7f8SJonas Toth //===--- MultiwayPathsCoveredCheck.h - clang-tidy----------------*- C++ -*-===// 2bf50a7f8SJonas Toth // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6bf50a7f8SJonas Toth // 7bf50a7f8SJonas Toth //===----------------------------------------------------------------------===// 8bf50a7f8SJonas Toth 9bf50a7f8SJonas Toth #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H 10bf50a7f8SJonas Toth #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H 11bf50a7f8SJonas Toth 12860aefd0SNathan James #include "../ClangTidyCheck.h" 13bf50a7f8SJonas Toth 14*4718da50SCarlos Galvez namespace clang::tidy::hicpp { 15bf50a7f8SJonas Toth 16bf50a7f8SJonas Toth /// Find occasions where not all codepaths are explicitly covered in code. 17bf50a7f8SJonas Toth /// This includes 'switch' without a 'default'-branch and 'if'-'else if'-chains 18bf50a7f8SJonas Toth /// without a final 'else'-branch. 19bf50a7f8SJonas Toth /// 20bf50a7f8SJonas Toth /// For the user-facing documentation see: 21165d6933SNathan James /// http://clang.llvm.org/extra/clang-tidy/checks/hicpp/multiway-paths-covered.html 22bf50a7f8SJonas Toth class MultiwayPathsCoveredCheck : public ClangTidyCheck { 23bf50a7f8SJonas Toth public: MultiwayPathsCoveredCheck(StringRef Name,ClangTidyContext * Context)24bf50a7f8SJonas Toth MultiwayPathsCoveredCheck(StringRef Name, ClangTidyContext *Context) 25bf50a7f8SJonas Toth : ClangTidyCheck(Name, Context), 26672207c3SNathan James WarnOnMissingElse(Options.get("WarnOnMissingElse", false)) {} 27bf50a7f8SJonas Toth void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 28bf50a7f8SJonas Toth void registerMatchers(ast_matchers::MatchFinder *Finder) override; 29bf50a7f8SJonas Toth void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 30bf50a7f8SJonas Toth 31bf50a7f8SJonas Toth private: 32bf50a7f8SJonas Toth void handleSwitchWithDefault(const SwitchStmt *Switch, std::size_t CaseCount); 33bf50a7f8SJonas Toth void handleSwitchWithoutDefault( 34bf50a7f8SJonas Toth const SwitchStmt *Switch, std::size_t CaseCount, 35bf50a7f8SJonas Toth const ast_matchers::MatchFinder::MatchResult &Result); 36bf50a7f8SJonas Toth /// This option can be configured to warn on missing 'else' branches in an 37bf50a7f8SJonas Toth /// 'if-else if' chain. The default is false because this option might be 38bf50a7f8SJonas Toth /// noisy on some code bases. 39bf50a7f8SJonas Toth const bool WarnOnMissingElse; 40bf50a7f8SJonas Toth }; 41bf50a7f8SJonas Toth 42*4718da50SCarlos Galvez } // namespace clang::tidy::hicpp 43bf50a7f8SJonas Toth 44bf50a7f8SJonas Toth #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H 45