skip nested anonymous unions when searching for variables in symbol database

This commit is contained in:
Robert Reif 2011-03-27 18:37:31 -04:00
parent 57056bcf61
commit 31f8ff723b
2 changed files with 38 additions and 0 deletions

View File

@ -1447,6 +1447,11 @@ void Scope::getVariableList()
else else
break; break;
} }
else if (Token::Match(tok, "union {") && Token::Match(tok->next()->link(), "} %var% ;"))
{
tok = tok->next()->link()->next()->next();
continue;
}
// Borland C++: Skip all variables in the __published section. // Borland C++: Skip all variables in the __published section.
// These are automatically initialized. // These are automatically initialized.

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(initvar_2constructors); // BUG 2270353 TEST_CASE(initvar_2constructors); // BUG 2270353
TEST_CASE(initvar_constvar); TEST_CASE(initvar_constvar);
TEST_CASE(initvar_staticvar); TEST_CASE(initvar_staticvar);
TEST_CASE(initvar_union);
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
TEST_CASE(initvar_copy_constructor); // ticket #1611 TEST_CASE(initvar_copy_constructor); // ticket #1611
@ -795,6 +796,38 @@ private:
} }
void initvar_union()
{
check("class Fred\n"
"{\n"
" union\n"
" {\n"
" int a;\n"
" char b[4];\n"
" } U;\n"
"public:\n"
" Fred()\n"
" {\n"
" U.a = 0;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("class Fred\n"
"{\n"
" union\n"
" {\n"
" int a;\n"
" char b[4];\n"
" } U;\n"
"public:\n"
" Fred()\n"
" {\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialised in the constructor.\n", errout.str());
}
void initvar_private_constructor() void initvar_private_constructor()
{ {