From 8d55d361ae428dc9fc44c424360835a263eb9b5b Mon Sep 17 00:00:00 2001 From: amai2012 Date: Wed, 30 May 2018 17:09:31 +0200 Subject: [PATCH] #8602 Template default parameter without name yields syntax error --- lib/templatesimplifier.cpp | 2 +- test/testsimplifytemplate.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0e621fa61..3a11cffe0 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -499,7 +499,7 @@ std::list 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(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index e9fdb6a32..4adebd3bf 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -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 struct s;")); + ASSERT_EQUALS(1U, templateParameters("template typename T> struct A {\n" + " void f();n" + " void g();\n" + "};n")); + } }; REGISTER_TEST(TestSimplifyTemplate)