@@ -2821,7 +2821,7 @@ static bool scopesMatch(const std::string &scope1, const std::string &scope2, co
2821
2821
return false ;
2822
2822
}
2823
2823
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
2825
2825
unsigned int dist = 0 ;
2826
2826
const Token* tok = tok1;
2827
2827
while (tok != tok2) {
@@ -9924,10 +9924,13 @@ void Tokenizer::simplifyBitfields()
9924
9924
}
9925
9925
}
9926
9926
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% :" ) &&
9928
9931
!Token::Match (tok->next (), " case|public|protected|private|class|struct" ) &&
9929
9932
!Token::simpleMatch (tok->tokAt (2 ), " default :" )) {
9930
- Token *tok1 = (tok-> strAt ( 1 ) == " const " ) ? tok-> tokAt ( 3 ) : tok-> tokAt ( 2 );
9933
+ Token *tok1 = typeTok-> next ( );
9931
9934
if (Token::Match (tok1, " %name% : %num% [;=]" ))
9932
9935
tok1->setBits (static_cast <unsigned char >(MathLib::toBigNumber (tok1->tokAt (2 ))));
9933
9936
if (tok1 && tok1->tokAt (2 ) &&
@@ -9948,13 +9951,10 @@ void Tokenizer::simplifyBitfields()
9948
9951
} else {
9949
9952
tok->next ()->deleteNext (2 );
9950
9953
}
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 ;
9958
9958
}
9959
9959
9960
9960
if (last && last->str () == " ," ) {
0 commit comments