Fixed setVarId for nested templates (#3976, #3769) and support C++11 right angle brackets in TemplateSimplifier::templateParameters()
This commit is contained in:
parent
475f12eec3
commit
9fa7e15fb4
|
@ -168,7 +168,7 @@ const Token* TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(Token *to
|
||||||
|
|
||||||
unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
{
|
{
|
||||||
unsigned int numberOfParameters = 0;
|
unsigned int numberOfParameters = 1;
|
||||||
|
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -179,9 +179,6 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
|
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (level == 0)
|
|
||||||
++numberOfParameters;
|
|
||||||
|
|
||||||
// skip const
|
// skip const
|
||||||
if (Token::Match(tok, "const %any%"))
|
if (Token::Match(tok, "const %any%"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
@ -217,20 +214,26 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
if (tok->str() == "<") {
|
if (tok->str() == "<") {
|
||||||
++level;
|
++level;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ,/>
|
// ,/>
|
||||||
while (tok->str() == ">") {
|
while (tok->str() == ">" || tok->str() == ">>") {
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
return numberOfParameters;
|
return numberOfParameters;
|
||||||
--level;
|
--level;
|
||||||
|
if (tok->str() == ">>") {
|
||||||
|
if (level == 0)
|
||||||
|
return numberOfParameters;
|
||||||
|
--level;
|
||||||
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (tok->str() != ",")
|
if (tok->str() != ",")
|
||||||
break;
|
continue;
|
||||||
|
if (level == 0)
|
||||||
|
++numberOfParameters;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -224,6 +224,7 @@ private:
|
||||||
TEST_CASE(varid49); // #3799 - void f(std::vector<int>)
|
TEST_CASE(varid49); // #3799 - void f(std::vector<int>)
|
||||||
TEST_CASE(varid50); // #3760 - explicit
|
TEST_CASE(varid50); // #3760 - explicit
|
||||||
TEST_CASE(varid51); // don't set varid for template function
|
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(varid_cpp_keywords_in_c_code);
|
||||||
TEST_CASE(varidFunctionCall1);
|
TEST_CASE(varidFunctionCall1);
|
||||||
TEST_CASE(varidFunctionCall2);
|
TEST_CASE(varidFunctionCall2);
|
||||||
|
@ -3380,6 +3381,17 @@ private:
|
||||||
tokenizeDebugListing(code, false, "test.cpp"));
|
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() {
|
void varid_cpp_keywords_in_c_code() {
|
||||||
const char code[] = "void f() {\n"
|
const char code[] = "void f() {\n"
|
||||||
" delete d;\n"
|
" delete d;\n"
|
||||||
|
|
Loading…
Reference in New Issue