Temporary fix for #994 (cppcheck cannot check my sources with segfaulting)

This commit is contained in:
Daniel Marjamäki 2009-11-22 13:38:45 +01:00
parent 7f6f41fd53
commit 9b397afeca
2 changed files with 53 additions and 0 deletions

View File

@ -983,6 +983,23 @@ void Tokenizer::simplifyTemplates()
}
const std::string type2(s);
if (type.size() != types2.size())
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok2->linenr();
loc.file = file(tok2);
locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList,
"error",
"Internal error: failed to instantiate template. The checking continues anyway.",
"internalError");
_errorLogger->reportErr(errmsg);
break;
}
// New classname/funcname..
const std::string name2(name + "<" + type2 + ">");

View File

@ -91,6 +91,7 @@ private:
TEST_CASE(template15);
TEST_CASE(template16);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
TEST_CASE(template_typename);
TEST_CASE(namespaces);
@ -1391,6 +1392,41 @@ private:
}
}
void template_default_type()
{
const char code[] = "template <typename T, typename U=T>\n"
"class A\n"
"{\n"
"public:\n"
" void foo() {\n"
" int a;\n"
" a = static_cast<U>(a);\n"
" }\n"
"};\n"
"\n"
"template <typename T>\n"
"class B\n"
"{\n"
"protected:\n"
" A<int> a;\n"
"};\n"
"\n"
"class C\n"
" : public B<int>\n"
"{\n"
"};\n";
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "file1.cpp");
tokenizer.simplifyTokenList();
ASSERT_EQUALS("[file1.cpp:15]: (error) Internal error: failed to instantiate template. The checking continues anyway.\n", errout.str());
TODO_ASSERT_EQUALS("", errout.str());
}
void template_typename()
{
const char code[] = "template <class T>\n"