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)); + } } };