1 //===--- ImplicitWideningOfMultiplicationResultCheck.h ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "../utils/IncludeInserter.h"
16 namespace clang::tidy::bugprone
{
18 /// Diagnoses instances of an implicit widening of multiplication result.
20 /// For the user-facing documentation see:
21 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.html
22 class ImplicitWideningOfMultiplicationResultCheck
: public ClangTidyCheck
{
23 const ast_matchers::MatchFinder::MatchResult
*Result
;
24 bool ShouldUseCXXStaticCast
;
25 bool ShouldUseCXXHeader
;
27 std::optional
<FixItHint
> includeStddefHeader(SourceLocation File
);
29 void handleImplicitCastExpr(const ImplicitCastExpr
*ICE
);
30 void handlePointerOffsetting(const Expr
*E
);
33 ImplicitWideningOfMultiplicationResultCheck(StringRef Name
,
34 ClangTidyContext
*Context
);
35 void registerPPCallbacks(const SourceManager
&SM
, Preprocessor
*PP
,
36 Preprocessor
*ModuleExpanderPP
) override
;
37 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
38 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
39 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
42 const bool UseCXXStaticCastsInCppSources
;
43 const bool UseCXXHeadersInCppSources
;
44 const bool IgnoreConstantIntExpr
;
45 utils::IncludeInserter IncludeInserter
;
48 } // namespace clang::tidy::bugprone
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H