From 8dbe6994a247209908d0e30cc1fe2815572774aa Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:25:31 +0200 Subject: [PATCH] Fix FP redundantPointerOp (#4058) * Fix #10991 FN: Redundant pointer operation * Fix FP redundantPointerOp * Check for LValue --- lib/checkother.cpp | 2 +- test/testother.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 16c74f5e2..a737b328a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2951,7 +2951,7 @@ void CheckOther::checkRedundantPointerOp() // variable const Token *varTok = tok->astOperand1()->astOperand1(); - if (!varTok || varTok->isExpandedMacro()) + if (!varTok || varTok->isExpandedMacro() || (!addressOfDeref && varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue)) continue; const Variable *var = varTok->variable(); diff --git a/test/testother.cpp b/test/testother.cpp index 06e13e0b2..d753c7032 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8774,6 +8774,9 @@ private: "[test.cpp:4]: (style) Redundant pointer operation on 'value' - it's already a variable.\n", errout.str()); + check("void f(int**& p) {}\n", nullptr, false, true); + ASSERT_EQUALS("", errout.str()); + // no warning for bitwise AND check("void f(const int *b) {\n" " int x = 0x20 & *b;\n"