From 2b809800b60bfaa02ae31b31693558821e4a058b Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Fri, 23 May 2014 23:38:40 +0200 Subject: [PATCH] Ticket #5823: Properly count template parameters in TemplateSimplifier::useDefaultArgumentValues and handle casts in template parameters' default values. --- lib/templatesimplifier.cpp | 22 +++++++++++----------- test/testtokenize.cpp | 8 +++++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0384ad351..3e9715e91 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -252,6 +252,13 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) if (!tok) return 0; + // Skip casts + if (tok->str() == "(") { + tok = tok->link(); + if(tok) + tok = tok->next(); + } + // skip std:: if (tok && tok->str() == "::") tok = tok->next(); @@ -558,7 +565,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp } // next template parameter - if (tok->str() == ",") + if (tok->str() == "," && (1 == templateParmDepth)) // Ticket #5823: Properly count parameters ++templatepar; // default parameter value? @@ -583,17 +590,10 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp continue; // count the parameters.. - unsigned int usedpar = 1; - for (tok = tok->tokAt(3); tok; tok = tok->tokAt(2)) { - if (tok->str() == ">") - break; + tok = tok->next(); + unsigned int usedpar = TemplateSimplifier::templateParameters(tok); + tok = tok->findClosingBracket(); - if (tok->str() == ",") - ++usedpar; - - else - break; - } if (tok && tok->str() == ">") { tok = tok->previous(); std::list::const_iterator it = eq.begin(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f95460d9c..5ab34f5be 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6554,7 +6554,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); // shouldn't segfault } - void syntax_error_templates_3() { // Ticket #5605, #5759, #5762, #5774 + void syntax_error_templates_3() { // Ticket #5605, #5759, #5762, #5774, #5823 tokenizeAndStringify("foo() template struct tuple Args> tuple { } main() { foo(); }"); tokenizeAndStringify("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"); tokenizeAndStringify("() template < T = typename = x > struct a {} { f () }"); @@ -6570,6 +6570,12 @@ private: " static const int s = 0; " "}; " "A a;"); + tokenizeAndStringify("template class A {}; " + "template > class B {}; " + "template > class C { " + " C() : _a(0), _b(0) {} " + " int _a, _b; " + "};"); } void template_member_ptr() { // Ticket #5786