diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6c78aba93..7b4dc00cf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3320,9 +3320,17 @@ bool Tokenizer::simplifySizeof() for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) { if (tempToken->str() == "(") ++parlevel; - else if (tempToken->str() == ")") + else if (tempToken->str() == ")") { --parlevel; - if (Token::Match(tempToken, "%var%")) { + if (parlevel == 0 && !Token::Match(tempToken, ") . %var%")) { + // Ok, we should be clean. Add ) after tempToken + tok->insertToken("("); + tempToken->insertToken(")"); + Token::createMutualLinks(tok->next(), tempToken->next()); + break; + } + } + if (parlevel == 0 && Token::Match(tempToken, "%var%")) { while (tempToken && tempToken->next() && tempToken->next()->str() == "[") { tempToken = tempToken->next()->link(); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index bf9d2dbf5..ea0acc2bc 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1325,6 +1325,9 @@ private: " int aa ; aa = sizeof ( * ( * a ) . b ) ; " "}"; ASSERT_EQUALS(expected, tok(code)); + + // #5064 - sizeof !! (a == 1); + ASSERT_EQUALS("sizeof ( ! ! ( a == 1 ) ) ;", tok("sizeof !!(a==1);")); } void sizeof15() {