Fixed #10485 (FP unusedStructMember for array size)
This commit is contained in:
parent
f363d8948b
commit
3f7093004a
|
@ -1456,13 +1456,16 @@ void CheckUnusedVar::checkStructMemberUsage()
|
|||
continue;
|
||||
|
||||
// Check if the struct member variable is used anywhere in the file
|
||||
std::string tmp(". " + var.name());
|
||||
if (Token::findsimplematch(mTokenizer->tokens(), tmp.c_str(), tmp.size()))
|
||||
bool use = false;
|
||||
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (tok->variable() != &var)
|
||||
continue;
|
||||
tmp = (":: " + var.name());
|
||||
if (Token::findsimplematch(mTokenizer->tokens(), tmp.c_str(), tmp.size()))
|
||||
continue;
|
||||
|
||||
if (tok != var.nameToken()) {
|
||||
use = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!use)
|
||||
unusedStructMemberError(var.nameToken(), scope.className, var.name(), scope.type == Scope::eUnion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ private:
|
|||
TEST_CASE(structmember14); // #6508 - (struct x){1,2,..}
|
||||
TEST_CASE(structmember15); // #3088 - #pragma pack(1)
|
||||
TEST_CASE(structmember_sizeof);
|
||||
TEST_CASE(structmember16); // #10485
|
||||
|
||||
TEST_CASE(localvar1);
|
||||
TEST_CASE(localvar2);
|
||||
|
@ -1563,6 +1564,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void structmember16() {
|
||||
checkStructMemberUsage("struct S {\n"
|
||||
" static const int N = 128;\n" // <- used
|
||||
" char E[N];\n" // <- not used
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'S::E' is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void functionVariableUsage(const char code[], const char filename[]="test.cpp") {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
|
Loading…
Reference in New Issue