Skip to content

Commit 8d55d36

Browse files
committed
#8602 Template default parameter without name yields syntax error
1 parent c7993c3 commit 8d55d36

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ std::list<TemplateSimplifier::TokenAndName> TemplateSimplifier::getTemplateDecla
499499
if (!tok->tokAt(2))
500500
syntaxError(tok->next());
501501
if (tok->strAt(2)=="typename" &&
502-
!Token::Match(tok->tokAt(3), "%name%|.|,|>"))
502+
!Token::Match(tok->tokAt(3), "%name%|.|,|=|>"))
503503
syntaxError(tok->next());
504504
codeWithTemplates = true;
505505
Token *parmEnd = tok->next()->findClosingBracket();

test/testsimplifytemplate.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class TestSimplifyTemplate : public TestFixture {
130130

131131
// Test TemplateSimplifier::instantiateMatch
132132
TEST_CASE(instantiateMatch);
133+
TEST_CASE(templateParameterWithoutName); // #8602 Template default parameter without name yields syntax error
133134
}
134135

135136
std::string tok(const char code[], bool simplify = true, bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
@@ -1655,6 +1656,15 @@ class TestSimplifyTemplate : public TestFixture {
16551656
instantiateMatch("integral_constant < bool, sizeof ( ns :: ConvertHelper < From, To > :: Create ( ) ) > ;",
16561657
2, ":: %name% ("));
16571658
}
1659+
1660+
void templateParameterWithoutName()
1661+
{
1662+
ASSERT_EQUALS(1U, templateParameters("template<typename = void> struct s;"));
1663+
ASSERT_EQUALS(1U, templateParameters("template<template<typename = float> typename T> struct A {\n"
1664+
" void f();n"
1665+
" void g();\n"
1666+
"};n"));
1667+
}
16581668
};
16591669

16601670
REGISTER_TEST(TestSimplifyTemplate)

0 commit comments

Comments
 (0)