Fix #9338 (Regression: Syntax error on valid C++) (#2156)

* Fix #9338 (Regression: Syntax error on valid C++)

* fix cppcheck warning
This commit is contained in:
IOBYTE 2019-09-09 15:46:21 -04:00 committed by Daniel Marjamäki
parent d20b1b2525
commit 639c29eb5c
2 changed files with 24 additions and 1 deletions

View File

@ -3494,6 +3494,14 @@ void TemplateSimplifier::simplifyTemplates(
const std::time_t maxtime,
bool &codeWithTemplates)
{
// convert "sizeof ..." to "sizeof..."
for (Token *tok = mTokenList.front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "sizeof ...")) {
tok->str("sizeof...");
tok->deleteNext();
}
}
// split ">>" into "> >"
fixAngleBrackets();

View File

@ -179,6 +179,7 @@ private:
TEST_CASE(template139);
TEST_CASE(template140);
TEST_CASE(template141); // #9337
TEST_CASE(template142); // #9338
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)
@ -3274,7 +3275,7 @@ private:
"template < class , template < class > class , class > struct e ; "
"template < class f , class g , class ... h > "
"using i = typename e < f , g :: template fn , h ... > :: d ; "
"template < class ... j > struct k : c < sizeof ... ( j ) , int > :: template fn < j ... > { } ;";
"template < class ... j > struct k : c < sizeof... ( j ) , int > :: template fn < j ... > { } ;";
ASSERT_EQUALS(exp, tok(code));
}
@ -3441,6 +3442,20 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template142() { // #9338
const char code[] = "template <typename...> struct a;\n"
"template <typename b, typename c, typename... d> struct a<b c::*, d...> {\n"
" using typename b ::e;\n"
" static_assert(e::f ? sizeof...(d) : sizeof...(d), \"\");\n"
"};";
const char exp[] = "template < typename ... > struct a ; "
"template < typename b , typename c , typename ... d > struct a < b c :: * , d ... > { "
"using b :: e ; "
"static_assert ( e :: f ? sizeof... ( d ) : sizeof... ( d ) , \"\" ) ; "
"} ;";
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"