From 17c0bb3cab8954f2cdcaf49b8c67763a4688c2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 Sep 2013 18:01:15 +0200 Subject: [PATCH] revert 027e5cc8. the div() standard function should not be reimplemented. create a different fix. Ticket: #4929 --- lib/checkother.cpp | 6 +++--- test/testother.cpp | 31 +++++++++++++------------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 58ca6362c..cd6862a0c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2142,9 +2142,9 @@ void CheckOther::checkZeroDivision() MathLib::isInt(tok->next()->str()) && MathLib::toLongNumber(tok->next()->str()) == 0L) { zerodivError(tok); - } else if (Token::Match(tok, "std :: div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && - MathLib::isInt(tok->strAt(6)) && - MathLib::toLongNumber(tok->strAt(6)) == 0L) { + } else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && + MathLib::isInt(tok->strAt(4)) && + MathLib::toLongNumber(tok->strAt(4)) == 0L) { zerodivError(tok); } } diff --git a/test/testother.cpp b/test/testother.cpp index 8512ffd52..0a82c6567 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -336,26 +336,9 @@ private: void zeroDiv3() { check("void f()\n" "{\n" - " div_t divresult = std::div (1,0);\n" + " div_t divresult = div (1,0);\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); - - check("void f()\n" - "{\n" - " div_t divresult = std::div (1,0L);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); - - check("void f()\n" - "{\n" - " div_t divresult = std::div (1,0x5);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f() {\n" // #4929 - we don't know if this "div" is the standard function - " div (1,0);\n" - "}"); - ASSERT_EQUALS("", errout.str()); } void zeroDiv4() { @@ -383,6 +366,18 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); + check("void f()\n" + "{\n" + " div_t divresult = div (1,0L);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); + + check("void f()\n" + "{\n" + " div_t divresult = div (1,0x5);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // Don't warn about floating points (gcc doesn't warn either) // and floating points are handled differently than integers. check("void f()\n"