Fixed #4973 (wrong enum simplification of shadow struct variable)
This commit is contained in:
parent
6c1012a8d6
commit
5fef7cc050
|
@ -7549,10 +7549,11 @@ void Tokenizer::simplifyEnum()
|
|||
bool inScope = !enumClass; // enum class objects are always in a different scope
|
||||
|
||||
std::stack<std::set<std::string> > shadowId; // duplicate ids in inner scope
|
||||
bool simplify = false;
|
||||
const EnumValue *ev = nullptr;
|
||||
|
||||
for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) {
|
||||
bool simplify = false;
|
||||
const EnumValue *ev = nullptr;
|
||||
|
||||
if (tok2->str() == "}") {
|
||||
--level;
|
||||
if (level < 0)
|
||||
|
@ -7640,6 +7641,7 @@ void Tokenizer::simplifyEnum()
|
|||
}
|
||||
} else if (inScope && // enum is in scope
|
||||
(shadowId.empty() || shadowId.top().find(tok2->str()) == shadowId.top().end()) && // no shadow enum/var/etc of enum
|
||||
!Token::Match(tok2->previous(), "} %name% ;") &&
|
||||
enumValues.find(tok2->str()) != enumValues.end()) { // tok2 is a enum id with a known value
|
||||
ev = &(enumValues.find(tok2->str())->second);
|
||||
if (!duplicateDefinition(&tok2)) {
|
||||
|
@ -7697,8 +7699,6 @@ void Tokenizer::simplifyEnum()
|
|||
tok2 = tok2->next();
|
||||
}
|
||||
}
|
||||
|
||||
simplify = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ private:
|
|||
TEST_CASE(enum44);
|
||||
TEST_CASE(enum45); // ticket #6806 (enum in init list)
|
||||
TEST_CASE(enum46); // ticket #4625 (shadow declaration)
|
||||
TEST_CASE(enum47); // ticket #4973 (wrong simplification in shadow struct variable declaration)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(enumOriginalName)
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
@ -3311,6 +3312,12 @@ private:
|
|||
ASSERT_EQUALS("class c { } ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum47() { // #4973 - wrong simplification in shadow struct variable declaration
|
||||
const char code[] = "enum e {foo};\n"
|
||||
"union { struct { } foo; };";
|
||||
ASSERT_EQUALS("union { struct Anonymous0 { } ; struct Anonymous0 foo ; } ;", 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; }";
|
||||
|
|
Loading…
Reference in New Issue