clang-tools 22.0.0git
InconsistentIfElseBracesCheck.h
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
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTIFELSEBRACESCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTIFELSEBRACESCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "clang/AST/ASTTypeTraits.h"
14#include <optional>
15
17
18/// Detects `if`/`else` statements where one branch uses braces and the other
19/// does not.
20///
21/// For the user-facing documentation see:
22/// https://clang.llvm.org/extra/clang-tidy/checks/readability/inconsistent-ifelse-braces.html
24public:
26 : ClangTidyCheck(Name, Context) {}
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
33private:
34 void checkIfStmt(const ast_matchers::MatchFinder::MatchResult &Result,
35 const IfStmt *If);
36 void emitDiagnostic(const ast_matchers::MatchFinder::MatchResult &Result,
37 const Stmt *S, SourceLocation StartLoc,
38 SourceLocation EndLocHint = {});
39};
40
41} // namespace clang::tidy::readability
42
43#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTIFELSEBRACESCHECK_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
InconsistentIfElseBracesCheck(StringRef Name, ClangTidyContext *Context)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override
std::optional< TraversalKind > getCheckTraversalKind() const override