From a61f21d1b69a2cdc2bdba1aba53d49ce0efead94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Sun, 4 Feb 2018 09:48:37 +0100 Subject: [PATCH] Accept nested templates in tokenizer-simplify (#1070) The following snippet triggerd the error: template template auto ComposableParserImpl::operator|( T const &other ) const -> Parser { return Parser() | static_cast( *this ) | other; } Whenever simplifyFunctionParameters was called on a templated class' templated member function (and probably any nested template), the tokenizer would recognise it as a syntax error, assuming that return type *must* come after a template<> token. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2465f121e..6b1276c04 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8420,7 +8420,7 @@ const Token * Tokenizer::findGarbageCode() const for (const Token *tok = tokens(); tok; tok = tok->next()) { if (!Token::simpleMatch(tok, "template <")) continue; - if (tok->previous() && !Token::Match(tok->previous(), "[:;{})]")) + if (tok->previous() && !Token::Match(tok->previous(), "[:;{})>]")) return tok; const Token * const tok1 = tok; tok = tok->next()->findClosingBracket(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 24852f69d..43a94f4b5 100755 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -220,6 +220,7 @@ private: TEST_CASE(simplifyFunctionParameters1); // #3721 TEST_CASE(simplifyFunctionParameters2); // #4430 TEST_CASE(simplifyFunctionParameters3); // #4436 + TEST_CASE(simplifyFunctionParametersMultiTemplate); TEST_CASE(simplifyFunctionParametersErrors); TEST_CASE(removeParentheses1); // Ticket #61 @@ -3116,6 +3117,12 @@ private: ASSERT_EQUALS(code, tokenizeAndStringify(code)); } + void simplifyFunctionParametersMultiTemplate() { + const char code[] = "template < typename T1 > template < typename T2 > " + "void A < T1 > :: foo ( T2 ) { }"; + ASSERT_EQUALS(code, tokenizeAndStringify(code)); + } + void simplifyFunctionParametersErrors() { //same parameters... ASSERT_THROW(tokenizeAndStringify("void foo(x, x)\n"