diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 05a82a3dd..ba6e9b1f0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2679,6 +2679,12 @@ void Tokenizer::setVarId() if (tok == list.front() || Token::Match(tok, "[;{}]") || (Token::Match(tok,"[(,]") && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {"))) || (tok->isName() && tok->str().at(tok->str().length()-1U) == ':')) { + + // No variable declarations in sizeof + if (Token::Match(tok->previous(), "sizeof (")) { + continue; + } + // locate the variable name.. const Token *tok2 = (tok->isName()) ? tok : tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index fd9df57c7..e0d57fc2e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -223,6 +223,7 @@ private: TEST_CASE(varidStl); TEST_CASE(varid_delete); TEST_CASE(varid_functions); + TEST_CASE(varid_sizeof); TEST_CASE(varid_reference_to_containers); TEST_CASE(varid_in_class1); TEST_CASE(varid_in_class2); @@ -3437,6 +3438,13 @@ private: } + void varid_sizeof() { + const char code[] = "x = sizeof(a*b);"; + const char expected[] = "\n\n##file 0\n" + "1: x = sizeof ( a * b ) ;\n"; + ASSERT_EQUALS(expected, tokenizeDebugListing(code,false,"test.c")); + } + void varid_reference_to_containers() { const std::string actual = tokenizeDebugListing( "void f()\n"