Fix #11763 internalAstError caused by parameter pack simplification (#5150)

This commit is contained in:
chrchr-github 2023-06-17 11:31:02 +02:00 committed by GitHub
parent 9a290c959f
commit 7075b6e61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -2059,6 +2059,8 @@ void TemplateSimplifier::expandTemplate(
Token * const beforeTypeToken = mTokenList.back();
bool pointerType = false;
const bool isVariadicTemplateArg = templateDeclaration.isVariadic() && itype + 1 == typeParametersInDeclaration.size();
if (isVariadicTemplateArg && mTypesUsedInTemplateInstantiation.size() > 1 && !Token::simpleMatch(tok3->next(), "..."))
continue;
if (isVariadicTemplateArg && Token::Match(tok3, "%name% ... %name%"))
tok3 = tok3->tokAt(2);
const std::string endStr(isVariadicTemplateArg ? ">" : ",>");

View File

@ -279,6 +279,7 @@ private:
TEST_CASE(template_variadic_1); // #9144
TEST_CASE(template_variadic_2); // #4349
TEST_CASE(template_variadic_3); // #6172
TEST_CASE(template_variadic_4);
TEST_CASE(template_variable_1);
TEST_CASE(template_variable_2);
@ -6133,6 +6134,25 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void template_variadic_4() { // #11763
const char code[] = "template <int... N>\n"
"class E {\n"
" template <int... I>\n"
" int f(int n, std::integer_sequence<int, I...>) {\n"
" return (((I == n) ? N : 0) + ...);\n"
" }\n"
"};\n"
"E<1, 3> e;\n";
const char expected[] = "class E<1,3> ; E<1,3> e ; "
"class E<1,3> { "
"template < int ... I > "
"int f ( int n , std :: integer_sequence < int , I ... > ) { "
"return ( ( ( I == n ) ? : 0 ) + ... ) ; "
"} "
"} ;";
ASSERT_EQUALS(expected, tok(code));
}
void template_variable_1() {
{
const char code[] = "template <int N> const int foo = N*N;\n"