struct member usage: bail out the check if the struct contain any functions
This commit is contained in:
parent
2e77f3bf04
commit
da46e4bd96
|
@ -647,15 +647,31 @@ void CheckOther::CheckConstantFunctionParameter()
|
|||
void CheckOther::CheckStructMemberUsage()
|
||||
{
|
||||
const char *structname = 0;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
{
|
||||
if (tok->fileIndex() != 0)
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "struct|union %type% {"))
|
||||
{
|
||||
structname = tok->strAt(1);
|
||||
|
||||
// Bail out if struct/union contain any functions
|
||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "(")
|
||||
{
|
||||
structname = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok2->str() == "}")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tok->str() == "}")
|
||||
structname = 0;
|
||||
if (Token::Match(tok, "struct|union %type% {"))
|
||||
structname = tok->strAt(1);
|
||||
|
||||
if (structname && Token::Match(tok, "[{;]"))
|
||||
{
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
TEST_CASE(structmember2);
|
||||
TEST_CASE(structmember3);
|
||||
TEST_CASE(structmember4);
|
||||
TEST_CASE(structmember5);
|
||||
|
||||
TEST_CASE(localvar1);
|
||||
TEST_CASE(localvar2);
|
||||
|
@ -144,6 +145,28 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void structmember5()
|
||||
{
|
||||
check("struct AB\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
" void reset()\n"
|
||||
" {\n"
|
||||
" a = 1;\n"
|
||||
" b = 2;\n"
|
||||
" }\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" struct AB ab;\n"
|
||||
" ab.reset();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue