Fixed #4625 (wrong enum simplification in shadowed enum declaration)

This commit is contained in:
Daniel Marjamäki 2016-02-07 13:51:03 +01:00
parent f781f13997
commit 6c1012a8d6
2 changed files with 8 additions and 1 deletions

View File

@ -7754,7 +7754,7 @@ void Tokenizer::simplifyEnum()
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
if (!Token::Match(tok2->previous(), "%op%|::|:") &&
!Token::simpleMatch(tok2->tokAt(-2), ") ,") &&
Token::Match(tok2->next(), "%name%|(")) {
Token::Match(tok2->next(), "%name%|( !!{")) {
simplify = true;
hasClass = false;
} else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") {

View File

@ -201,6 +201,7 @@ private:
TEST_CASE(enum43); // lhs in assignment
TEST_CASE(enum44);
TEST_CASE(enum45); // ticket #6806 (enum in init list)
TEST_CASE(enum46); // ticket #4625 (shadow declaration)
TEST_CASE(enumscope1); // ticket #3949
TEST_CASE(enumOriginalName)
TEST_CASE(duplicateDefinition); // ticket #3565
@ -3304,6 +3305,12 @@ private:
ASSERT_EQUALS("c :: c ( ) : a ( 0 ) , a ( 0 ) { }", checkSimplifyEnum(code));
}
void enum46() { // #4625 - wrong simplification in shadow declaration
const char code[] = "enum e {foo,bar};\n"
"class c { enum e {foo=0,bar}; };";
ASSERT_EQUALS("class c { } ;", 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; }";