clang-tools
7.0.0
llvm.src
tools
clang
tools
extra
clang-tidy
bugprone
IncorrectRoundingsCheck.h
Go to the documentation of this file.
1
//===--- IncorrectRoundingsCheck.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_BUGPRONE_INCORRECTROUNDINGSCHECK_H_
11
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INCORRECTROUNDINGSCHECK_H_
12
13
#include "../ClangTidy.h"
14
15
namespace
clang
{
16
namespace
tidy {
17
namespace
bugprone {
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.
27
class
IncorrectRoundingsCheck
:
public
ClangTidyCheck
{
28
public
:
29
IncorrectRoundingsCheck
(StringRef
Name
,
ClangTidyContext
*Context)
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 bugprone
36
}
// namespace tidy
37
}
// namespace clang
38
39
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INCORRECTROUNDINGSCHECK_H_
Name
llvm::StringRef Name
Definition:
CodeComplete.cpp:190
clang::tidy::bugprone::IncorrectRoundingsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
IncorrectRoundingsCheck.cpp:62
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
clang::tidy::bugprone::IncorrectRoundingsCheck
Checks the usage of patterns known to produce incorrect rounding.
Definition:
IncorrectRoundingsCheck.h:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ChangeNamespace.cpp:16
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:100
clang::tidy::bugprone::IncorrectRoundingsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
IncorrectRoundingsCheck.cpp:34
clang::tidy::bugprone::IncorrectRoundingsCheck::IncorrectRoundingsCheck
IncorrectRoundingsCheck(StringRef Name, ClangTidyContext *Context)
Definition:
IncorrectRoundingsCheck.h:29
Generated on Mon Sep 17 2018 14:01:19 for clang-tools by
1.8.13