From e7d7507c65ced48407f659fbaa151ca1a4827f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 29 Nov 2009 12:14:42 +0100 Subject: [PATCH] Fixed #1020 (lib/tokenize.cpp:4615: bool Tokenizer::validate() const: Assertion 0 failed) --- lib/tokenize.cpp | 9 ++++++++- test/testsimplifytokens.cpp | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index affeb775b..3826396bd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1730,8 +1730,15 @@ void Tokenizer::simplifySizeof() continue; } + // sizeof * (...) -> sizeof(*...) + if (Token::simpleMatch(tok->next(), "* (") && !Token::simpleMatch(tok->tokAt(2)->link(), ") .")) + { + tok->deleteNext(); + tok->next()->insertToken("*"); + } + // sizeof int -> sizeof( int ) - if (tok->strAt(1) != std::string("(")) + if (tok->next()->str() != "(") { // Add parenthesis around the sizeof for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 75cef138f..afcc7a541 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -70,6 +70,7 @@ private: TEST_CASE(sizeof12); TEST_CASE(sizeof13); TEST_CASE(sizeof14); + TEST_CASE(sizeof15); TEST_CASE(casting); TEST_CASE(strlen1); @@ -148,9 +149,14 @@ private: std::string tok(const char code[], bool simplify = true) { + errout.str(""); + + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); - Tokenizer tokenizer; tokenizer.tokenize(istr, "test.cpp"); + if (simplify) tokenizer.simplifyTokenList(); @@ -908,6 +914,17 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void sizeof15() + { + // ticket #1020 + tok("void f()\n" + "{\n" + " int *n;\n" + " sizeof *(n);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void casting() { {