From 3518e02d230214d1bfc6aadb5ced16f7d582010a Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 1 Mar 2014 14:55:57 +0100 Subject: [PATCH] Ticket #5506: Skip template parameters when determining whether a template is a declaration or a definition. --- lib/templatesimplifier.cpp | 3 ++- test/testtokenize.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index fc76f1360..90b789490 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -443,9 +443,10 @@ std::list TemplateSimplifier::getTemplateDeclarations(Token *tokens, bo tok = tok->linkAt(2); if (Token::simpleMatch(tok, "template <")) { + Token *parmEnd = tok->next()->findClosingBracket(); codeWithTemplates = true; - for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) { + for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) { // Just a declaration => ignore this if (tok2->str() == ";") break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 70d2925ba..32580e8c1 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -61,6 +61,7 @@ private: TEST_CASE(tokenize26); // #4245 (segmentation fault) TEST_CASE(tokenize27); // #4525 (segmentation fault) TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}") + TEST_CASE(tokenize29); // #5506 (segmentation fault upon invalid code) // don't freak out when the syntax is wrong TEST_CASE(wrong_syntax1); @@ -825,6 +826,11 @@ private: ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }")); } + // #5506 - segmentation fault upon invalid code + void tokenize29() { + tokenizeAndStringify("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;"); + } + void wrong_syntax1() { { const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");