diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a737b328a..7c542dc53 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2951,9 +2951,16 @@ void CheckOther::checkRedundantPointerOp() // variable const Token *varTok = tok->astOperand1()->astOperand1(); - if (!varTok || varTok->isExpandedMacro() || (!addressOfDeref && varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue)) + if (!varTok || varTok->isExpandedMacro()) continue; + if (!addressOfDeref) { // dereference of address + if (tok->isExpandedMacro()) + continue; + if (varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue) + continue; + } + const Variable *var = varTok->variable(); if (!var || (addressOfDeref && !var->isPointer())) continue; diff --git a/test/testother.cpp b/test/testother.cpp index d753c7032..541a2b6f0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8777,6 +8777,12 @@ private: check("void f(int**& p) {}\n", nullptr, false, true); ASSERT_EQUALS("", errout.str()); + checkP("#define RESTORE(ORIG, COPY) { *ORIG = *COPY; }\n" + "void f(int* p, int i) {\n" + " RESTORE(p, &i);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // no warning for bitwise AND check("void f(const int *b) {\n" " int x = 0x20 & *b;\n"