Fix #9337 (Syntax error on valid C++) (#2152)

This commit is contained in:
IOBYTE 2019-09-07 03:09:04 -04:00 committed by Daniel Marjamäki
parent 92ab7c6b92
commit 59fdbd8435
2 changed files with 14 additions and 1 deletions

View File

@ -366,7 +366,7 @@ 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% ;"))
inclevel = true;
} else if (tok2->next() && tok2->next()->isStandardType())
inclevel = true;

View File

@ -178,6 +178,7 @@ private:
TEST_CASE(template138);
TEST_CASE(template139);
TEST_CASE(template140);
TEST_CASE(template141); // #9337
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)
@ -3428,6 +3429,18 @@ private:
}
}
void template141() { // #9337
const char code[] = "struct a {\n"
" int c;\n"
" template <typename b> void d(b e) const { c < *e; }\n"
"};";
const char exp[] = "struct a { "
"int c ; "
"template < typename b > void d ( b e ) const { c < * e ; } "
"} ;";
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"