#8602 Template default parameter without name yields syntax error

This commit is contained in:
amai2012 2018-05-30 17:09:31 +02:00
parent c7993c38b5
commit 8d55d361ae
2 changed files with 11 additions and 1 deletions

View File

@ -499,7 +499,7 @@ std::list<TemplateSimplifier::TokenAndName> TemplateSimplifier::getTemplateDecla
if (!tok->tokAt(2))
syntaxError(tok->next());
if (tok->strAt(2)=="typename" &&
!Token::Match(tok->tokAt(3), "%name%|.|,|>"))
!Token::Match(tok->tokAt(3), "%name%|.|,|=|>"))
syntaxError(tok->next());
codeWithTemplates = true;
Token *parmEnd = tok->next()->findClosingBracket();

View File

@ -130,6 +130,7 @@ private:
// Test TemplateSimplifier::instantiateMatch
TEST_CASE(instantiateMatch);
TEST_CASE(templateParameterWithoutName); // #8602 Template default parameter without name yields syntax error
}
std::string tok(const char code[], bool simplify = true, bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
@ -1655,6 +1656,15 @@ private:
instantiateMatch("integral_constant < bool, sizeof ( ns :: ConvertHelper < From, To > :: Create ( ) ) > ;",
2, ":: %name% ("));
}
void templateParameterWithoutName()
{
ASSERT_EQUALS(1U, templateParameters("template<typename = void> struct s;"));
ASSERT_EQUALS(1U, templateParameters("template<template<typename = float> typename T> struct A {\n"
" void f();n"
" void g();\n"
"};n"));
}
};
REGISTER_TEST(TestSimplifyTemplate)