@@ -2821,7 +2821,7 @@ static bool scopesMatch(const std::string &scope1, const std::string &scope2, co
28212821 return false ;
28222822}
28232823
2824- static unsigned int tokDistance (const Token* tok1, const Token* tok2) { // TODO: use index()
2824+ static unsigned int tokDistance (const Token* tok1, const Token* tok2) { // use when index() is not available yet
28252825 unsigned int dist = 0 ;
28262826 const Token* tok = tok1;
28272827 while (tok != tok2) {
@@ -9924,10 +9924,13 @@ void Tokenizer::simplifyBitfields()
99249924 }
99259925 }
99269926
9927- if (Token::Match (tok->next (), " const| %type% %name% :" ) &&
9927+ Token* typeTok = tok->next ();
9928+ while (Token::Match (typeTok, " const|volatile" ))
9929+ typeTok = typeTok->next ();
9930+ if (Token::Match (typeTok, " %type% %name% :" ) &&
99289931 !Token::Match (tok->next (), " case|public|protected|private|class|struct" ) &&
99299932 !Token::simpleMatch (tok->tokAt (2 ), " default :" )) {
9930- Token *tok1 = (tok-> strAt ( 1 ) == " const " ) ? tok-> tokAt ( 3 ) : tok-> tokAt ( 2 );
9933+ Token *tok1 = typeTok-> next ( );
99319934 if (Token::Match (tok1, " %name% : %num% [;=]" ))
99329935 tok1->setBits (static_cast <unsigned char >(MathLib::toBigNumber (tok1->tokAt (2 ))));
99339936 if (tok1 && tok1->tokAt (2 ) &&
@@ -9948,13 +9951,10 @@ void Tokenizer::simplifyBitfields()
99489951 } else {
99499952 tok->next ()->deleteNext (2 );
99509953 }
9951- } else if (Token::Match (tok->next (), " const| %type% : %num%|%bool% ;" ) &&
9952- tok->strAt (1 ) != " default" ) {
9953- const int offset = (tok->strAt (1 ) == " const" ) ? 1 : 0 ;
9954- if (!Token::Match (tok->tokAt (3 + offset), " [{};()]" )) {
9955- tok->deleteNext (4 + offset);
9956- goback = true ;
9957- }
9954+ } else if (Token::Match (typeTok, " %type% : %num%|%bool% ;" ) &&
9955+ typeTok->str () != " default" ) {
9956+ tok->deleteNext (4 + tokDistance (tok, typeTok) - 1 );
9957+ goback = true ;
99589958 }
99599959
99609960 if (last && last->str () == " ," ) {
0 commit comments