Fixed ticket #387 (Templates: template functions that return a pointer are not simplified correctly)
This commit is contained in:
parent
2307395d6e
commit
be52e573f3
|
@ -571,13 +571,23 @@ void Tokenizer::simplifyTemplates()
|
|||
type.push_back(tok->str());
|
||||
}
|
||||
|
||||
// bail out if the end of the file was reached
|
||||
if (!tok)
|
||||
break;
|
||||
|
||||
// name of template function/class..
|
||||
const std::string name(tok->strAt(2));
|
||||
// if this is a template function, get the position of the function name
|
||||
unsigned int pos = 0;
|
||||
if (Token::Match(tok, "> %type% *| %var% ("))
|
||||
pos = 2;
|
||||
else if (Token::Match(tok, "> %type% %type% *| %var% ("))
|
||||
pos = 3;
|
||||
if (pos > 0 && tok->tokAt(pos)->str() == "*")
|
||||
++pos;
|
||||
|
||||
const bool isfunc(tok->strAt(3)[0] == '(');
|
||||
// name of template function/class..
|
||||
const std::string name(tok->strAt(pos > 0 ? pos : 2));
|
||||
|
||||
const bool isfunc(pos > 0);
|
||||
|
||||
// locate template usage..
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ private:
|
|||
TEST_CASE(template7);
|
||||
TEST_CASE(template8);
|
||||
TEST_CASE(template9);
|
||||
TEST_CASE(template10);
|
||||
|
||||
TEST_CASE(namespaces);
|
||||
|
||||
|
@ -826,6 +827,26 @@ private:
|
|||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
|
||||
void template10()
|
||||
{
|
||||
const char code[] = "template <int ui, typename T> T * foo()\n"
|
||||
"{ return new T[ui]; }\n"
|
||||
"\n"
|
||||
"void f ( )\n"
|
||||
"{\n"
|
||||
" foo<3,int>();\n"
|
||||
"}\n";
|
||||
|
||||
// The expected result..
|
||||
const std::string expected(" template < int ui , typename T > T * foo ( )"
|
||||
" { return new T [ ui ] ; }"
|
||||
" void f ( )"
|
||||
" {"
|
||||
" foo<3,int> ( ) ;"
|
||||
" }"
|
||||
" int * foo<3,int> ( ) { return new int [ 3 ] ; }");
|
||||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue