Fix handling of `sizeof &var` (#1498)

Fixes https://trac.cppcheck.net/ticket/8870
This commit is contained in:
Colomban Wendling 2018-11-30 13:53:58 +01:00 committed by Daniel Marjamäki
parent 86f984020b
commit cad4e4ab20
2 changed files with 2 additions and 1 deletions

View File

@ -3340,7 +3340,7 @@ void Tokenizer::sizeofAddParentheses()
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (!Token::Match(tok, "sizeof !!("))
continue;
if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!")) {
if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!|&")) {
Token *endToken = tok->next();
while (Token::simpleMatch(endToken, "* *"))
endToken = endToken->next();

View File

@ -8662,6 +8662,7 @@ private:
ASSERT_EQUALS("sizeof ( a . b ) + 3 ;", tokenizeAndStringify("sizeof a.b+3;"));
ASSERT_EQUALS("sizeof ( a [ 2 ] . b ) + 3 ;", tokenizeAndStringify("sizeof a[2].b+3;"));
ASSERT_EQUALS("f ( 0 , sizeof ( ptr . bar ) ) ;", tokenizeAndStringify("f(0, sizeof ptr->bar );"));
ASSERT_EQUALS("sizeof ( a ) > sizeof ( & main ) ;", tokenizeAndStringify("sizeof a > sizeof &main;"));
}
void findGarbageCode() { // Make sure the Tokenizer::findGarbageCode() does not have FPs