* Fix #10618 FP knownConditionTrueFalse with virtual function * Remove redundant check
This commit is contained in:
parent
375880988c
commit
51c8630bb3
|
@ -870,9 +870,9 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
|
|||
// Abort recursion to avoid stack overflow
|
||||
return true;
|
||||
++depth;
|
||||
|
||||
// calling nonstatic method?
|
||||
if (Token::Match(expr->previous(), "!!:: %name% (") && expr->function() && expr->function()->nestedIn &&
|
||||
expr->function()->nestedIn->isClassOrStruct()) {
|
||||
if (Token::Match(expr, "%name% (") && expr->function() && expr->function()->nestedIn && expr->function()->nestedIn->isClassOrStruct() && !expr->function()->isStatic()) {
|
||||
// is it a method of this?
|
||||
const Scope* fScope = expr->scope();
|
||||
while (!fScope->functionOf && fScope->nestedIn)
|
||||
|
|
|
@ -4196,6 +4196,29 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Logical conjunction always evaluates to false: s.bar(1) == 0 && s.bar(1) > 0.\n",
|
||||
errout.str());
|
||||
|
||||
check("struct B {\n" // #10618
|
||||
" void Modify();\n"
|
||||
" static void Static();\n"
|
||||
" virtual void CalledByModify();\n"
|
||||
"};\n"
|
||||
"struct D : B {\n"
|
||||
" int i{};\n"
|
||||
" void testV();\n"
|
||||
" void testS();\n"
|
||||
" void CalledByModify() override { i = 0; }\n"
|
||||
"};\n"
|
||||
"void D::testV() {\n"
|
||||
" i = 1;\n"
|
||||
" B::Modify();\n"
|
||||
" if (i == 1) {}\n"
|
||||
"}\n"
|
||||
"void D::testS() {\n"
|
||||
" i = 1;\n"
|
||||
" B::Static();\n"
|
||||
" if (i == 1) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:20]: (style) Condition 'i==1' is always true\n", errout.str());
|
||||
}
|
||||
|
||||
void alwaysTrueSymbolic()
|
||||
|
|
Loading…
Reference in New Issue