revert 027e5cc8. the div() standard function should not be reimplemented. create a different fix. Ticket: #4929

This commit is contained in:
Daniel Marjamäki 2013-09-23 18:01:15 +02:00
parent 698e9e2b59
commit 17c0bb3cab
2 changed files with 16 additions and 21 deletions

View File

@ -2142,9 +2142,9 @@ void CheckOther::checkZeroDivision()
MathLib::isInt(tok->next()->str()) && MathLib::isInt(tok->next()->str()) &&
MathLib::toLongNumber(tok->next()->str()) == 0L) { MathLib::toLongNumber(tok->next()->str()) == 0L) {
zerodivError(tok); zerodivError(tok);
} else if (Token::Match(tok, "std :: div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && } else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
MathLib::isInt(tok->strAt(6)) && MathLib::isInt(tok->strAt(4)) &&
MathLib::toLongNumber(tok->strAt(6)) == 0L) { MathLib::toLongNumber(tok->strAt(4)) == 0L) {
zerodivError(tok); zerodivError(tok);
} }
} }

View File

@ -336,26 +336,9 @@ private:
void zeroDiv3() { void zeroDiv3() {
check("void f()\n" check("void f()\n"
"{\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()); 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() { void zeroDiv4() {
@ -383,6 +366,18 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); 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) // Don't warn about floating points (gcc doesn't warn either)
// and floating points are handled differently than integers. // and floating points are handled differently than integers.
check("void f()\n" check("void f()\n"