clang-tools 6.0.0

MisplacedWideningCastCheck.h
Go to the documentation of this file.
1 //===--- MisplacedWideningCastCheck.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_MISC_MISPLACED_WIDENING_CAST_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_WIDENING_CAST_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace misc {
18
19 /// Find casts of calculation results to bigger type. Typically from int to
20 /// long. If the intention of the cast is to avoid loss of precision then
21 /// the cast is misplaced, and there can be loss of precision. Otherwise
22 /// such cast is ineffective.
23 ///
24 /// There is one option:
25 ///
26 /// - `CheckImplicitCasts`: Whether to check implicit casts as well which may
27 // be the most common case. Enabled by default.
28 ///
29 /// For the user-facing documentation see:
30 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-misplaced-widening-cast.html
31 class MisplacedWideningCastCheck : public ClangTidyCheck {
32 public:
33 MisplacedWideningCastCheck(StringRef Name, ClangTidyContext *Context);
34 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37
38 private:
39 const bool CheckImplicitCasts;
40 };
41
42 } // namespace misc
43 } // namespace tidy
44 } // namespace clang
45
46 #endif
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::misc::MisplacedWideningCastCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: MisplacedWideningCastCheck.cpp:31
clang::tidy::misc::MisplacedWideningCastCheck
Find casts of calculation results to bigger type.
Definition: MisplacedWideningCastCheck.h:31
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang::tidy::misc::MisplacedWideningCastCheck::MisplacedWideningCastCheck
MisplacedWideningCastCheck(StringRef Name, ClangTidyContext *Context)
Definition: MisplacedWideningCastCheck.cpp:21
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104
clang::tidy::misc::MisplacedWideningCastCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: MisplacedWideningCastCheck.cpp:184
clang::tidy::misc::MisplacedWideningCastCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: MisplacedWideningCastCheck.cpp:26