Fixed #4378 (simplifyEnum doesn't simplify enum type within open and close parenthisis)

This commit is contained in:
Robert Reif 2012-12-02 07:22:55 +01:00 committed by Daniel Marjamäki
parent 45a16baaa0
commit b216639069
2 changed files with 9 additions and 0 deletions

View File

@ -7373,6 +7373,9 @@ void Tokenizer::simplifyEnum()
(tok2->next()->isName() || tok2->next()->str() == "(")) { (tok2->next()->isName() || tok2->next()->str() == "(")) {
simplify = true; simplify = true;
hasClass = false; hasClass = false;
} else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") {
simplify = true;
hasClass = false;
} }
} }

View File

@ -356,6 +356,7 @@ private:
TEST_CASE(enum33); // ticket #4015 (segmentation fault) TEST_CASE(enum33); // ticket #4015 (segmentation fault)
TEST_CASE(enum34); // ticket #4141 (division by zero) TEST_CASE(enum34); // ticket #4141 (division by zero)
TEST_CASE(enum35); // ticket #3953 (avoid simplification of type) TEST_CASE(enum35); // ticket #3953 (avoid simplification of type)
TEST_CASE(enum36); // ticket #4378
TEST_CASE(enumscope1); // ticket #3949 TEST_CASE(enumscope1); // ticket #3949
TEST_CASE(duplicateDefinition); // ticket #3565 TEST_CASE(duplicateDefinition); // ticket #3565
@ -7241,6 +7242,11 @@ private:
ASSERT_EQUALS("void f ( A * a ) { }", checkSimplifyEnum("enum { A }; void f(A * a) { }")); ASSERT_EQUALS("void f ( A * a ) { }", checkSimplifyEnum("enum { A }; void f(A * a) { }"));
} }
void enum36() { // #4378
const char code[] = "struct X { enum Y { a, b }; X(Y) { Y y = (Y)1; } };";
ASSERT_EQUALS("struct X { X ( int ) { int y ; y = ( int ) 1 ; } } ;", checkSimplifyEnum(code));
}
void enumscope1() { // #3949 - don't simplify enum from one function in another function void enumscope1() { // #3949 - don't simplify enum from one function in another function
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n" const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
"void bar() { int a = A; }"; "void bar() { int a = A; }";