File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2674,10 +2674,10 @@ void CheckOther::checkRedundantPointerOp()
26742674 return ;
26752675
26762676 for (const Token *tok = mTokenizer ->tokens (); tok; tok = tok->next ()) {
2677- if (! tok->isUnaryOp ( " & " ) || ! tok->astOperand1 ()-> isUnaryOp ( " * " ) )
2678- continue ;
2677+ if (tok->isExpandedMacro () && tok->str () == " ( " )
2678+ tok = tok-> link () ;
26792679
2680- if (tok->isExpandedMacro ( ))
2680+ if (! tok->isUnaryOp ( " & " ) || !tok-> astOperand1 ()-> isUnaryOp ( " * " ))
26812681 continue ;
26822682
26832683 // variable
Original file line number Diff line number Diff line change @@ -8179,12 +8179,18 @@ class TestOther : public TestFixture {
81798179 ASSERT_EQUALS (" [test.cpp:2]: (style) Redundant pointer operation on 'ptr' - it's already a pointer.\n " , errout.str ());
81808180
81818181 // no warning for macros
8182- check (" #define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n "
8183- " void f(struct mutex *mut) {\n "
8184- " MUTEX_LOCK(*mut);\n "
8185- " }\n " , nullptr , false , true );
8182+ checkP (" #define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n "
8183+ " void f(struct mutex *mut) {\n "
8184+ " MUTEX_LOCK(*mut);\n "
8185+ " }\n " );
81868186 ASSERT_EQUALS (" " , errout.str ());
81878187
8188+ checkP (" #define B(op) bar(op)\n "
8189+ " #define C(orf) B(&orf)\n "
8190+ " void foo(const int * pkey) {\n "
8191+ " C(*pkey);\n "
8192+ " }\n " );
8193+ ASSERT_EQUALS (" " , errout.str ());
81888194 }
81898195
81908196 void test_isSameExpression () { // see #5738
You can’t perform that action at this time.
0 commit comments