From e45bb20f9232da5926f6940277465f73c56e02de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 29 Mar 2009 16:36:34 +0200 Subject: [PATCH] tokenizer: don't replace sizeof when size can't be determined (#233) --- src/tokenize.cpp | 13 ++++++++----- test/testsimplifytokens.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 22f91f311..bedab3fcf 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -1010,12 +1010,15 @@ void Tokenizer::simplifyTokenList() } } - std::ostringstream ostr; - ostr << sz; - tok->str(ostr.str().c_str()); - while (tok->next()->str() != ")") + if (sz > 0) + { + std::ostringstream ostr; + ostr << sz; + tok->str(ostr.str().c_str()); + while (tok->next()->str() != ")") + tok->deleteNext(); tok->deleteNext(); - tok->deleteNext(); + } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 59eca94d1..c9108bd27 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -75,6 +75,7 @@ private: TEST_CASE(sizeof4); TEST_CASE(sizeof5); TEST_CASE(sizeof6); + TEST_CASE(sizeof7); TEST_CASE(casting); TEST_CASE(template1); @@ -448,6 +449,13 @@ private: ASSERT_EQUALS(expected.str(), sizeof_(code)); } + void sizeof7() + { + const char code[] = ";INT32 i[10];\n" + "sizeof(i[0]);\n"; + ASSERT_EQUALS(" ; INT32 i [ 10 ] ; sizeof ( i [ 0 ] ) ;", sizeof_(code)); + } + void casting() { const char code[] = "void f()\n"