Fixed #1976 (False Positives with unions)

This commit is contained in:
Daniel Marjamäki 2010-09-03 08:10:29 +02:00
parent fb4fce466e
commit 1938b8a423
2 changed files with 19 additions and 0 deletions

View File

@ -7996,10 +7996,21 @@ void Tokenizer::simplifyStructDecl()
{
unsigned int count = 0;
// Skip simplification of unions in class definition
std::list<bool> skip;
skip.push_back(false);
for (Token *tok = _tokens; tok; tok = tok->next())
{
Token *restart;
if (tok->str() == "{")
skip.push_back(!Token::Match(tok->previous(), "const|)"));
else if (tok->str() == "}" && !skip.empty())
skip.pop_back();
else if (!skip.empty() && skip.back() && tok->str() == "union")
continue;
// check for named struct/union
if (Token::Match(tok, "struct|union %type% :|{"))
{

View File

@ -213,6 +213,7 @@ private:
TEST_CASE(vardecl12);
TEST_CASE(vardecl_stl);
TEST_CASE(vardecl_template);
TEST_CASE(vardecl_union);
TEST_CASE(volatile_variables);
TEST_CASE(syntax_error);
TEST_CASE(syntax_error_templates);
@ -3536,6 +3537,13 @@ private:
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
}
void vardecl_union()
{
// ticket #1976
const char code1[] = "class Fred { public: union { int a ; int b ; } ; } ;";
ASSERT_EQUALS(code1, tokenizeAndStringify(code1));
}
void vardec_static()
{
{