diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7e3f56a7d..49362ce4d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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 diff --git a/test/testother.cpp b/test/testother.cpp index e5c13ae29..d1d2c33b1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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