From 50e542c183b1db8b1bd765aa9902af9789e6c580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Oct 2009 18:06:32 +0200 Subject: [PATCH] Fixed #827 (Tokenizer: sizeof is incorrectly simplified) --- src/tokenize.cpp | 3 +-- test/testsimplifytokens.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 1915a4b41..d7bb3780c 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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; } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c791668db..8876a6707 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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() { {