clang-tools 10.0.0

FoldInitTypeCheck.h
Go to the documentation of this file.
1 //===--- FoldInitTypeCheck.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_BUGPRONE_FOLD_INIT_TYPE_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
11
12 #include "../ClangTidyCheck.h"
13
14 namespace clang {
15 namespace tidy {
16 namespace bugprone {
17
18 /// Find and flag invalid initializer values in folds, e.g. std::accumulate.
19 /// Example:
20 /// \code
21 /// auto v = {65536L * 65536 * 65536};
22 /// std::accumulate(begin(v), end(v), 0 /* int type is too small */);
23 /// \endcode
24 ///
25 /// For the user-facing documentation see:
26 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-fold-init-type.html
27 class FoldInitTypeCheck : public ClangTidyCheck {
28 public:
29 FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
30 : ClangTidyCheck(Name, Context) {}
31 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33
34 private:
35 void doCheck(const BuiltinType &IterValueType, const BuiltinType &InitType,
36 const ASTContext &Context, const CallExpr &CallNode);
37 };
38
39 } // namespace bugprone
40 } // namespace tidy
41 } // namespace clang
42
43 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::bugprone::FoldInitTypeCheck
Find and flag invalid initializer values in folds, e.g.
Definition: FoldInitTypeCheck.h:27
clang::tidy::bugprone::FoldInitTypeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: FoldInitTypeCheck.cpp:19
clang::tidy::bugprone::FoldInitTypeCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: FoldInitTypeCheck.cpp:117
clang::tidy::bugprone::FoldInitTypeCheck::FoldInitTypeCheck
FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
Definition: FoldInitTypeCheck.h:29
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77