Skip to content

Commit

Permalink
Fixed #827 (Tokenizer: sizeof is incorrectly simplified)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Marjamäki committed Oct 18, 2009
1 parent 58790ed commit 50e542c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/tokenize.cpp
Expand Up @@ -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:"))
Expand Down Expand Up @@ -1537,7 +1537,6 @@ void Tokenizer::simplifySizeof()
tok->insertToken("(");
tempToken->insertToken(")");
Token::createMutualLinks(tok->next(), tempToken->next());
setVarId();
break;
}
}
Expand Down
33 changes: 33 additions & 0 deletions test/testsimplifytokens.cpp
Expand Up @@ -66,6 +66,7 @@ class TestSimplifyTokens : public TestFixture
TEST_CASE(sizeof8);
TEST_CASE(sizeof9);
TEST_CASE(sizeof10);
TEST_CASE(sizeof11);
TEST_CASE(casting);

TEST_CASE(template1);
Expand Down Expand Up @@ -788,6 +789,38 @@ class TestSimplifyTokens : public TestFixture
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()
{
{
Expand Down

0 comments on commit 50e542c

Please sign in to comment.