From fc7e2d1ac1994fc1e88c57e169514da38d42cec1 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 22 Dec 2010 18:37:23 +0100 Subject: [PATCH] Fixed #2341 (false positive for function pointer returning typedef) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7e3c37f0a..d3086036d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -573,7 +573,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) 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->previous(), "return|new|const|friend|public|private|protected|throw|extern") && !Token::Match(tok->tokAt(-2), "friend class")))) { // scan backwards for the end of the previous statement diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7838ca42e..abf8cd923 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -222,6 +222,7 @@ private: TEST_CASE(simplifyTypedef63); // ticket #2175 'typedef float x[3];' TEST_CASE(simplifyTypedef64); TEST_CASE(simplifyTypedef65); // ticket #2314 + TEST_CASE(simplifyTypedef66); // ticket #2341 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4602,6 +4603,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef66() // ticket #2341 + { + const char code[] = "typedef long* GEN;\n" + "extern GEN (*foo)(long);"; + const std::string actual(sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {