Merge pull request #2683 from Ken-Patrick/cast_expandTemplate

Fix handling of c++ casts in template expansion
This commit is contained in:
Daniel Marjamäki 2020-06-17 09:21:01 +02:00 committed by GitHub
commit 51a6af299f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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() == ")")

View File

@ -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<longdouble> { } ;";
ASSERT_EQUALS(expected, tok(code));
}
void castInExpansion() {
const char code[] = "template <int N> class C { };\n"
"template <typename TC> class Base {};\n"
"template <typename TC> class Derived : private Base<TC> {};\n"
"typedef Derived<C<static_cast<int>(-1)> > C_;\n"
"class C3 { C_ c; };";
const char expected[] = "template < int N > class C { } ; "
"class Base<C<static_cast<int>-1>> ; "
"class Derived<C<static_cast<int>-1>> ; "
"class C3 { Derived<C<static_cast<int>-1>> c ; } ; "
"class Derived<C<static_cast<int>-1>> : private Base<C<static_cast<int>-1>> { } ; "
"class Base<C<static_cast<int>-1>> { } ;";
ASSERT_EQUALS(expected, tok(code));
}
};
REGISTER_TEST(TestSimplifyTemplate)