From f554a71dea83497ece285a65e35f5a892b54024d Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Fri, 29 Nov 2019 03:44:27 -0500 Subject: [PATCH] fix #9495 (Crash when parsing angle brackets in template with type traits (assertion failure)) (#2407) --- lib/templatesimplifier.cpp | 5 +++-- test/testsimplifytemplate.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index d4e4c22fa..653136f06 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -495,8 +495,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return numberOfParameters; else if (tok->str() == ">>" && level == 1) return numberOfParameters; - else if (tok->str() == "," && level == 0) { - ++numberOfParameters; + else if (tok->str() == ",") { + if (level == 0) + ++numberOfParameters; tok = tok->next(); } continue; diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 9fadc6467..0b064d6c1 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -191,6 +191,7 @@ private: TEST_CASE(template151); // crash TEST_CASE(template152); // #9467 TEST_CASE(template153); // #9483 + TEST_CASE(template154); // #9495 TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -2798,6 +2799,12 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template154() { // #9495 + const char code[] = "template ::value), int>> void i(S s);"; + const char exp[] = "template < typename S , enable_if_t < ( is_compile_string < S > :: value ) , int > > void i ( S s ) ;"; + ASSERT_EQUALS(exp, tok(code)); + } + void template116() { // #9178 { const char code[] = "template auto b() -> decltype(a{}.template b);\n" @@ -4379,6 +4386,8 @@ private: ASSERT_EQUALS(2U, templateParameters("template...Foo,template>>> x;")); ASSERT_EQUALS(3U, templateParameters("template...Foo,int,template>>> x;")); ASSERT_EQUALS(4U, templateParameters("template...Foo,int,template>>,int> x;")); + ASSERT_EQUALS(2U, templateParameters("template::value), int>> void i(S s);")); + ASSERT_EQUALS(2U, templateParameters("template> void e();")); } // Helper function to unit test TemplateSimplifier::getTemplateNamePosition