clang-tools 20.0.0git
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
14namespace clang::tidy::bugprone {
15
16/// Find and flag invalid initializer values in folds, e.g. std::accumulate.
17/// Example:
18/// \code
19/// auto v = {65536L * 65536 * 65536};
20/// std::accumulate(begin(v), end(v), 0 /* int type is too small */);
21/// \endcode
22///
23/// For the user-facing documentation see:
24/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/fold-init-type.html
26public:
28 : ClangTidyCheck(Name, Context) {}
29 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31
32private:
33 void doCheck(const BuiltinType &IterValueType, const BuiltinType &InitType,
34 const ASTContext &Context, const CallExpr &CallNode);
35};
36
37} // namespace clang::tidy::bugprone
38
39#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Find and flag invalid initializer values in folds, e.g.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.