@@ -1125,6 +1125,18 @@ void Tokenizer::simplifyTypedef()
11251125 simplifyTypedefCpp ();
11261126}
11271127
1128+ static bool isEnumScope (const Token* tok)
1129+ {
1130+ if (!Token::simpleMatch (tok, " {" ))
1131+ return false ;
1132+ tok = tok->previous ();
1133+ while (tok && !tok->isKeyword () && Token::Match (tok, " %name%|::|:" ))
1134+ tok = tok->previous ();
1135+ if (Token::simpleMatch (tok, " class" ))
1136+ tok = tok->previous ();
1137+ return Token::simpleMatch (tok, " enum" );
1138+ }
1139+
11281140void Tokenizer::simplifyTypedefCpp ()
11291141{
11301142 bool isNamespace = false ;
@@ -1622,7 +1634,7 @@ void Tokenizer::simplifyTypedefCpp()
16221634 bool globalScope = false ;
16231635 int classLevel = spaceInfo.size ();
16241636 bool inTypeDef = false ;
1625- bool inEnumClass = false ;
1637+ bool inEnum = false ;
16261638 std::string removed;
16271639 std::string classPath;
16281640 for (size_t i = 1 ; i < spaceInfo.size (); ++i) {
@@ -1676,7 +1688,7 @@ void Tokenizer::simplifyTypedefCpp()
16761688 if (memberScope == 0 )
16771689 inMemberFunc = false ;
16781690 }
1679- inEnumClass = false ;
1691+ inEnum = false ;
16801692
16811693 if (classLevel > 1 && tok2 == spaceInfo[classLevel - 1 ].bodyEnd2 ) {
16821694 --classLevel;
@@ -1736,8 +1748,8 @@ void Tokenizer::simplifyTypedefCpp()
17361748 }
17371749 ++scope;
17381750 }
1739- if (Token::Match (tok2-> tokAt (- 3 ), " enum class %name% " ))
1740- inEnumClass = true ;
1751+ if (isEnumScope (tok2))
1752+ inEnum = true ;
17411753 }
17421754
17431755 // keep track of scopes within member function
@@ -1863,7 +1875,7 @@ void Tokenizer::simplifyTypedefCpp()
18631875 }
18641876 }
18651877
1866- simplifyType = simplifyType && (!inEnumClass || Token::simpleMatch (tok2->previous (), " =" ));
1878+ simplifyType = simplifyType && (!inEnum || ! Token::simpleMatch (tok2->next (), " =" ));
18671879 simplifyType = simplifyType && !(Token::simpleMatch (tok2->next (), " <" ) && Token::simpleMatch (typeEnd, " >" ));
18681880
18691881 if (simplifyType) {
0 commit comments