Fixed #8938 (FP identicalInnerCondition)

This commit is contained in:
Daniel Marjamäki 2019-04-22 16:54:59 +02:00
parent 751902da86
commit 0edf0b5628
2 changed files with 22 additions and 10 deletions

View File

@ -685,6 +685,9 @@ void CheckCondition::multiCondition2()
} }
} }
} }
if (Token::Match(tok, "%name% ("))
// TODO: This is a bailout to avoid fp
break;
if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings->library)) // non const function call -> bailout if there are nonlocal variables if (Token::Match(tok, "%type% (") && nonlocal && isNonConstFunctionCall(tok, mSettings->library)) // non const function call -> bailout if there are nonlocal variables
break; break;
if (Token::Match(tok, "case|break|continue|return|throw") && tok->scope() == endToken->scope()) if (Token::Match(tok, "case|break|continue|return|throw") && tok->scope() == endToken->scope())

View File

@ -1570,7 +1570,7 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
check("void foo(const int &i);\n" check("void foo(const int &i);\n"
"void bar(int i) {\n" "void bar(int i) {\n"
@ -1580,7 +1580,7 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
check("void foo(int i);\n" check("void foo(int i);\n"
"void bar() {\n" "void bar() {\n"
@ -1591,7 +1591,7 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method
"void foo(C c, int i) {\n" "void foo(C c, int i) {\n"
@ -1614,7 +1614,7 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
// #5874 - array // #5874 - array
@ -1661,6 +1661,15 @@ private:
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str());
// #8938
check("void Delete(SS_CELLCOORD upperleft) {\n"
" if ((upperleft.Col == -1) && (upperleft.Row == -1)) {\n"
" GetActiveCell(&(upperleft.Col), &(upperleft.Row));\n"
" if (upperleft.Row == -1) {}\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void oppositeInnerConditionPointers() { void oppositeInnerConditionPointers() {
@ -1707,7 +1716,7 @@ private:
" if (!fred.isValid()) {}\n" " if (!fred.isValid()) {}\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
check("class Fred { public: bool isValid() const; void dostuff() const; };\n" check("class Fred { public: bool isValid() const; void dostuff() const; };\n"
"void f() {\n" "void f() {\n"
@ -1717,7 +1726,7 @@ private:
" if (!fred.isValid()) {}\n" " if (!fred.isValid()) {}\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", "", errout.str());
check("void f() {\n" check("void f() {\n"
" Fred fred;\n" " Fred fred;\n"
@ -2231,14 +2240,14 @@ private:
" if (abc) {}\n" " if (abc) {}\n"
" if (x > 100) {}\n" " if (x > 100) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", "", errout.str());
check("void f(int x) {\n" check("void f(int x) {\n"
" if (x > 100) { return; }\n" " if (x > 100) { return; }\n"
" while (abc) { y = x; }\n" " while (abc) { y = x; }\n"
" if (x > 100) {}\n" " if (x > 100) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", "", errout.str());
check("void f(int x) {\n" // #8217 - crash for incomplete code check("void f(int x) {\n" // #8217 - crash for incomplete code
" if (x > 100) { return; }\n" " if (x > 100) { return; }\n"
@ -2253,7 +2262,7 @@ private:
" if (!num1tok) { *num1 = *num2; }\n" " if (!num1tok) { *num1 = *num2; }\n"
" if (!i) {}\n" " if (!i) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition '!i', second condition is always false\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition '!i', second condition is always false\n", "", errout.str());
check("void C::f(Tree &coreTree) {\n" // daca check("void C::f(Tree &coreTree) {\n" // daca
" if(!coreTree.build())\n" " if(!coreTree.build())\n"
@ -2270,7 +2279,7 @@ private:
" coreTree.dostuff();\n" " coreTree.dostuff();\n"
" if(!coreTree.build()) {}\n" " if(!coreTree.build()) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Identical condition '!coreTree.build()', second condition is always false\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Identical condition '!coreTree.build()', second condition is always false\n", "", errout.str());
check("void f(int x) {\n" // daca: labplot check("void f(int x) {\n" // daca: labplot
" switch(type) {\n" " switch(type) {\n"