clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
FoldInitTypeCheck.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_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::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
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/fold-init-type.html
25
class
FoldInitTypeCheck
:
public
ClangTidyCheck
{
26
public
:
27
FoldInitTypeCheck
(StringRef Name,
ClangTidyContext
*Context)
28
:
ClangTidyCheck
(Name, Context) {}
29
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
30
return
LangOpts.CPlusPlus;
31
}
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 clang::tidy::bugprone
41
42
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
ClangTidyCheck.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::bugprone::FoldInitTypeCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Definition
FoldInitTypeCheck.h:29
clang::tidy::bugprone::FoldInitTypeCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
FoldInitTypeCheck.cpp:130
clang::tidy::bugprone::FoldInitTypeCheck::FoldInitTypeCheck
FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
Definition
FoldInitTypeCheck.h:27
clang::tidy::bugprone::FoldInitTypeCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
FoldInitTypeCheck.cpp:17
clang::tidy::bugprone
Definition
ArgumentCommentCheck.cpp:19
Generated on
for clang-tools by
1.14.0