* Fix #11679 FP knownArgument with known return value * Add test for #11051
This commit is contained in:
parent
5b4c95f229
commit
2b92351b49
|
@ -1498,6 +1498,8 @@ void CheckCondition::alwaysTrueFalse()
|
|||
continue;
|
||||
if (Token::simpleMatch(tok, ":"))
|
||||
continue;
|
||||
if (Token::Match(tok->astOperand1(), "%name% (") && Token::simpleMatch(tok->astParent(), "return"))
|
||||
continue;
|
||||
if (tok->isComparisonOp() && isWithoutSideEffects(mTokenizer->isCPP(), tok->astOperand1()) &&
|
||||
isSameExpression(mTokenizer->isCPP(),
|
||||
true,
|
||||
|
|
|
@ -3597,6 +3597,8 @@ void CheckOther::checkKnownArgument()
|
|||
continue;
|
||||
if (isConstVarExpression(tok))
|
||||
continue;
|
||||
if (Token::Match(tok->astOperand1(), "%name% ("))
|
||||
continue;
|
||||
const Token * tok2 = tok;
|
||||
if (isCPPCast(tok2))
|
||||
tok2 = tok2->astOperand2();
|
||||
|
|
|
@ -4504,6 +4504,20 @@ private:
|
|||
" if (j == 1) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void h(int);\n" // #11679
|
||||
"bool g(int a) { h(a); return false; }\n"
|
||||
"bool f(int i) {\n"
|
||||
" return g(i);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(std::string a) {\n" // #11051
|
||||
" a = \"x\";\n"
|
||||
" if (a == \"x\") {}\n"
|
||||
" return a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'a==\"x\"' is always true\n", errout.str());
|
||||
}
|
||||
|
||||
void alwaysTrueSymbolic()
|
||||
|
|
|
@ -10696,6 +10696,15 @@ private:
|
|||
" dostuff(self->maxsize * sizeof(intptr_t));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #11679
|
||||
check("bool g(int);\n"
|
||||
"void h(int);\n"
|
||||
"int k(int a) { h(a); return 0; }\n"
|
||||
"void f(int i) {\n"
|
||||
" if (g(k(i))) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void knownArgumentHiddenVariableExpression() {
|
||||
|
|
Loading…
Reference in New Issue