From 2ec5438186eca97120fe115cce42c6f2f17fc8f9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 14 Nov 2009 01:07:44 +0600 Subject: [PATCH] Fixed #954 (Tokenizer: correctly simplify sizeof of class members) http://sourceforge.net/apps/trac/cppcheck/ticket/954 --- lib/tokenize.cpp | 5 +++++ test/testsimplifytokens.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 218e45195..e3e5e042c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1721,6 +1721,11 @@ void Tokenizer::simplifySizeof() // nothing after this tempToken = tempToken->tokAt(2); } + else if (Token::simpleMatch(tempToken->next(), ") .")) + { + tempToken = tempToken->tokAt(2); + continue; + } // Ok, we should be clean. Add ) after tempToken tok->insertToken("("); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4f8e9a94a..dc276be63 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -69,6 +69,7 @@ private: TEST_CASE(sizeof11); TEST_CASE(sizeof12); TEST_CASE(sizeof13); + TEST_CASE(sizeof14); TEST_CASE(casting); TEST_CASE(strlen1); @@ -884,6 +885,22 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void sizeof14() + { + // ticket #954 + const char code[] = "void f()\n" + "{\n" + " A **a;\n" + " int aa = sizeof *(*a)->b;\n" + "}\n"; + const char expected[] = "void f ( ) " + "{" + " A * * a ;" + " int aa ; aa = sizeof ( * ( * a ) . b ) ; " + "}"; + ASSERT_EQUALS(expected, tok(code)); + } + void casting() { {