From 8a379d482629afba4c266c6f4f63b4d48d06b464 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 6 Nov 2010 15:15:50 +0100 Subject: [PATCH] Fixed #2176 (Tokenizer::simplifyTypedef function pointer bug) --- lib/tokenize.cpp | 5 +++++ test/testsimplifytokens.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 611a47334..63edfb2c7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1371,10 +1371,15 @@ void Tokenizer::simplifyTypedef() else if (!inOperator && !Token::Match(tok2->next(), "[|>|;")) { tok2 = tok2->next(); + while (Token::Match(tok2, "*|&") && !Token::Match(tok2->next(), ")|>")) tok2 = tok2->next(); + // skip over namespace + while (Token::Match(tok2, "%var% ::")) + tok2 = tok2->tokAt(2); + // skip over typedef parameter if (tok2->next()->str() == "(") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a6c8ce96b..a7a0f2c84 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -225,6 +225,7 @@ private: TEST_CASE(simplifyTypedefFunction3); TEST_CASE(simplifyTypedefFunction4); TEST_CASE(simplifyTypedefFunction5); + TEST_CASE(simplifyTypedefFunction6); TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -5083,6 +5084,37 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedefFunction6() + { + const char code[] = "typedef void (*testfp)();\n" + "struct Fred\n" + "{\n" + " testfp get1() { return 0; }\n" + " void ( * get2 ( ) ) ( ) { return 0 ; }\n" + " testfp get3();\n" + " void ( * get4 ( ) ) ( );\n" + "};\n" + "testfp Fred::get3() { return 0; }\n" + "void ( * Fred::get4 ( ) ) ( ) { return 0 ; }\n"; + + // The expected result.. + const std::string expected("; " + "struct Fred " + "{ " + "void ( * get1 ( ) ) ( ) { return 0 ; } " + "void ( * get2 ( ) ) ( ) { return 0 ; } " + "void ( * get3 ( ) ) ( ) ; " + "void ( * get4 ( ) ) ( ) ; " + "} ; " + "void ( * Fred :: get3 ( ) ) ( ) { return 0 ; } " + "void ( * Fred :: get4 ( ) ) ( ) { return 0 ; }"); + + ASSERT_EQUALS(expected, tok(code, false)); + + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));