forked from OSchip/llvm-project
clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings
More specifically, clang-tidy/rename_check.py misc-incorrect-roundings \ bugprone-incorrect-roundings --check_class_name IncorrectRoundings llvm-svn: 323768
This commit is contained in:
parent
5c9c0427bb
commit
4256fd0b4b
|
@ -18,6 +18,7 @@
|
|||
#include "FoldInitTypeCheck.h"
|
||||
#include "ForwardDeclarationNamespaceCheck.h"
|
||||
#include "InaccurateEraseCheck.h"
|
||||
#include "IncorrectRoundingsCheck.h"
|
||||
#include "IntegerDivisionCheck.h"
|
||||
#include "MisplacedOperatorInStrlenInAllocCheck.h"
|
||||
#include "MoveForwardingReferenceCheck.h"
|
||||
|
@ -51,6 +52,8 @@ public:
|
|||
"bugprone-forward-declaration-namespace");
|
||||
CheckFactories.registerCheck<InaccurateEraseCheck>(
|
||||
"bugprone-inaccurate-erase");
|
||||
CheckFactories.registerCheck<IncorrectRoundingsCheck>(
|
||||
"bugprone-incorrect-roundings");
|
||||
CheckFactories.registerCheck<IntegerDivisionCheck>(
|
||||
"bugprone-integer-division");
|
||||
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
|
||||
|
|
|
@ -10,6 +10,7 @@ add_clang_library(clangTidyBugproneModule
|
|||
FoldInitTypeCheck.cpp
|
||||
ForwardDeclarationNamespaceCheck.cpp
|
||||
InaccurateEraseCheck.cpp
|
||||
IncorrectRoundingsCheck.cpp
|
||||
IntegerDivisionCheck.cpp
|
||||
MisplacedOperatorInStrlenInAllocCheck.cpp
|
||||
MoveForwardingReferenceCheck.cpp
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===--- IncorrectRoundings.cpp - clang-tidy ------------------------------===//
|
||||
//===--- IncorrectRoundingsCheck.cpp - clang-tidy ------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,7 +7,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "IncorrectRoundings.h"
|
||||
#include "IncorrectRoundingsCheck.h"
|
||||
#include "clang/AST/DeclBase.h"
|
||||
#include "clang/AST/Type.h"
|
||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||
|
@ -18,7 +18,7 @@ using namespace clang::ast_matchers;
|
|||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace bugprone {
|
||||
|
||||
namespace {
|
||||
AST_MATCHER(FloatingLiteral, floatHalf) {
|
||||
|
@ -31,7 +31,7 @@ AST_MATCHER(FloatingLiteral, floatHalf) {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
void IncorrectRoundings::registerMatchers(MatchFinder *MatchFinder) {
|
||||
void IncorrectRoundingsCheck::registerMatchers(MatchFinder *MatchFinder) {
|
||||
// Match a floating literal with value 0.5.
|
||||
auto FloatHalf = floatLiteral(floatHalf());
|
||||
|
||||
|
@ -59,13 +59,13 @@ void IncorrectRoundings::registerMatchers(MatchFinder *MatchFinder) {
|
|||
this);
|
||||
}
|
||||
|
||||
void IncorrectRoundings::check(const MatchFinder::MatchResult &Result) {
|
||||
void IncorrectRoundingsCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
const auto *CastExpr = Result.Nodes.getNodeAs<ImplicitCastExpr>("CastExpr");
|
||||
diag(CastExpr->getLocStart(),
|
||||
"casting (double + 0.5) to integer leads to incorrect rounding; "
|
||||
"consider using lround (#include <cmath>) instead");
|
||||
}
|
||||
|
||||
} // namespace misc
|
||||
} // namespace bugprone
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
|
@ -1,4 +1,4 @@
|
|||
//===--- IncorrectRoundings.h - clang-tidy ----------------------*- C++ -*-===//
|
||||
//===--- IncorrectRoundingsCheckCheck.h - clang-tidy -----------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace bugprone {
|
||||
|
||||
/// \brief Checks the usage of patterns known to produce incorrect rounding.
|
||||
/// Programmers often use
|
||||
|
@ -24,15 +24,15 @@ namespace misc {
|
|||
/// 2. It is incorrect. The number 0.499999975 (smallest representable float
|
||||
/// number below 0.5) rounds to 1.0. Even worse behavior for negative
|
||||
/// numbers where both -0.5f and -1.4f both round to 0.0.
|
||||
class IncorrectRoundings : public ClangTidyCheck {
|
||||
class IncorrectRoundingsCheck : public ClangTidyCheck {
|
||||
public:
|
||||
IncorrectRoundings(StringRef Name, ClangTidyContext *Context)
|
||||
IncorrectRoundingsCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
};
|
||||
|
||||
} // namespace misc
|
||||
} // namespace bugprone
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
|
@ -6,7 +6,6 @@ add_clang_library(clangTidyMiscModule
|
|||
MisplacedConstCheck.cpp
|
||||
UnconventionalAssignOperatorCheck.cpp
|
||||
DefinitionsInHeadersCheck.cpp
|
||||
IncorrectRoundings.cpp
|
||||
MacroParenthesesCheck.cpp
|
||||
MacroRepeatedSideEffectsCheck.cpp
|
||||
MiscTidyModule.cpp
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "../ClangTidyModuleRegistry.h"
|
||||
#include "DefinitionsInHeadersCheck.h"
|
||||
#include "ForwardingReferenceOverloadCheck.h"
|
||||
#include "IncorrectRoundings.h"
|
||||
#include "LambdaFunctionNameCheck.h"
|
||||
#include "MacroParenthesesCheck.h"
|
||||
#include "MacroRepeatedSideEffectsCheck.h"
|
||||
|
@ -56,8 +55,6 @@ public:
|
|||
"misc-unconventional-assign-operator");
|
||||
CheckFactories.registerCheck<DefinitionsInHeadersCheck>(
|
||||
"misc-definitions-in-headers");
|
||||
CheckFactories.registerCheck<IncorrectRoundings>(
|
||||
"misc-incorrect-roundings");
|
||||
CheckFactories.registerCheck<MacroParenthesesCheck>(
|
||||
"misc-macro-parentheses");
|
||||
CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
|
||||
|
|
|
@ -57,6 +57,9 @@ The improvements are...
|
|||
Improvements to clang-tidy
|
||||
--------------------------
|
||||
|
||||
- The 'misc-incorrect-roundings' check was renamed to `bugprone-incorrect-roundings
|
||||
<http://clang.llvm.org/extra/clang-tidy/checks/bugprone-incorrect-roundings.html>`_
|
||||
|
||||
- The 'misc-string-compare' check was renamed to `readability-string-compare
|
||||
<http://clang.llvm.org/extra/clang-tidy/checks/readability-string-compare.html>`_
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.. title:: clang-tidy - misc-incorrect-roundings
|
||||
.. title:: clang-tidy - bugprone-incorrect-roundings
|
||||
|
||||
misc-incorrect-roundings
|
||||
========================
|
||||
bugprone-incorrect-roundings
|
||||
============================
|
||||
|
||||
Checks the usage of patterns known to produce incorrect rounding.
|
||||
Programmers often use::
|
|
@ -25,6 +25,7 @@ Clang-Tidy Checks
|
|||
bugprone-fold-init-type
|
||||
bugprone-forward-declaration-namespace
|
||||
bugprone-inaccurate-erase
|
||||
bugprone-incorrect-roundings
|
||||
bugprone-integer-division
|
||||
bugprone-misplaced-operator-in-strlen-in-alloc
|
||||
bugprone-move-forwarding-reference
|
||||
|
@ -126,7 +127,6 @@ Clang-Tidy Checks
|
|||
llvm-twine-local
|
||||
misc-definitions-in-headers
|
||||
misc-forwarding-reference-overload
|
||||
misc-incorrect-roundings
|
||||
misc-lambda-function-name
|
||||
misc-macro-parentheses
|
||||
misc-macro-repeated-side-effects
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %check_clang_tidy %s misc-incorrect-roundings %t
|
||||
// RUN: %check_clang_tidy %s bugprone-incorrect-roundings %t
|
||||
|
||||
void b(int x) {}
|
||||
|
||||
|
@ -9,7 +9,7 @@ void f1() {
|
|||
int x;
|
||||
|
||||
x = (d + 0.5);
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include <cmath>) instead [misc-incorrect-roundings]
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include <cmath>) instead [bugprone-incorrect-roundings]
|
||||
x = (d + 0.5f);
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
|
||||
x = (f + 0.5);
|
Loading…
Reference in New Issue