Handle anonymous structs (which can appear inside unions) like anonymous unions (#2039)

This commit is contained in:
PKEuS 2015-08-30 15:41:32 +02:00
parent 3bae4ae429
commit f12f16cb4a
2 changed files with 25 additions and 2 deletions

View File

@ -2647,8 +2647,8 @@ void Tokenizer::setVarId()
scopeStack.push(scopeStackEntryType(isExecutable, _varId));
}
} else if (tok->str() == "}") {
// parse anonymous unions as part of the current scope
if (!(Token::simpleMatch(tok, "} ;") && tok->link() && Token::simpleMatch(tok->link()->previous(), "union {")) &&
// parse anonymous unions/structs as part of the current scope
if (!(Token::simpleMatch(tok, "} ;") && tok->link() && Token::Match(tok->link()->previous(), "union|struct {")) &&
!(initlist && Token::Match(tok, "} ,|{") && Token::Match(tok->link()->previous(), "%name%|>|>> {"))) {
// Set variable ids in class declaration..
if (!initlist && !isC() && !scopeStack.top().isExecutable && tok->link()) {

View File

@ -1545,6 +1545,29 @@ private:
"3: union { float a@1 ; int b@2 ; } ;\n"
"4: } ;\n",
tokenize(code2));
const char code3[] = "void f() {\n"
" union {\n"
" struct {\n"
" char a, b, c, d;\n"
" };\n"
" int abcd;\n"
" };\n"
" g(abcd);\n"
" h(a, b, c, d);\n"
"}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: void f ( ) {\n"
"2: union {\n"
"3: struct {\n"
"4: char a@1 ; char b@2 ; char c@3 ; char d@4 ;\n"
"5: } ;\n"
"6: int abcd@5 ;\n"
"7: } ;\n"
"8: g ( abcd@5 ) ;\n"
"9: h ( a@1 , b@2 , c@3 , d@4 ) ;\n"
"10: }\n",
tokenize(code3));
}
void varid_in_class12() { // #4637 - method