Fixed #2069 (cppcheck fails to scan OpenBSDs ftp source code)

This commit is contained in:
Daniel Marjamäki 2010-10-02 13:28:44 +02:00
parent 365b1bed1a
commit e4c3b390cc
2 changed files with 40 additions and 6 deletions

View File

@ -2225,6 +2225,20 @@ static void removeTemplates(Token *tok)
void Tokenizer::simplifyTemplates()
{
// Don't simplify C files
{
if (_files.empty())
return;
std::string::size_type pos = _files[0].rfind(".");
if (pos == std::string::npos)
return;
const std::string ext(_files[0].substr(pos));
if (ext == ".c" || ext == ".C")
return;
}
// Remove "typename" unless used in template arguments..
for (Token *tok = _tokens; tok; tok = tok->next())
{

View File

@ -2022,13 +2022,33 @@ private:
void template_typename()
{
const char code[] = "template <class T>\n"
"void foo(typename T::t *)\n"
"{ }";
{
const char code[] = "template <class T>\n"
"void foo(typename T::t *)\n"
"{ }";
// The expected result..
const std::string expected(";");
ASSERT_EQUALS(expected, sizeof_(code));
// The expected result..
const std::string expected(";");
ASSERT_EQUALS(expected, sizeof_(code));
}
{
const char code[] = "void f() {\n"
" x(sizeof typename);\n"
" type = 0;\n"
"}";
std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.c", "", false);
std::ostringstream ostr;
for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
{
ostr << tok1->str();
if (Token::Match(tok1, "%var% %var%"))
ostr << " ";
}
ASSERT_EQUALS("void f(){x(sizeof typename);type=0;}", ostr.str());
}
}
void namespaces()