Fix FP redundantPointerOp with macro (#4061)
* Fix #10991 FN: Redundant pointer operation * Fix FP redundantPointerOp * Check for LValue * Fix FP redundantPointerOp with macro * Format
This commit is contained in:
parent
0467ab1339
commit
e7afb3045b
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue