clang-tools 6.0.0

FoldInitTypeCheck.h
Go to the documentation of this file.
1 //===--- FoldInitTypeCheck.h - clang-tidy------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace bugprone {
18
19 /// Find and flag invalid initializer values in folds, e.g. std::accumulate.
20 /// Example:
21 /// \code
22 /// auto v = {65536L * 65536 * 65536};
23 /// std::accumulate(begin(v), end(v), 0 /* int type is too small */);
24 /// \endcode
25 ///
26 /// For the user-facing documentation see:
27 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-fold-init-type.html
28 class FoldInitTypeCheck : public ClangTidyCheck {
29 public:
30 FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
31 : ClangTidyCheck(Name, Context) {}
32 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
33 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
34
35 private:
36 void doCheck(const BuiltinType &IterValueType, const BuiltinType &InitType,
37 const ASTContext &Context, const CallExpr &CallNode);
38 };
39
40 } // namespace bugprone
41 } // namespace tidy
42 } // namespace clang
43
44 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::bugprone::FoldInitTypeCheck
Find and flag invalid initializer values in folds, e.g.
Definition: FoldInitTypeCheck.h:28
clang::tidy::bugprone::FoldInitTypeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: FoldInitTypeCheck.cpp:20
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:118
clang::tidy::bugprone::FoldInitTypeCheck::FoldInitTypeCheck
FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
Definition: FoldInitTypeCheck.h:30
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104