Fixed setVarId for nested templates (#3976, #3769) and support C++11 right angle brackets in TemplateSimplifier::templateParameters()

This commit is contained in:
PKEuS 2012-08-26 09:49:38 +02:00
parent 475f12eec3
commit 9fa7e15fb4
2 changed files with 22 additions and 7 deletions

View File

@ -168,7 +168,7 @@ const Token* TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(Token *to
unsigned int TemplateSimplifier::templateParameters(const Token *tok)
{
unsigned int numberOfParameters = 0;
unsigned int numberOfParameters = 1;
if (!tok)
return 0;
@ -179,9 +179,6 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
unsigned int level = 0;
while (tok) {
if (level == 0)
++numberOfParameters;
// skip const
if (Token::Match(tok, "const %any%"))
tok = tok->next();
@ -217,20 +214,26 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
if (tok->str() == "<") {
++level;
tok = tok->next();
continue;
}
// ,/>
while (tok->str() == ">") {
while (tok->str() == ">" || tok->str() == ">>") {
if (level == 0)
return numberOfParameters;
--level;
if (tok->str() == ">>") {
if (level == 0)
return numberOfParameters;
--level;
}
tok = tok->next();
if (!tok)
return 0;
}
if (tok->str() != ",")
break;
continue;
if (level == 0)
++numberOfParameters;
tok = tok->next();
}
return 0;

View File

@ -224,6 +224,7 @@ private:
TEST_CASE(varid49); // #3799 - void f(std::vector<int>)
TEST_CASE(varid50); // #3760 - explicit
TEST_CASE(varid51); // don't set varid for template function
TEST_CASE(varid52); // Set varid for nested templates
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
@ -3380,6 +3381,17 @@ private:
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid52() {
const std::string code("A<B<C>::D> e;\n"
"B< C<> > b[10];\n"
"B<C<>> c[10];");
ASSERT_EQUALS("\n\n##file 0\n"
"1: A < B < C > :: D > e@1 ;\n"
"2: B < C < > > b@2 [ 10 ] ;\n"
"3: B < C < > > c@3 [ 10 ] ;\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"