File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7549,10 +7549,11 @@ void Tokenizer::simplifyEnum()
75497549 bool inScope = !enumClass; // enum class objects are always in a different scope
75507550
75517551 std::stack<std::set<std::string> > shadowId; // duplicate ids in inner scope
7552- bool simplify = false ;
7553- const EnumValue *ev = nullptr ;
75547552
75557553 for (Token *tok2 = tok1->next (); tok2; tok2 = tok2->next ()) {
7554+ bool simplify = false ;
7555+ const EnumValue *ev = nullptr ;
7556+
75567557 if (tok2->str () == " }" ) {
75577558 --level;
75587559 if (level < 0 )
@@ -7640,6 +7641,7 @@ void Tokenizer::simplifyEnum()
76407641 }
76417642 } else if (inScope && // enum is in scope
76427643 (shadowId.empty () || shadowId.top ().find (tok2->str ()) == shadowId.top ().end ()) && // no shadow enum/var/etc of enum
7644+ !Token::Match (tok2->previous (), " } %name% ;" ) &&
76437645 enumValues.find (tok2->str ()) != enumValues.end ()) { // tok2 is a enum id with a known value
76447646 ev = &(enumValues.find (tok2->str ())->second );
76457647 if (!duplicateDefinition (&tok2)) {
@@ -7697,8 +7699,6 @@ void Tokenizer::simplifyEnum()
76977699 tok2 = tok2->next ();
76987700 }
76997701 }
7700-
7701- simplify = false ;
77027702 }
77037703 }
77047704 }
Original file line number Diff line number Diff line change @@ -202,6 +202,7 @@ class TestSimplifyTokens : public TestFixture {
202202 TEST_CASE (enum44);
203203 TEST_CASE (enum45); // ticket #6806 (enum in init list)
204204 TEST_CASE (enum46); // ticket #4625 (shadow declaration)
205+ TEST_CASE (enum47); // ticket #4973 (wrong simplification in shadow struct variable declaration)
205206 TEST_CASE (enumscope1); // ticket #3949
206207 TEST_CASE (enumOriginalName)
207208 TEST_CASE (duplicateDefinition); // ticket #3565
@@ -3311,6 +3312,12 @@ class TestSimplifyTokens : public TestFixture {
33113312 ASSERT_EQUALS (" class c { } ;" , checkSimplifyEnum (code));
33123313 }
33133314
3315+ void enum47 () { // #4973 - wrong simplification in shadow struct variable declaration
3316+ const char code[] = " enum e {foo};\n "
3317+ " union { struct { } foo; };" ;
3318+ ASSERT_EQUALS (" union { struct Anonymous0 { } ; struct Anonymous0 foo ; } ;" , checkSimplifyEnum (code));
3319+ }
3320+
33143321 void enumscope1 () { // #3949 - don't simplify enum from one function in another function
33153322 const char code[] = " void foo() { enum { A = 0, B = 1 }; }\n "
33163323 " void bar() { int a = A; }" ;
You can’t perform that action at this time.
0 commit comments