Partial fix #1464 (takes too long (days) to process some files)
Fix template functions that return "&T". http://sourceforge.net/apps/trac/cppcheck/ticket/1464
This commit is contained in:
parent
e207da18a2
commit
d881fd7a31
|
@ -1621,7 +1621,6 @@ void Tokenizer::simplifyTemplates()
|
|||
for (std::list<Token *>::iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1)
|
||||
{
|
||||
Token *tok = *iter1;
|
||||
|
||||
std::vector<std::string> type;
|
||||
for (tok = tok->tokAt(2); tok && tok->str() != ">"; tok = tok->next())
|
||||
{
|
||||
|
@ -1635,11 +1634,11 @@ void Tokenizer::simplifyTemplates()
|
|||
|
||||
// if this is a template function, get the position of the function name
|
||||
unsigned int pos = 0;
|
||||
if (Token::Match(tok, "> %type% *| %var% ("))
|
||||
if (Token::Match(tok, "> %type% *|&| %var% ("))
|
||||
pos = 2;
|
||||
else if (Token::Match(tok, "> %type% %type% *| %var% ("))
|
||||
else if (Token::Match(tok, "> %type% %type% *|&| %var% ("))
|
||||
pos = 3;
|
||||
if (pos > 0 && tok->tokAt(pos)->str() == "*")
|
||||
if (pos > 0 && (tok->tokAt(pos)->str() == "*" || tok->tokAt(pos)->str() == "&"))
|
||||
++pos;
|
||||
|
||||
if (_settings && _settings->_debug)
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
TEST_CASE(template16);
|
||||
TEST_CASE(template17);
|
||||
TEST_CASE(template18);
|
||||
TEST_CASE(template19);
|
||||
TEST_CASE(template_default_parameter);
|
||||
TEST_CASE(template_default_type);
|
||||
TEST_CASE(template_typename);
|
||||
|
@ -1508,6 +1509,26 @@ private:
|
|||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
|
||||
void template19()
|
||||
{
|
||||
const char code[] = "template <typename T> T & foo()\n"
|
||||
"{ static T temp; return temp; }\n"
|
||||
"\n"
|
||||
"void f ( )\n"
|
||||
"{\n"
|
||||
" char p = foo<char>();\n"
|
||||
"}\n";
|
||||
|
||||
// The expected result..
|
||||
const std::string expected("; "
|
||||
"void f ( ) "
|
||||
"{"
|
||||
" char p ; p = foo<char> ( ) ; "
|
||||
"} "
|
||||
"char & foo<char> ( ) { static char temp ; return temp ; }");
|
||||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
|
||||
void template_default_parameter()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue