diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 51bfd36ad..a92c9a130 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1986,6 +1986,9 @@ void TemplateSimplifier::expandTemplate( } else if (typeindentlevel > 0 && typetok->str() == ">" && brackets1.top()->str() == "<") { --typeindentlevel; brackets1.pop(); + } else if (Token::Match(typetok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <")) { + brackets1.push(typetok->next()); + ++typeindentlevel; } else if (typetok->str() == "(") ++typeindentlevel; else if (typetok->str() == ")") diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 77c268df6..eb520527c 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -256,6 +256,8 @@ private: TEST_CASE(template_variable_4); TEST_CASE(simplifyDecltype); + + TEST_CASE(castInExpansion); } std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) { @@ -5129,6 +5131,21 @@ private: "class type { } ;"; ASSERT_EQUALS(expected, tok(code)); } + + void castInExpansion() { + const char code[] = "template class C { };\n" + "template class Base {};\n" + "template class Derived : private Base {};\n" + "typedef Derived(-1)> > C_;\n" + "class C3 { C_ c; };"; + const char expected[] = "template < int N > class C { } ; " + "class Base-1>> ; " + "class Derived-1>> ; " + "class C3 { Derived-1>> c ; } ; " + "class Derived-1>> : private Base-1>> { } ; " + "class Base-1>> { } ;"; + ASSERT_EQUALS(expected, tok(code)); + } }; REGISTER_TEST(TestSimplifyTemplate)