Fixed #3706 (cppcheck 1.53 hangs when processing a certain template with specializations)
This commit is contained in:
parent
8afdde0b5e
commit
e534ee0426
|
@ -370,6 +370,10 @@ std::list<Token *> TemplateSimplifier::simplifyTemplatesGetTemplateDeclarations(
|
|||
{
|
||||
std::list<Token *> templates;
|
||||
for (Token *tok = tokens; tok; tok = tok->next()) {
|
||||
// TODO: handle namespaces. Right now we don't instantiate templates that are defined in namespaces.
|
||||
if (Token::Match(tok, "namespace %type% {"))
|
||||
tok = tok->tokAt(2)->link();
|
||||
|
||||
if (Token::simpleMatch(tok, "template <")) {
|
||||
codeWithTemplates = true;
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ private:
|
|||
TEST_CASE(template31); // #4010 - reference type
|
||||
TEST_CASE(template32); // #3818 - mismatching template not handled well
|
||||
TEST_CASE(template33); // #3818 - inner templates in template instantiation not handled well
|
||||
TEST_CASE(template34); // #3706 - namespace => hang
|
||||
TEST_CASE(template_unhandled);
|
||||
TEST_CASE(template_default_parameter);
|
||||
TEST_CASE(template_default_type);
|
||||
|
@ -2181,6 +2182,18 @@ private:
|
|||
"struct C<int> { A < B < X < int > > > ab ; }", tok(code));
|
||||
}
|
||||
|
||||
void template34() {
|
||||
// #3706 - namespace => hang
|
||||
const char code[] = "namespace abc {\n"
|
||||
"template <typename T> struct X { void f(X<T> &x) {} };\n"
|
||||
"}\n"
|
||||
"template <> int X<int>::Y(0);";
|
||||
ASSERT_EQUALS("namespace abc { "
|
||||
"template < typename T > struct X { void f ( X < T > & x ) { } } ; "
|
||||
"} "
|
||||
"template < > int X < int > :: Y ( 0 ) ;", tok(code));
|
||||
}
|
||||
|
||||
void template_unhandled() {
|
||||
// An unhandled template usage should be simplified..
|
||||
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));
|
||||
|
|
Loading…
Reference in New Issue