Fixed #827 (Tokenizer: sizeof is incorrectly simplified)

This commit is contained in:
Daniel Marjamäki 2009-10-18 18:06:32 +02:00
parent 58790eda82
commit 50e542c183
2 changed files with 34 additions and 2 deletions

View File

@ -1039,7 +1039,7 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "class|struct %type% :|{|;"))
continue;
if (Token::Match(tok, "else|return|typedef|delete"))
if (Token::Match(tok, "else|return|typedef|delete|sizeof"))
continue;
if (Token::Match(tok, "const|static|extern|public:|private:|protected:"))
@ -1537,7 +1537,6 @@ void Tokenizer::simplifySizeof()
tok->insertToken("(");
tempToken->insertToken(")");
Token::createMutualLinks(tok->next(), tempToken->next());
setVarId();
break;
}
}

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(sizeof8);
TEST_CASE(sizeof9);
TEST_CASE(sizeof10);
TEST_CASE(sizeof11);
TEST_CASE(casting);
TEST_CASE(template1);
@ -788,6 +789,38 @@ private:
ASSERT_EQUALS(code, tok(code));
}
void sizeof11()
{
// ticket #827
const char code[] = "void f()\n"
"{\n"
" char buf2[4];\n"
" sizeof buf2;\n"
"}\n"
"\n"
"void g()\n"
"{\n"
" struct A a[2];\n"
" char buf[32];\n"
" sizeof buf;\n"
"}";
const char expected[] = "void f ( ) "
"{"
" char buf2 [ 4 ] ;"
" 4 ; "
"} "
""
"void g ( ) "
"{"
" struct A a [ 2 ] ;"
" char buf [ 32 ] ;"
" 32 ; "
"}";
ASSERT_EQUALS(expected, tok(code));
}
void casting()
{
{