Merge pull request #2683 from Ken-Patrick/cast_expandTemplate
Fix handling of c++ casts in template expansion
This commit is contained in:
commit
51a6af299f
|
@ -1986,6 +1986,9 @@ void TemplateSimplifier::expandTemplate(
|
||||||
} else if (typeindentlevel > 0 && typetok->str() == ">" && brackets1.top()->str() == "<") {
|
} else if (typeindentlevel > 0 && typetok->str() == ">" && brackets1.top()->str() == "<") {
|
||||||
--typeindentlevel;
|
--typeindentlevel;
|
||||||
brackets1.pop();
|
brackets1.pop();
|
||||||
|
} else if (Token::Match(typetok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <")) {
|
||||||
|
brackets1.push(typetok->next());
|
||||||
|
++typeindentlevel;
|
||||||
} else if (typetok->str() == "(")
|
} else if (typetok->str() == "(")
|
||||||
++typeindentlevel;
|
++typeindentlevel;
|
||||||
else if (typetok->str() == ")")
|
else if (typetok->str() == ")")
|
||||||
|
|
|
@ -256,6 +256,8 @@ private:
|
||||||
TEST_CASE(template_variable_4);
|
TEST_CASE(template_variable_4);
|
||||||
|
|
||||||
TEST_CASE(simplifyDecltype);
|
TEST_CASE(simplifyDecltype);
|
||||||
|
|
||||||
|
TEST_CASE(castInExpansion);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
||||||
|
@ -5129,6 +5131,21 @@ private:
|
||||||
"class type<longdouble> { } ;";
|
"class type<longdouble> { } ;";
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
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)
|
REGISTER_TEST(TestSimplifyTemplate)
|
||||||
|
|
Loading…
Reference in New Issue