Merge pull request #422 from simartin/ticket_6023

Ticket #6023: Properly handle template'd default template parameter values
This commit is contained in:
PKEuS 2014-09-06 22:55:45 +02:00
commit 4859b55ce6
2 changed files with 13 additions and 1 deletions

View File

@ -600,11 +600,16 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
for (std::size_t i = (templatepar - eq.size()); it != eq.end() && i < usedpar; ++i)
++it;
while (it != eq.end()) {
int indentlevel = 0;
tok->insertToken(",");
tok = tok->next();
const Token *from = (*it)->next();
std::stack<Token *> links;
while (from && (!links.empty() || (from->str() != "," && from->str() != ">"))) {
while (from && (!links.empty() || (from->str() != "," && (indentlevel || from->str() != ">")))) {
if (from->str() == "<")
++indentlevel;
else if (from->str() == ">")
--indentlevel;
tok->insertToken(from->str(), from->originalName());
tok = tok->next();
if (Token::Match(tok, "(|["))

View File

@ -139,6 +139,7 @@ private:
TEST_CASE(template44); // #5297 - TemplateSimplifier::simplifyCalculations not eager enough
TEST_CASE(template45); // #5814 - syntax error reported for valid code
TEST_CASE(template46); // #5816 - syntax error reported for valid code
TEST_CASE(template47); // #6023 - syntax error reported for valid code
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2425,6 +2426,12 @@ private:
ASSERT_EQUALS("", errout.str());
}
void template47() { // #6023
tok("template <typename T1, typename T2 = T3<T1> > class C1 {}; "
"class C2 : public C1<C2> {};");
ASSERT_EQUALS("", errout.str());
}
void template_default_parameter() {
{
const char code[] = "template <class T, int n=3>\n"