Fixed #1476 (false positive: Uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2010-03-16 19:53:09 +01:00
parent 235404077f
commit 12c45a1aba
3 changed files with 39 additions and 0 deletions

View File

@ -1257,6 +1257,12 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
// Handle templates..
simplifyTemplates();
// Simplify templates.. sometimes the "simplifyTemplates" fail and
// then unsimplified function calls etc remain. These have the
// "wrong" syntax. So this function will just fix so that the
// syntax is corrected.
simplifyTemplates2();
// Simplify the operator "?:"
simplifyConditionOperator();
@ -1910,6 +1916,25 @@ void Tokenizer::simplifyTemplates()
}
//---------------------------------------------------------------------------
void Tokenizer::simplifyTemplates2()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "(")
tok = tok->link();
else if (Token::Match(tok, "; %type% < %type% > ("))
{
tok = tok->next();
tok->str(tok->str() + "<" + tok->strAt(2) + ">");
tok->deleteNext();
tok->deleteNext();
tok->deleteNext();
}
}
}
//---------------------------------------------------------------------------
std::string Tokenizer::getNameForFunctionParams(const Token *start)
{
if (start->next() == start->link())

View File

@ -324,6 +324,13 @@ private:
*/
void simplifyTemplates();
/**
* Used after simplifyTemplates to perform a little cleanup.
* Sometimes the simplifyTemplates isn't fully successful and then
* there are function calls etc with "wrong" syntax.
*/
void simplifyTemplates2();
/**
* Simplify e.g. 'atol("0")' into '0'
*/

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(template17);
TEST_CASE(template18);
TEST_CASE(template19);
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
TEST_CASE(template_typename);
@ -1539,6 +1540,12 @@ private:
ASSERT_EQUALS(expected, sizeof_(code));
}
void template_unhandled()
{
// An unhandled template usage should be simplified..
ASSERT_EQUALS("; x<int> ( ) ;", sizeof_(";x<int>();"));
}
void template_default_parameter()
{
{