diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c3f2f5a29..2639ec3aa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -527,6 +527,12 @@ void Tokenizer::simplifyTypedef() tok = tok->previous(); } + // Skip typedefs inside parentheses (#2453 and #4002) + if (tok->str() == "(" && tok->strAt(1) == "typedef") { + tok = tok->next(); + continue; + } + if (Token::Match(tok, "class|struct|namespace %any%") && (!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) { isNamespace = (tok->str() == "namespace"); @@ -551,12 +557,6 @@ void Tokenizer::simplifyTypedef() } else if (tok->str() != "typedef") continue; - // check for syntax errors - if (tok->previous() && tok->previous()->str() == "(") { - syntaxError(tok); - continue; - } - // pull struct, union, enum or class definition out of typedef // use typedef name for unnamed struct, union, enum or class if (Token::Match(tok->next(), "const| struct|enum|union|class %type% {") || diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 237f3e292..e3f369af1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -5382,7 +5382,7 @@ private: const char code[] = "void f1(typedef int x) {}\n"; const std::string expected = "void f1 ( typedef int x ) { }"; ASSERT_EQUALS(expected, tok(code)); - ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void simplifyTypedef77() { // ticket #2554