fix 2 problems related to ticket 1976:

1. nested unnamed anonymous structures and unions were not supported.
 2. declaration split up in class had bug if proceeded by access specifier.
This commit is contained in:
Robert Reif 2010-08-25 20:17:31 +02:00 committed by Daniel Marjamäki
parent 4d6b7bea2e
commit 4a6070d2af
4 changed files with 32 additions and 7 deletions

View File

@ -4725,13 +4725,13 @@ void Tokenizer::simplifyVarDecl()
break;
}
if (tok->previous() && !Token::Match(tok->previous(), "[{};)]"))
if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|)|public:|protected:|private:"))
continue;
Token *type0 = tok;
if (!Token::Match(type0, "%type%"))
continue;
if (Token::Match(type0, "else|return"))
if (Token::Match(type0, "else|return|public:|protected:|private:"))
continue;
bool isconst = false;
@ -7793,6 +7793,8 @@ void Tokenizer::simplifyStructDecl()
for (Token *tok = _tokens; tok; tok = tok->next())
{
Token *restart;
// check for named struct/union
if (Token::Match(tok, "struct|union %type% :|{"))
{
@ -7803,6 +7805,7 @@ void Tokenizer::simplifyStructDecl()
next = next->next();
tok = next->link();
restart = next;
// check for named type
if (Token::Match(tok->next(), "*|&| %type% ,|;|["))
@ -7812,7 +7815,7 @@ void Tokenizer::simplifyStructDecl()
tok->insertToken(type->str().c_str());
}
tok = next;
tok = restart;
}
// check for anonymous struct/union
@ -7820,6 +7823,7 @@ void Tokenizer::simplifyStructDecl()
{
Token *tok1 = tok;
restart = tok->next();
tok = tok->next()->link();
// check for named type
@ -7847,14 +7851,21 @@ void Tokenizer::simplifyStructDecl()
}
else
tok1->deleteThis();
restart = tok1->previous();
tok->deleteThis();
if (tok->next())
tok->deleteThis();
if (!tok->next())
return;
}
tok = tok1->next();
if (!restart)
{
simplifyStructDecl();
return;
}
else if (!restart->next())
return;
tok = restart;
}
}
}

View File

@ -5723,6 +5723,12 @@ private:
const char expected[] = ";";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct { struct { struct { } ; } ; };";
const char expected[] = ";";
ASSERT_EQUALS(expected, tok(code, false));
}
}
void removeUnwantedKeywords()

View File

@ -205,6 +205,7 @@ private:
TEST_CASE(vardecl9);
TEST_CASE(vardecl10);
TEST_CASE(vardecl11);
TEST_CASE(vardecl12);
TEST_CASE(vardecl_stl);
TEST_CASE(vardecl_template);
TEST_CASE(volatile_variables);
@ -3557,6 +3558,12 @@ private:
ASSERT_EQUALS("char a [ 5 ] [ 8 ] ; char b [ 5 ] [ 8 ] ;", tokenizeAndStringify(code));
}
void vardecl12()
{
const char code[] = "struct A { public: B a, b, c, d; };";
ASSERT_EQUALS("struct A { public: B a ; B b ; B c ; B d ; } ;", tokenizeAndStringify(code));
}
void volatile_variables()
{
const char code[] = "volatile int a=0;\n"

View File

@ -2175,7 +2175,8 @@ private:
" func();\n"
" } while(a--);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: z\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: x\n"
"[test.cpp:4]: (style) Unused variable: z\n", errout.str());
}
void localvarStruct4()