Skip to content

Commit 7fc03c6

Browse files
IOBYTERobert Reif
andauthored
fix #10032 (Syntax error if first function in a struct is a template function) (danmar#2940)
Co-authored-by: Robert Reif <reif@FX6840>
1 parent c4190d1 commit 7fc03c6

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,10 @@ void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates()
357357
;
358358
else if (level == 0 && Token::Match(tok2->previous(), "%type%")) {
359359
// @todo add better expression detection
360-
if (!Token::Match(tok2->next(), "*| %type%|%num% ;"))
360+
if (!(Token::Match(tok2->next(), "*| %type%|%num% ;") ||
361+
Token::Match(tok2->next(), "*| %type% . %type% ;"))) {
361362
inclevel = true;
363+
}
362364
} else if (tok2->next() && tok2->next()->isStandardType() && !Token::Match(tok2->tokAt(2), "(|{"))
363365
inclevel = true;
364366
else if (Token::simpleMatch(tok2, "< typename"))

test/testsimplifytemplate.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class TestSimplifyTemplate : public TestFixture {
207207
TEST_CASE(template162);
208208
TEST_CASE(template163); // #9685 syntax error
209209
TEST_CASE(template164); // #9394
210+
TEST_CASE(template162); // #10032 syntax error
210211
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
211212
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
212213
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@@ -4161,6 +4162,22 @@ class TestSimplifyTemplate : public TestFixture {
41614162
ASSERT_EQUALS(exp, tok(code));
41624163
}
41634164

4165+
void template165() { // #10032 syntax error
4166+
const char code[] = "struct MyStruct {\n"
4167+
" template<class T>\n"
4168+
" bool operator()(const T& l, const T& r) const {\n"
4169+
" return l.first < r.first;\n"
4170+
" }\n"
4171+
"};";
4172+
const char exp[] = "struct MyStruct { "
4173+
"template < class T > "
4174+
"bool operator() ( const T & l , const T & r ) const { "
4175+
"return l . first < r . first ; "
4176+
"} "
4177+
"} ;";
4178+
ASSERT_EQUALS(exp, tok(code));
4179+
}
4180+
41644181
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
41654182
const char code[] = "template <typename T> struct C {};\n"
41664183
"template <typename T> struct S {a};\n"

0 commit comments

Comments
 (0)