Fixed #3650 (Variable declaration: Doesn't handle template usage well)
This commit is contained in:
parent
37b98c2a56
commit
823fc9ac04
|
@ -5279,6 +5279,22 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
|
|||
while (tok2 && tok2->str() != "," && tok2->str() != ";") {
|
||||
if (tok2->str() == "{" || tok2->str() == "(" || tok2->str() == "[")
|
||||
tok2 = tok2->link();
|
||||
if (tok2->str() == "<" && TemplateSimplifier::templateParameters(tok2) > 0) {
|
||||
unsigned int level = 1;
|
||||
while (NULL != (tok2 = tok2->next())) {
|
||||
if (tok2->str() == "<")
|
||||
level++;
|
||||
else if (tok2->str() == ">") {
|
||||
if (level <= 1)
|
||||
break;
|
||||
--level;
|
||||
} else if (tok2->str() == ">>") {
|
||||
if (level <= 2)
|
||||
break;
|
||||
level -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
if (tok2 && tok2->str() == ";")
|
||||
|
|
|
@ -296,7 +296,8 @@ private:
|
|||
TEST_CASE(vardecl19);
|
||||
TEST_CASE(vardecl_stl_1);
|
||||
TEST_CASE(vardecl_stl_2);
|
||||
TEST_CASE(vardecl_template);
|
||||
TEST_CASE(vardecl_template_1);
|
||||
TEST_CASE(vardecl_template_2);
|
||||
TEST_CASE(vardecl_union);
|
||||
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
|
||||
TEST_CASE(volatile_variables);
|
||||
|
@ -4536,7 +4537,7 @@ private:
|
|||
ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }", tokenizeAndStringify(code2));
|
||||
}
|
||||
|
||||
void vardecl_template() {
|
||||
void vardecl_template_1() {
|
||||
// ticket #1046
|
||||
const char code1[] = "b<(1<<24),10,24> u, v;";
|
||||
const char res1[] = "b < ( 1 << 24 ) , 10 , 24 > u ; b < ( 1 << 24 ) , 10 , 24 > v ;";
|
||||
|
@ -4545,6 +4546,13 @@ private:
|
|||
tokenizeAndStringify("template <int i = (3>4) > class X4 {};");
|
||||
}
|
||||
|
||||
void vardecl_template_2() {
|
||||
// ticket #3650
|
||||
const char code[] = "const string str = x<8,int>();";
|
||||
const char expected[] = "const string str = x < 8 , int > ( ) ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void vardecl_union() {
|
||||
// ticket #1976
|
||||
const char code1[] = "class Fred { public: union { int a ; int b ; } ; } ;";
|
||||
|
|
Loading…
Reference in New Issue