Skip to content

Commit e7afb30

Browse files
Fix FP redundantPointerOp with macro (#4061)
* Fix #10991 FN: Redundant pointer operation * Fix FP redundantPointerOp * Check for LValue * Fix FP redundantPointerOp with macro * Format
1 parent 0467ab1 commit e7afb30

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,9 +2951,16 @@ void CheckOther::checkRedundantPointerOp()
29512951

29522952
// variable
29532953
const Token *varTok = tok->astOperand1()->astOperand1();
2954-
if (!varTok || varTok->isExpandedMacro() || (!addressOfDeref && varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue))
2954+
if (!varTok || varTok->isExpandedMacro())
29552955
continue;
29562956

2957+
if (!addressOfDeref) { // dereference of address
2958+
if (tok->isExpandedMacro())
2959+
continue;
2960+
if (varTok->valueType() && varTok->valueType()->pointer && varTok->valueType()->reference == Reference::LValue)
2961+
continue;
2962+
}
2963+
29572964
const Variable *var = varTok->variable();
29582965
if (!var || (addressOfDeref && !var->isPointer()))
29592966
continue;

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8777,6 +8777,12 @@ class TestOther : public TestFixture {
87778777
check("void f(int**& p) {}\n", nullptr, false, true);
87788778
ASSERT_EQUALS("", errout.str());
87798779

8780+
checkP("#define RESTORE(ORIG, COPY) { *ORIG = *COPY; }\n"
8781+
"void f(int* p, int i) {\n"
8782+
" RESTORE(p, &i);\n"
8783+
"}\n");
8784+
ASSERT_EQUALS("", errout.str());
8785+
87808786
// no warning for bitwise AND
87818787
check("void f(const int *b) {\n"
87828788
" int x = 0x20 & *b;\n"

0 commit comments

Comments
 (0)