From bebf8ccdd53a436e4bd6b69f7213f386af20f62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 16 Dec 2015 14:51:50 +0100 Subject: [PATCH] Revert da15efb3 and 6304a4dd to fix FPs. See #7148, #7179, etc --- lib/checkunusedvar.cpp | 28 +++------------------------ test/testunusedvar.cpp | 44 ------------------------------------------ 2 files changed, 3 insertions(+), 69 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index adc057ae7..57af9c37c 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1248,32 +1248,10 @@ void CheckUnusedVar::checkStructMemberUsage() continue; // Check if the struct member variable is used anywhere in the file - const std::string usagePattern(". " + *memberVarName); - bool used = false; - const Token* usageTok = _tokenizer->tokens(); - while ((usageTok = Token::findsimplematch(usageTok->next(), usagePattern.c_str())) != nullptr) { - // Locate the containing struct variable and ensure it's of the same type, not a random struct - const Token* structVarTok = usageTok->previous(); - // Walk backwards over array accesses - while (structVarTok && structVarTok->link()) - structVarTok = structVarTok->link()->previous(); - if (!structVarTok) - continue; - const Variable* structVar = structVarTok->variable(); - if (structVar && structVar->type() && structVar->type()->name() == structname) { - used = true; - break; - } - const Function* function = structVarTok->function(); - if (function && function->retType && function->retType->name() == structname) { - used = true; - break; - } - } + if (Token::findsimplematch(_tokenizer->tokens(), (". " + *memberVarName).c_str())) + continue; - if (!used) { - unusedStructMemberError(tok->next(), structname, *memberVarName, tok->scope()->type == Scope::eUnion); - } + unusedStructMemberError(tok->next(), structname, *memberVarName, tok->scope()->type == Scope::eUnion); } } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f20de37b0..258ac0b9e 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -223,50 +223,6 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) union member 'abc::a' is never used.\n" "[test.cpp:4]: (style) union member 'abc::b' is never used.\n" "[test.cpp:5]: (style) union member 'abc::c' is never used.\n", errout.str()); - - checkStructMemberUsage("struct A\n" - "{\n" - " int a;\n" - "};\n" - "struct B\n" - "{\n" - " int a;\n" - "};\n" - "void foo()\n" - "{\n" - " A a;\n" - " a.a;\n" - "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str()); - - checkStructMemberUsage("struct A\n" - "{\n" - " int a;\n" - "};\n" - "struct B\n" - "{\n" - " int a;\n" - "};\n" - "void foo(A* a)\n" - "{\n" - " a->a;\n" - "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str()); - - checkStructMemberUsage("struct A\n" - "{\n" - " int a;\n" - "};\n" - "struct B\n" - "{\n" - " int a;\n" - "};\n" - "A& bar();\n" - "void foo()\n" - "{\n" - " bar().a;\n" - "}"); - ASSERT_EQUALS("[test.cpp:7]: (style) struct member 'B::a' is never used.\n", errout.str()); } void structmember2() {