From 82527422a8d5d45618f97f18ac6a5e46160cc2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Aug 2017 19:18:05 +0200 Subject: [PATCH] Fixed #5614 (Incorrect syntax error with function pointer typedef and dependent template types) --- lib/tokenize.cpp | 17 ++++++++++++----- test/testsimplifytypedef.cpp | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index dabeaa150..61820ba5e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -798,6 +798,15 @@ void Tokenizer::simplifyTypedef() // or a function typedef else if (tokOffset && tokOffset->str() == "(") { + Token *tokOffset2 = nullptr; + if (Token::Match(tokOffset, "( *|%name%")) { + tokOffset2 = tokOffset->next(); + if (tokOffset2->str() == "typename") + tokOffset2 = tokOffset2->next(); + while (Token::Match(tokOffset2, "%type% ::")) + tokOffset2 = tokOffset2->tokAt(2); + } + // unhandled typedef, skip it and continue if (typeName->str() == "void") { unsupportedTypedef(typeDef); @@ -809,14 +818,12 @@ void Tokenizer::simplifyTypedef() } // function pointer - else if (Token::Match(tokOffset, "( * %name% ) (")) { + else if (Token::Match(tokOffset2, "* %name% ) (")) { // name token wasn't a name, it was part of the type typeEnd = typeEnd->next(); functionPtr = true; - tokOffset = tokOffset->next(); - funcStart = tokOffset; - funcEnd = tokOffset; - tokOffset = tokOffset->tokAt(3); + funcStart = funcEnd = tokOffset2; // * + tokOffset = tokOffset2->tokAt(3); // ( typeName = tokOffset->tokAt(-2); argStart = tokOffset; argEnd = tokOffset->link(); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 919b60d05..55a640425 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -2329,6 +2329,11 @@ private: const char expected5[] = "A c ;"; ASSERT_EQUALS(expected5, tok(code5)); + // #5614 + const char code5614[] = "typedef typename T::U V;\n" + "typedef typename T::W (V::*Fn)();\n"; + const char expected5614[] = ";"; + ASSERT_EQUALS(expected5614, tok(code5614)); } void simplifyTypedef112() { // ticket #6048