functionVariableUsage: support for nested struct/union declaration.
This commit is contained in:
parent
e664f255a4
commit
1a14cd527c
|
@ -874,11 +874,20 @@ void CheckOther::functionVariableUsage()
|
||||||
else if (Token::Match(tok, "struct|union|class {") ||
|
else if (Token::Match(tok, "struct|union|class {") ||
|
||||||
Token::Match(tok, "struct|union|class %type% {"))
|
Token::Match(tok, "struct|union|class %type% {"))
|
||||||
{
|
{
|
||||||
while (tok && tok->str() != "}")
|
int indentlevel0 = indentlevel;
|
||||||
|
|
||||||
|
while (tok->str() != "{")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (tok)
|
|
||||||
continue;
|
do
|
||||||
break;
|
{
|
||||||
|
if (tok->str() == "{")
|
||||||
|
indentlevel++;
|
||||||
|
else if (tok->str() == "}")
|
||||||
|
indentlevel--;
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
while (tok && indentlevel > indentlevel0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "[;{}] bool|char|short|int|long|float|double %var% ;|="))
|
if (Token::Match(tok, "[;{}] bool|char|short|int|long|float|double %var% ;|="))
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
// Don't give false positives for variables in structs/unions
|
// Don't give false positives for variables in structs/unions
|
||||||
TEST_CASE(localvarStruct1);
|
TEST_CASE(localvarStruct1);
|
||||||
TEST_CASE(localvarStruct2);
|
TEST_CASE(localvarStruct2);
|
||||||
|
TEST_CASE(localvarStruct3);
|
||||||
|
|
||||||
TEST_CASE(localvarOp); // Usage with arithmetic operators
|
TEST_CASE(localvarOp); // Usage with arithmetic operators
|
||||||
TEST_CASE(localvarInvert); // Usage with inverted variable
|
TEST_CASE(localvarInvert); // Usage with inverted variable
|
||||||
|
@ -259,6 +260,19 @@ private:
|
||||||
ASSERT_EQUALS(std::string(""), errout.str());
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarStruct3()
|
||||||
|
{
|
||||||
|
functionVariableUsage("void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int a = 10;\n"
|
||||||
|
" union { struct { unsigned char x; }; unsigned char z; };\n"
|
||||||
|
" do {\n"
|
||||||
|
" func();\n"
|
||||||
|
" } while(a--);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void localvarOp()
|
void localvarOp()
|
||||||
|
|
Loading…
Reference in New Issue