Skip to content

Commit bebf8cc

Browse files
committed
Revert da15efb and 6304a4d to fix FPs. See #7148, #7179, etc
1 parent ad17a0d commit bebf8cc

2 files changed

Lines changed: 3 additions & 69 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,32 +1248,10 @@ void CheckUnusedVar::checkStructMemberUsage()
12481248
continue;
12491249

12501250
// Check if the struct member variable is used anywhere in the file
1251-
const std::string usagePattern(". " + *memberVarName);
1252-
bool used = false;
1253-
const Token* usageTok = _tokenizer->tokens();
1254-
while ((usageTok = Token::findsimplematch(usageTok->next(), usagePattern.c_str())) != nullptr) {
1255-
// Locate the containing struct variable and ensure it's of the same type, not a random struct
1256-
const Token* structVarTok = usageTok->previous();
1257-
// Walk backwards over array accesses
1258-
while (structVarTok && structVarTok->link())
1259-
structVarTok = structVarTok->link()->previous();
1260-
if (!structVarTok)
1261-
continue;
1262-
const Variable* structVar = structVarTok->variable();
1263-
if (structVar && structVar->type() && structVar->type()->name() == structname) {
1264-
used = true;
1265-
break;
1266-
}
1267-
const Function* function = structVarTok->function();
1268-
if (function && function->retType && function->retType->name() == structname) {
1269-
used = true;
1270-
break;
1271-
}
1272-
}
1251+
if (Token::findsimplematch(_tokenizer->tokens(), (". " + *memberVarName).c_str()))
1252+
continue;
12731253

1274-
if (!used) {
1275-
unusedStructMemberError(tok->next(), structname, *memberVarName, tok->scope()->type == Scope::eUnion);
1276-
}
1254+
unusedStructMemberError(tok->next(), structname, *memberVarName, tok->scope()->type == Scope::eUnion);
12771255
}
12781256
}
12791257
}

test/testunusedvar.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -223,50 +223,6 @@ class TestUnusedVar : public TestFixture {
223223
ASSERT_EQUALS("[test.cpp:3]: (style) union member 'abc::a' is never used.\n"
224224
"[test.cpp:4]: (style) union member 'abc::b' is never used.\n"
225225
"[test.cpp:5]: (style) union member 'abc::c' is never used.\n", errout.str());
226-
227-
checkStructMemberUsage("struct A\n"
228-
"{\n"
229-
" int a;\n"
230-
"};\n"
231-
"struct B\n"
232-
"{\n"
233-
" int a;\n"
234-
"};\n"
235-
"void foo()\n"
236-
"{\n"
237-
" A a;\n"
238-
" a.a;\n"
239-
"}");
240-
ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str());
241-
242-
checkStructMemberUsage("struct A\n"
243-
"{\n"
244-
" int a;\n"
245-
"};\n"
246-
"struct B\n"
247-
"{\n"
248-
" int a;\n"
249-
"};\n"
250-
"void foo(A* a)\n"
251-
"{\n"
252-
" a->a;\n"
253-
"}");
254-
ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str());
255-
256-
checkStructMemberUsage("struct A\n"
257-
"{\n"
258-
" int a;\n"
259-
"};\n"
260-
"struct B\n"
261-
"{\n"
262-
" int a;\n"
263-
"};\n"
264-
"A& bar();\n"
265-
"void foo()\n"
266-
"{\n"
267-
" bar().a;\n"
268-
"}");
269-
ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str());
270226
}
271227

272228
void structmember2() {

0 commit comments

Comments
 (0)