Accept nested templates in tokenizer-simplify (#1070)

The following snippet triggerd the error:

template<typename DerivedT>
template<typename T>
auto ComposableParserImpl<DerivedT>::operator|( T const &other ) const -> Parser {
    return Parser() | static_cast<DerivedT const &>( *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.
This commit is contained in:
Jørgen Kvalsvik 2018-02-04 09:48:37 +01:00 committed by Daniel Marjamäki
parent d47b7726fa
commit a61f21d1b6
2 changed files with 8 additions and 1 deletions

View File

@ -8420,7 +8420,7 @@ const Token * Tokenizer::findGarbageCode() const
for (const Token *tok = tokens(); tok; tok = tok->next()) { for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (!Token::simpleMatch(tok, "template <")) if (!Token::simpleMatch(tok, "template <"))
continue; continue;
if (tok->previous() && !Token::Match(tok->previous(), "[:;{})]")) if (tok->previous() && !Token::Match(tok->previous(), "[:;{})>]"))
return tok; return tok;
const Token * const tok1 = tok; const Token * const tok1 = tok;
tok = tok->next()->findClosingBracket(); tok = tok->next()->findClosingBracket();

View File

@ -220,6 +220,7 @@ private:
TEST_CASE(simplifyFunctionParameters1); // #3721 TEST_CASE(simplifyFunctionParameters1); // #3721
TEST_CASE(simplifyFunctionParameters2); // #4430 TEST_CASE(simplifyFunctionParameters2); // #4430
TEST_CASE(simplifyFunctionParameters3); // #4436 TEST_CASE(simplifyFunctionParameters3); // #4436
TEST_CASE(simplifyFunctionParametersMultiTemplate);
TEST_CASE(simplifyFunctionParametersErrors); TEST_CASE(simplifyFunctionParametersErrors);
TEST_CASE(removeParentheses1); // Ticket #61 TEST_CASE(removeParentheses1); // Ticket #61
@ -3116,6 +3117,12 @@ private:
ASSERT_EQUALS(code, tokenizeAndStringify(code)); 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() { void simplifyFunctionParametersErrors() {
//same parameters... //same parameters...
ASSERT_THROW(tokenizeAndStringify("void foo(x, x)\n" ASSERT_THROW(tokenizeAndStringify("void foo(x, x)\n"