diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2530,12 +2530,13 @@ // If we should expand this pack expansion now, do so. if (ShouldExpand) { for (unsigned I = 0; I != *NumExpansions; ++I) { + { Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); - TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), - TemplateArgs, - Base.getSourceRange().getBegin(), - DeclarationName()); + BaseTypeLoc = + SubstType(Base.getTypeSourceInfo(), TemplateArgs, + Base.getSourceRange().getBegin(), DeclarationName()); + } if (!BaseTypeLoc) { Invalid = true; continue; diff --git a/clang/test/SemaCXX/template-base-class-pack-expansion.cpp b/clang/test/SemaCXX/template-base-class-pack-expansion.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/template-base-class-pack-expansion.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s +// Don't crash (#53609). + +// expected-no-diagnostics + +template struct a; + +template struct b; +template +struct b...> {}; + +template struct c: b... {}; + +c d;