From 8716c771a43e51cbe7410fc7dda2fa2351e9d74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 30 Jan 2010 14:25:11 +0100 Subject: [PATCH] Tokenizer: improved the simplifyInitVar --- lib/tokenize.cpp | 7 +++++-- test/testsimplifytokens.cpp | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 702b5082a..21c3dfe2a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4126,9 +4126,12 @@ void Tokenizer::simplifyInitVar() { for (Token *tok = _tokens; tok; tok = tok->next()) { - if (Token::Match(tok, "[{};] %type% *| %var% ( %num% ) ;") && - tok->next()->isStandardType()) + if (Token::Match(tok, "[{};] %type% *| %var% ( %num% ) ;")) { + // call constructor of class => no simplification + if (!tok->next()->isStandardType() && tok->tokAt(2)->str() != "*") + continue; + // goto variable name.. tok = tok->tokAt(2); if (tok->str() == "*") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 5ad45465c..a34d3d794 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3237,8 +3237,20 @@ private: void simplifyInitVar() { // ticket #1005 - int *p(0); => int *p = 0; - const char code[] = "void foo() { int *p(0); }"; - ASSERT_EQUALS("void foo ( ) { int * p ; p = 0 ; }", tok(code)); + { + const char code[] = "void foo() { int *p(0); }"; + ASSERT_EQUALS("void foo ( ) { int * p ; p = 0 ; }", tok(code)); + } + + { + const char code[] = "void foo() { int p(0); }"; + ASSERT_EQUALS("void foo ( ) { int p ; p = 0 ; }", tok(code)); + } + + { + const char code[] = "void a() { foo *p(0); }"; + ASSERT_EQUALS("void a ( ) { foo * p ; p = 0 ; }", tok(code)); + } } };