diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 429291dcb..2fb66ac58 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -555,7 +555,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) else { // look backwards - if (Token::Match(tok->previous(), "typedef|}|>|*") || + if (Token::Match(tok->previous(), "typedef|}|>") || + (tok->previous()->str() == "*" && tok->next()->str() != "(") || (Token::Match(tok->previous(), "%type%") && (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") && !Token::Match(tok->tokAt(-2), "friend class")))) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9ae5bab5c..3bee07ea8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -207,6 +207,7 @@ private: TEST_CASE(simplifyTypedef54); // ticket #1814 TEST_CASE(simplifyTypedef55); TEST_CASE(simplifyTypedef56); // ticket #1829 + TEST_CASE(simplifyTypedef57); // ticket #1846 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4268,6 +4269,25 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef57() // ticket #1846 + { + const char code[] = "void foo {\n" + " typedef int A;\n" + " A a = A(1) * A(2);\n" + "};\n"; + + // The expected result.. + const std::string expected("void foo { " + "; " + "int a ; a = int ( 1 ) * int ( 2 ) ; " + "} ;"); + ASSERT_EQUALS(expected, sizeof_(code)); + + // Check for output.. + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {