clang-tools  7.0.0svn
IncorrectRoundings.h
Go to the documentation of this file.
1 //===--- IncorrectRoundings.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_INCORRECTROUNDINGS_H_
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCORRECTROUNDINGS_H_
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace misc {
18 
19 /// \brief Checks the usage of patterns known to produce incorrect rounding.
20 /// Programmers often use
21 /// (int)(double_expression + 0.5)
22 /// to round the double expression to an integer. The problem with this
23 /// 1. It is unnecessarily slow.
24 /// 2. It is incorrect. The number 0.499999975 (smallest representable float
25 /// number below 0.5) rounds to 1.0. Even worse behavior for negative
26 /// numbers where both -0.5f and -1.4f both round to 0.0.
28 public:
30  : ClangTidyCheck(Name, Context) {}
31  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33 };
34 
35 } // namespace misc
36 } // namespace tidy
37 } // namespace clang
38 
39 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCORRECTROUNDINGS_H_
StringHandle Name
IncorrectRoundings(StringRef Name, ClangTidyContext *Context)
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
Checks the usage of patterns known to produce incorrect rounding.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.