Skip to content

Commit 6c1012a

Browse files
committed
Fixed #4625 (wrong enum simplification in shadowed enum declaration)
1 parent f781f13 commit 6c1012a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7754,7 +7754,7 @@ void Tokenizer::simplifyEnum()
77547754
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
77557755
if (!Token::Match(tok2->previous(), "%op%|::|:") &&
77567756
!Token::simpleMatch(tok2->tokAt(-2), ") ,") &&
7757-
Token::Match(tok2->next(), "%name%|(")) {
7757+
Token::Match(tok2->next(), "%name%|( !!{")) {
77587758
simplify = true;
77597759
hasClass = false;
77607760
} else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") {

test/testsimplifytokens.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class TestSimplifyTokens : public TestFixture {
201201
TEST_CASE(enum43); // lhs in assignment
202202
TEST_CASE(enum44);
203203
TEST_CASE(enum45); // ticket #6806 (enum in init list)
204+
TEST_CASE(enum46); // ticket #4625 (shadow declaration)
204205
TEST_CASE(enumscope1); // ticket #3949
205206
TEST_CASE(enumOriginalName)
206207
TEST_CASE(duplicateDefinition); // ticket #3565
@@ -3304,6 +3305,12 @@ class TestSimplifyTokens : public TestFixture {
33043305
ASSERT_EQUALS("c :: c ( ) : a ( 0 ) , a ( 0 ) { }", checkSimplifyEnum(code));
33053306
}
33063307

3308+
void enum46() { // #4625 - wrong simplification in shadow declaration
3309+
const char code[] = "enum e {foo,bar};\n"
3310+
"class c { enum e {foo=0,bar}; };";
3311+
ASSERT_EQUALS("class c { } ;", checkSimplifyEnum(code));
3312+
}
3313+
33073314
void enumscope1() { // #3949 - don't simplify enum from one function in another function
33083315
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
33093316
"void bar() { int a = A; }";

0 commit comments

Comments
 (0)