From 75f6e20e619be6136093e77af47ed45b054170cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Dec 2009 08:46:59 +0100 Subject: [PATCH] Fixed #1050 (Internal error: In tokenizer for: 'do { sizeof 1; } while (0);') --- lib/tokenize.cpp | 11 ++++++++++- test/testsimplifytokens.cpp | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 18cfa1f72..133fd0b37 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1745,8 +1745,17 @@ void Tokenizer::simplifySizeof() Token::createMutualLinks(tok->next(), tok->tokAt(4)); } + // sizeof 1 => sizeof ( 1 ) + if (tok->next()->isNumber()) + { + Token *tok2 = tok->next(); + tok->insertToken("("); + tok2->insertToken(")"); + Token::createMutualLinks(tok->next(), tok2->next()); + } + // sizeof int -> sizeof( int ) - if (tok->next()->str() != "(") + else 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 36f6f46a9..ae31e9c37 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -72,6 +72,7 @@ private: TEST_CASE(sizeof14); TEST_CASE(sizeof15); TEST_CASE(sizeof16); + TEST_CASE(sizeof17); TEST_CASE(casting); TEST_CASE(strlen1); @@ -938,6 +939,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void sizeof17() + { + // ticket #1050 + const char code[] = "void f()\n" + "{\n" + " sizeof 1;\n" + " while (0);\n" + "}\n"; + ASSERT_EQUALS("void f ( ) { sizeof ( 1 ) ; while ( false ) { ; } }", tok(code)); + ASSERT_EQUALS("", errout.str()); + } + void casting() { {