Fix #11478 FP identicalConditionAfterEarlyExit when passing *this (#4684)

This commit is contained in:
chrchr-github 2023-01-07 22:10:07 +01:00 committed by GitHub
parent 6020feb271
commit 4ebdf5fae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -790,7 +790,7 @@ void CheckCondition::multiCondition2()
if (!function || !function->isConst())
break;
}
if (Token::Match(tok->previous(), "[(,] %name% [,)]") && isParameterChanged(tok))
if (Token::Match(tok->previous(), "[(,] *|& %name% [,)]") && isParameterChanged(tok))
break;
}
}

View File

@ -2887,6 +2887,23 @@ private:
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11478
check("struct S {\n"
" void run();\n"
" bool b = false;\n"
" const std::function<void(S&)> f;\n"
"};\n"
"void S::run() {\n"
" while (true) {\n"
" if (b)\n"
" return;\n"
" f(*this);\n"
" if (b)\n"
" return;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void innerConditionModified() {