[clang-tools-extra] r323768 - clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 07:12:24 PST 2018


Author: alexfh
Date: Tue Jan 30 07:12:24 2018
New Revision: 323768

URL: http://llvm.org/viewvc/llvm-project?rev=323768&view=rev
Log:
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

Added:
    clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
      - copied, changed from r323766, clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
    clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h
      - copied, changed from r323766, clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h
    clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst
      - copied, changed from r323766, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst
    clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp
      - copied, changed from r323766, clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp
Removed:
    clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
    clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h
    clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst
    clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
    clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
    clang-tools-extra/trunk/docs/ReleaseNotes.rst
    clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Tue Jan 30 07:12:24 2018
@@ -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>(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Tue Jan 30 07:12:24 2018
@@ -10,6 +10,7 @@ add_clang_library(clangTidyBugproneModul
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   InaccurateEraseCheck.cpp
+  IncorrectRoundingsCheck.cpp
   IntegerDivisionCheck.cpp
   MisplacedOperatorInStrlenInAllocCheck.cpp
   MoveForwardingReferenceCheck.cpp

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp (from r323766, clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp&r1=323766&r2=323768&rev=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp Tue Jan 30 07:12:24 2018
@@ -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::registerMatcher
       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

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h (from r323766, clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h?p2=clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h&r1=323766&r2=323768&rev=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h Tue Jan 30 07:12:24 2018
@@ -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
 

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Jan 30 07:12:24 2018
@@ -6,7 +6,6 @@ add_clang_library(clangTidyMiscModule
   MisplacedConstCheck.cpp
   UnconventionalAssignOperatorCheck.cpp
   DefinitionsInHeadersCheck.cpp
-  IncorrectRoundings.cpp
   MacroParenthesesCheck.cpp
   MacroRepeatedSideEffectsCheck.cpp
   MiscTidyModule.cpp

Removed: clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp?rev=323767&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (removed)
@@ -1,71 +0,0 @@
-//===--- IncorrectRoundings.cpp - clang-tidy ------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "IncorrectRoundings.h"
-#include "clang/AST/DeclBase.h"
-#include "clang/AST/Type.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Lex/Lexer.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-namespace {
-AST_MATCHER(FloatingLiteral, floatHalf) {
-  const auto &literal = Node.getValue();
-  if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
-    return literal.convertToFloat() == 0.5f;
-  if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
-    return literal.convertToDouble() == 0.5;
-  return false;
-}
-} // namespace
-
-void IncorrectRoundings::registerMatchers(MatchFinder *MatchFinder) {
-  // Match a floating literal with value 0.5.
-  auto FloatHalf = floatLiteral(floatHalf());
-
-  // Match a floating point expression.
-  auto FloatType = expr(hasType(realFloatingPointType()));
-
-  // Match a floating literal of 0.5 or a floating literal of 0.5 implicitly.
-  // cast to floating type.
-  auto FloatOrCastHalf =
-      anyOf(FloatHalf,
-            implicitCastExpr(FloatType, has(ignoringParenImpCasts(FloatHalf))));
-
-  // Match if either the LHS or RHS is a floating literal of 0.5 or a floating
-  // literal of 0.5 and the other is of type double or vice versa.
-  auto OneSideHalf = anyOf(allOf(hasLHS(FloatOrCastHalf), hasRHS(FloatType)),
-                           allOf(hasRHS(FloatOrCastHalf), hasLHS(FloatType)));
-
-  // Find expressions of cast to int of the sum of a floating point expression
-  // and 0.5.
-  MatchFinder->addMatcher(
-      implicitCastExpr(
-          hasImplicitDestinationType(isInteger()),
-          ignoringParenCasts(binaryOperator(hasOperatorName("+"), OneSideHalf)))
-          .bind("CastExpr"),
-      this);
-}
-
-void IncorrectRoundings::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 tidy
-} // namespace clang

Removed: clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h?rev=323767&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h (removed)
@@ -1,39 +0,0 @@
-//===--- IncorrectRoundings.h - clang-tidy ----------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCORRECTROUNDINGS_H_
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCORRECTROUNDINGS_H_
-
-#include "../ClangTidy.h"
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-/// \brief Checks the usage of patterns known to produce incorrect rounding.
-/// Programmers often use
-///   (int)(double_expression + 0.5)
-/// to round the double expression to an integer. The problem with this
-///  1. It is unnecessarily slow.
-///  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 {
-public:
-  IncorrectRoundings(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 tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCORRECTROUNDINGS_H_

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Tue Jan 30 07:12:24 2018
@@ -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>(

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Jan 30 07:12:24 2018
@@ -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>`_
 

Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst (from r323766, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst&r1=323766&r2=323768&rev=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst Tue Jan 30 07:12:24 2018
@@ -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::

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=323768&r1=323767&r2=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Tue Jan 30 07:12:24 2018
@@ -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

Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst?rev=323767&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst (removed)
@@ -1,16 +0,0 @@
-.. title:: clang-tidy - misc-incorrect-roundings
-
-misc-incorrect-roundings
-========================
-
-Checks the usage of patterns known to produce incorrect rounding.
-Programmers often use::
-
-   (int)(double_expression + 0.5)
-
-to round the double expression to an integer. The problem with this:
-
-1. It is unnecessarily slow.
-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.

Copied: clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp (from r323766, clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp&r1=323766&r2=323768&rev=323768&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp Tue Jan 30 07:12:24 2018
@@ -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);

Removed: clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp?rev=323767&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp (removed)
@@ -1,86 +0,0 @@
-// RUN: %check_clang_tidy %s misc-incorrect-roundings %t
-
-void b(int x) {}
-
-void f1() {
-  float f;
-  double d;
-  long double ld;
-  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]
-  x = (d + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (f + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (f + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5 + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5f + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5 + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5f + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5 + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (0.5f + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
-  x = (int)(d + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(d + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(ld + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(ld + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(f + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(f + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5 + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5f + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5 + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5f + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5 + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = (int)(0.5f + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
-  x = static_cast<int>(d + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(d + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(ld + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(ld + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(f + 0.5);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(f + 0.5f);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5 + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5f + d);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5 + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5f + ld);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5 + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-  x = static_cast<int>(0.5f + f);
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
-
-  // Don't warn if constant is not 0.5.
-  x = (int)(d + 0.6);
-  x = (int)(0.6 + d);
-
-  // Don't warn if binary operator is not directly beneath cast.
-  x = (int)(1 + (0.5 + f));
-}




More information about the cfe-commits mailing list