Fixed #2069 (cppcheck fails to scan OpenBSDs ftp source code)
This commit is contained in:
parent
365b1bed1a
commit
e4c3b390cc
|
@ -2225,6 +2225,20 @@ static void removeTemplates(Token *tok)
|
||||||
|
|
||||||
void Tokenizer::simplifyTemplates()
|
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..
|
// Remove "typename" unless used in template arguments..
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
|
|
@ -2022,13 +2022,33 @@ private:
|
||||||
|
|
||||||
void template_typename()
|
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..
|
// The expected result..
|
||||||
const std::string expected(";");
|
const std::string expected(";");
|
||||||
ASSERT_EQUALS(expected, sizeof_(code));
|
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()
|
void namespaces()
|
||||||
|
|
Loading…
Reference in New Issue