From b216639069971f076921b10f4776043d4ce47074 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 2 Dec 2012 07:22:55 +0100 Subject: [PATCH] Fixed #4378 (simplifyEnum doesn't simplify enum type within open and close parenthisis) --- lib/tokenize.cpp | 3 +++ test/testsimplifytokens.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b4eeb831b..ce510ac34 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7373,6 +7373,9 @@ void Tokenizer::simplifyEnum() (tok2->next()->isName() || tok2->next()->str() == "(")) { simplify = true; hasClass = false; + } else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") { + simplify = true; + hasClass = false; } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 05cc1335c..8c9424b55 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -356,6 +356,7 @@ private: TEST_CASE(enum33); // ticket #4015 (segmentation fault) TEST_CASE(enum34); // ticket #4141 (division by zero) TEST_CASE(enum35); // ticket #3953 (avoid simplification of type) + TEST_CASE(enum36); // ticket #4378 TEST_CASE(enumscope1); // ticket #3949 TEST_CASE(duplicateDefinition); // ticket #3565 @@ -7241,6 +7242,11 @@ private: 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 const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n" "void bar() { int a = A; }";