@@ -60,14 +60,24 @@ namespace {
6060 const bool isEnum;
6161 const unsigned int startVarid;
6262 };
63+ }
6364
64- /* * Return whether tok is the "{" that starts an enumerator list */
65- bool isEnumStart (const Token* tok)
66- {
67- if (!tok || tok->str () != " {" )
68- return false ;
69- return (tok->strAt (-1 ) == " enum" ) || (tok->strAt (-2 ) == " enum" );
70- }
65+ /* * Return whether tok is the "{" that starts an enumerator list */
66+ static bool isEnumStart (const Token* tok)
67+ {
68+ if (!tok || tok->str () != " {" )
69+ return false ;
70+ return (tok->strAt (-1 ) == " enum" ) || (tok->strAt (-2 ) == " enum" );
71+ }
72+
73+ template <typename T>
74+ static void skipEnumBody (T **tok)
75+ {
76+ T *defStart = *tok;
77+ while (Token::Match (defStart, " %name%|::|:" ))
78+ defStart = defStart->next ();
79+ if (defStart && defStart->str () == " {" )
80+ *tok = defStart->link ()->next ();
7181}
7282
7383const Token * Tokenizer::isFunctionHead (const Token *tok, const std::string &endsWith) const
@@ -7935,11 +7945,7 @@ void Tokenizer::simplifyComma()
79357945
79367946 // skip enums
79377947 if (Token::Match (tok, " enum class|struct| %name%| :|{" )) {
7938- Token *defStart = tok->next ();
7939- while (Token::Match (defStart, " %name%|::|:" ))
7940- defStart = defStart->next ();
7941- if (defStart && defStart->str () == " {" )
7942- tok = defStart->link ()->next ();
7948+ skipEnumBody (&tok);
79437949 }
79447950 if (!tok)
79457951 syntaxError (nullptr ); // invalid code like in #4195
@@ -9113,11 +9119,7 @@ void Tokenizer::simplifyNamespaceStd()
91139119 for (const Token* tok = Token::findsimplematch (list.front (), " using namespace std ;" ); tok; tok = tok->next ()) {
91149120 bool insert = false ;
91159121 if (Token::Match (tok, " enum class|struct| %name%| :|{" )) { // Don't replace within enum definitions
9116- Token *defStart = tok->next ();
9117- while (Token::Match (defStart, " %name%|::|:" ))
9118- defStart = defStart->next ();
9119- if (defStart && defStart->str () == " {" )
9120- tok = defStart->link ();
9122+ skipEnumBody (&tok);
91219123 }
91229124 if (!Token::Match (tok->previous (), " .|::" )) {
91239125 if (Token::Match (tok, " %name% (" ) && !Token::Match (tok->linkAt (1 )->next (), " %name%|{" ) && stdFunctions.find (tok->str ()) != stdFunctions.end ())
0 commit comments