clang-tools  4.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
32 public:
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
const std::string Name
Definition: USRFinder.cpp:164
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:262
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Find casts of calculation results to bigger type.
std::map< std::string, std::string > OptionMap
MisplacedWideningCastCheck(StringRef Name, ClangTidyContext *Context)
ClangTidyContext & Context
Definition: ClangTidy.cpp:87
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
const NamedDecl * Result
Definition: USRFinder.cpp:162