Redundant pointer op; Fixed false positives when macro is used

This commit is contained in:
Daniel Marjamäki 2021-05-22 14:18:29 +02:00
parent 9a9f14bd8a
commit 87554bed7a
2 changed files with 13 additions and 7 deletions

View File

@ -2674,10 +2674,10 @@ void CheckOther::checkRedundantPointerOp()
return;
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (!tok->isUnaryOp("&") || !tok->astOperand1()->isUnaryOp("*"))
continue;
if (tok->isExpandedMacro() && tok->str() == "(")
tok = tok->link();
if (tok->isExpandedMacro())
if (!tok->isUnaryOp("&") || !tok->astOperand1()->isUnaryOp("*"))
continue;
// variable

View File

@ -8179,12 +8179,18 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'ptr' - it's already a pointer.\n", errout.str());
// no warning for macros
check("#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n"
"void f(struct mutex *mut) {\n"
" MUTEX_LOCK(*mut);\n"
"}\n", nullptr, false, true);
checkP("#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n"
"void f(struct mutex *mut) {\n"
" MUTEX_LOCK(*mut);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkP("#define B(op) bar(op)\n"
"#define C(orf) B(&orf)\n"
"void foo(const int * pkey) {\n"
" C(*pkey);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void test_isSameExpression() { // see #5738