fix missing pop in Tokenizer::simplifyStructDecl() when anonymous struct/union removed

This commit is contained in:
Robert Reif 2011-07-03 08:14:51 -04:00
parent b32b2c6d87
commit 8ec1dfacbf
2 changed files with 33 additions and 0 deletions

View File

@ -9434,6 +9434,7 @@ void Tokenizer::simplifyStructDecl()
// don't remove unnamed anonymous unions from a class, struct or union
if (!(tok1->str() == "union" && !inFunction))
{
skip.pop_back();
tok1->deleteThis();
if (tok1->next() == tok)
{

View File

@ -336,6 +336,7 @@ private:
TEST_CASE(simplifyStructDecl1);
TEST_CASE(simplifyStructDecl2); // ticket #2579
TEST_CASE(simplifyStructDecl3);
TEST_CASE(simplifyStructDecl4);
// register int var; => int var;
// inline int foo() {} => int foo() {}
@ -7055,6 +7056,37 @@ private:
}
}
void simplifyStructDecl4()
{
{
const char code[] = "class ABC {\n"
" void foo() {\n"
" union {\n"
" int i;\n"
" float f;\n"
" };\n"
" struct Fee { } fee;\n"
" }\n"
" union {\n"
" long long ll;\n"
" double d;\n"
" };\n"
"} abc;\n";
const char expected[] = "class ABC { "
"void foo ( ) { "
"int i ; "
"float & f = i ; "
"struct Fee { } ; Fee fee ; "
"} "
"union { "
"long long ll ; "
"double d ; "
"} ; "
"} ; ABC abc ;";
ASSERT_EQUALS(expected, tok(code, false));
}
}
void removeUnwantedKeywords()
{
ASSERT_EQUALS("int var ;", tok("register int var ;", true));