Ticket #5823: Properly count template parameters in TemplateSimplifier::useDefaultArgumentValues and handle casts in template parameters' default values.
This commit is contained in:
parent
e1ad71dba5
commit
2b809800b6
|
@ -252,6 +252,13 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// Skip casts
|
||||||
|
if (tok->str() == "(") {
|
||||||
|
tok = tok->link();
|
||||||
|
if(tok)
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
|
||||||
// skip std::
|
// skip std::
|
||||||
if (tok && tok->str() == "::")
|
if (tok && tok->str() == "::")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -558,7 +565,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
|
||||||
}
|
}
|
||||||
|
|
||||||
// next template parameter
|
// next template parameter
|
||||||
if (tok->str() == ",")
|
if (tok->str() == "," && (1 == templateParmDepth)) // Ticket #5823: Properly count parameters
|
||||||
++templatepar;
|
++templatepar;
|
||||||
|
|
||||||
// default parameter value?
|
// default parameter value?
|
||||||
|
@ -583,17 +590,10 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// count the parameters..
|
// count the parameters..
|
||||||
unsigned int usedpar = 1;
|
tok = tok->next();
|
||||||
for (tok = tok->tokAt(3); tok; tok = tok->tokAt(2)) {
|
unsigned int usedpar = TemplateSimplifier::templateParameters(tok);
|
||||||
if (tok->str() == ">")
|
tok = tok->findClosingBracket();
|
||||||
break;
|
|
||||||
|
|
||||||
if (tok->str() == ",")
|
|
||||||
++usedpar;
|
|
||||||
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (tok && tok->str() == ">") {
|
if (tok && tok->str() == ">") {
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
std::list<Token *>::const_iterator it = eq.begin();
|
std::list<Token *>::const_iterator it = eq.begin();
|
||||||
|
|
|
@ -6554,7 +6554,7 @@ private:
|
||||||
tokenizer.tokenize(istr, "test.cpp"); // shouldn't segfault
|
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("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 < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }");
|
||||||
tokenizeAndStringify("() template < T = typename = x > struct a {} { f <int> () }");
|
tokenizeAndStringify("() template < T = typename = x > struct a {} { f <int> () }");
|
||||||
|
@ -6570,6 +6570,12 @@ private:
|
||||||
" static const int s = 0; "
|
" static const int s = 0; "
|
||||||
"}; "
|
"}; "
|
||||||
"A<int> a;");
|
"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
|
void template_member_ptr() { // Ticket #5786
|
||||||
|
|
Loading…
Reference in New Issue