Struct member usage : Check union member variables at the same time

This commit is contained in:
Daniel Marjamäki 2009-01-04 15:05:00 +00:00
parent 0f4dd5ea7b
commit 53cd729ccc
2 changed files with 5 additions and 5 deletions

View File

@ -620,7 +620,7 @@ void CheckOther::CheckStructMemberUsage()
continue;
if ( tok->str() == "}" )
structname = 0;
if ( Token::Match(tok, "struct %type% {") )
if ( Token::Match(tok, "struct|union %type% {") )
structname = tok->strAt( 1);
if (structname && Token::Match(tok, "[{;]"))
@ -651,7 +651,7 @@ void CheckOther::CheckStructMemberUsage()
if ( ! used )
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next()) << ": struct member '" << structname << "::" << varname << "' is never used";
errmsg << _tokenizer->fileLine(tok->next()) << ": struct or union member '" << structname << "::" << varname << "' is never used";
_errorLogger->reportErr(errmsg.str());
}
}

View File

@ -73,9 +73,9 @@ private:
" int b;\n"
" int c;\n"
"};\n" );
ASSERT_EQUALS( std::string("[test.cpp:3]: struct member 'abc::a' is never used\n"
"[test.cpp:4]: struct member 'abc::b' is never used\n"
"[test.cpp:5]: struct member 'abc::c' is never used\n"), errout.str() );
ASSERT_EQUALS( std::string("[test.cpp:3]: struct or union member 'abc::a' is never used\n"
"[test.cpp:4]: struct or union member 'abc::b' is never used\n"
"[test.cpp:5]: struct or union member 'abc::c' is never used\n"), errout.str() );
}
void structmember2()