diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 7f487f4a9..543c8f068 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -357,8 +357,10 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates() ; else if (level == 0 && Token::Match(tok2->previous(), "%type%")) { // @todo add better expression detection - if (!Token::Match(tok2->next(), "*| %type%|%num% ;")) + if (!(Token::Match(tok2->next(), "*| %type%|%num% ;") || + Token::Match(tok2->next(), "*| %type% . %type% ;"))) { inclevel = true; + } } else if (tok2->next() && tok2->next()->isStandardType() && !Token::Match(tok2->tokAt(2), "(|{")) inclevel = true; else if (Token::simpleMatch(tok2, "< typename")) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 32e766ad8..2bd5f203c 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -207,6 +207,7 @@ private: TEST_CASE(template162); TEST_CASE(template163); // #9685 syntax error TEST_CASE(template164); // #9394 + TEST_CASE(template162); // #10032 syntax error 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) @@ -4161,6 +4162,22 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template165() { // #10032 syntax error + const char code[] = "struct MyStruct {\n" + " template\n" + " bool operator()(const T& l, const T& r) const {\n" + " return l.first < r.first;\n" + " }\n" + "};"; + const char exp[] = "struct MyStruct { " + "template < class T > " + "bool operator() ( const T & l , const T & r ) const { " + "return l . first < r . first ; " + "} " + "} ;"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"