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:
FoldInitTypeCheck(StringRef Name,ClangTidyContext * Context)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
44