Ticket #5823: Properly count template parameters in TemplateSimplifier::useDefaultArgumentValues and handle casts in template parameters' default values.

This commit is contained in:
Simon Martin 2014-05-23 23:38:40 +02:00
parent e1ad71dba5
commit 2b809800b6
2 changed files with 18 additions and 12 deletions

View File

@ -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<Token *> &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<Token *> &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<Token *>::const_iterator it = eq.begin();

View File

@ -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<typename T1 = T2 = typename = unused, T5 = = unused> struct tuple Args> tuple<Args...> { } main() { foo<int,int,int,int,int,int>(); }");
tokenizeAndStringify("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }");
tokenizeAndStringify("() template < T = typename = x > struct a {} { f <int> () }");
@ -6570,6 +6570,12 @@ private:
" static const int s = 0; "
"}; "
"A<int> a;");
tokenizeAndStringify("template<class T, class U> class A {}; "
"template<class T = A<int, int> > class B {}; "
"template<class T = B<int> > class C { "
" C() : _a(0), _b(0) {} "
" int _a, _b; "
"};");
}
void template_member_ptr() { // Ticket #5786