diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 275485811..a5cb41c1c 100755 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -372,9 +372,10 @@ void Tokenizer::simplifyTypedef() const char *type1 = 0; const char *type2 = 0; const char *typeName = 0; + bool pointer = false; if (Token::Match(tok->next(), "%type% %type% ;") || - Token::Match(tok->next(), "%type% %type% %type% ;")) + Token::Match(tok->next(), "%type% %type% *| %type% ;")) { if (tok->tokAt(3)->str() == ";") { @@ -385,10 +386,22 @@ void Tokenizer::simplifyTypedef() } else { + pointer = (tok->tokAt(3)->str() == "*"); + type1 = tok->strAt(1); type2 = tok->strAt(2); - typeName = tok->strAt(3); - tok = tok->tokAt(4); + + if (pointer) + { + typeName = tok->strAt(4); + tok = tok->tokAt(5); + } + else + { + typeName = tok->strAt(3); + tok = tok->tokAt(4); + + } } const std::string pattern = className + " :: " + typeName; @@ -443,6 +456,11 @@ void Tokenizer::simplifyTypedef() tok2->insertToken(type2); tok2 = tok2->next(); } + if (pointer) + { + tok2->insertToken("*"); + tok2 = tok2->next(); + } simplifyType = false; } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index ede53bb74..8ecc1a57a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -123,6 +123,7 @@ private: TEST_CASE(simplifyTypedef2) TEST_CASE(simplifyTypedef3) TEST_CASE(simplifyTypedef4) + TEST_CASE(simplifyTypedef5) } std::string tok(const char code[], bool simplify = true) @@ -1754,6 +1755,26 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } + void simplifyTypedef5() + { + // ticket #780 + const char code[] = + "typedef struct yy_buffer_state *YY_BUFFER_STATE;\n" + "void f()\n" + "{\n" + " YY_BUFFER_STATE state;\n" + "}\n"; + + const char expected[] = + "typedef struct yy_buffer_state * YY_BUFFER_STATE ; " + "void f ( ) " + "{ " + "struct yy_buffer_state * state ; " + "}"; + + ASSERT_EQUALS(expected, tok(code, false)); + } + }; REGISTER_TEST(TestSimplifyTokens)