Fixed #2279 ((style) struct of union member is never used)

This commit is contained in:
Daniel Marjamäki 2010-12-05 18:33:53 +01:00
parent ac60a41a7e
commit b25e6ff24c
2 changed files with 15 additions and 0 deletions

View File

@ -2121,6 +2121,11 @@ void CheckOther::checkStructMemberUsage()
{ {
// Declaring struct variable.. // Declaring struct variable..
std::string varname; std::string varname;
// declaring a POD variable?
if (!tok->next()->isStandardType())
continue;
if (Token::Match(tok->next(), "%type% %var% [;[]")) if (Token::Match(tok->next(), "%type% %var% [;[]"))
varname = tok->strAt(2); varname = tok->strAt(2);
else if (Token::Match(tok->next(), "%type% %type% %var% [;[]")) else if (Token::Match(tok->next(), "%type% %type% %var% [;[]"))

View File

@ -46,6 +46,7 @@ private:
TEST_CASE(structmember8); TEST_CASE(structmember8);
TEST_CASE(structmember9); // #2017 - struct is inherited TEST_CASE(structmember9); // #2017 - struct is inherited
TEST_CASE(structmember_extern); // No false positives for extern structs TEST_CASE(structmember_extern); // No false positives for extern structs
TEST_CASE(structmember10);
TEST_CASE(localvar1); TEST_CASE(localvar1);
TEST_CASE(localvar2); TEST_CASE(localvar2);
@ -297,6 +298,15 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void structmember10()
{
// Fred may have some useful side-effects
checkStructMemberUsage("struct abc {\n"
" Fred fred;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void structmember_extern() void structmember_extern()
{ {
// extern struct => no false positive // extern struct => no false positive