fix #10032 (Syntax error if first function in a struct is a template function) (#2940)

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
IOBYTE 2020-12-11 01:01:20 -05:00 committed by GitHub
parent c4190d1741
commit 7fc03c6030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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"))

View File

@ -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 <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
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<class T>\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 <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"