diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5f3aa734a..101e375e1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -742,14 +742,16 @@ void Tokenizer::simplifyTypedef() typeStart = tokOffset; while (Token::Match(tokOffset, "const|struct|enum %type%") || - (tokOffset->next() && tokOffset->next()->isStandardType())) + (tokOffset->next() && tokOffset->next()->isStandardType() && !Token::Match(tokOffset->next(), "%name% ;"))) tokOffset = tokOffset->next(); typeEnd = tokOffset; - tokOffset = tokOffset->next(); + if (!Token::Match(tokOffset->next(), "%name% ;")) + tokOffset = tokOffset->next(); while (Token::Match(tokOffset, "%type%") && - (tokOffset->isStandardType() || Token::Match(tokOffset, "unsigned|signed"))) { + (tokOffset->isStandardType() || Token::Match(tokOffset, "unsigned|signed")) && + !Token::Match(tokOffset->next(), "%name% ;")) { typeEnd = tokOffset; tokOffset = tokOffset->next(); } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 6929df7a2..005d2e304 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -2545,11 +2545,12 @@ private: void simplifyTypedef124() { // ticket #7792 const char code[] = "typedef long unsigned int size_t;\n" - "typedef size_t (my_func)(char *, size_t, size_t, void *);"; + "typedef size_t (my_func)(char *, size_t, size_t, void *);" + "size_t f(size_t s);"; - // Check for output.. - checkSimplifyTypedef(code); - ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:1]: (debug) Failed to parse 'typedef long unsigned int size_t ;'. The checking continues anyway.\n", errout.str()); + const char exp[] = "long f ( long s ) ;"; + ASSERT_EQUALS(exp, tok(code, /*simplify*/ true)); + ASSERT_EQUALS("", errout.str()); const char code1[] = "typedef long unsigned int uint32_t;\n" "typedef uint32_t (my_func)(char *, uint32_t, uint32_t, void *);";