Revert da15efb3 and 6304a4dd to fix FPs. See #7148, #7179, etc

This commit is contained in:
Daniel Marjamäki 2015-12-16 14:51:50 +01:00
parent ad17a0d721
commit bebf8ccdd5
2 changed files with 3 additions and 69 deletions

View File

@ -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);
}
}
}

View File

@ -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() {