From daad877559bfd72e3f7ed64e11fd98e495cdec3c Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 31 Oct 2017 18:55:39 -0400 Subject: [PATCH] Bug 526684 - Use InstantiationContext.setExpandPack() in CPPTemplates.instantiateTypes() if appropriate InstantiationContext.setExpandPack() and related methods were introduced in bug 486971 to ensure that when instantiating a type list that contains a pack expansion, with a parameter map that maps the template parameter pack that appears in the expansion to another parameter pack (which can happen when e.g. instantiating an alias template with dependent arguments), the pack is expanded in the correct place. However, bug 486971 only added use of this machinery to CPPTemplates. instantiateArguments(). We can also instantiate a type list in instantiateTypes() (used e.g. when instantiating the parameter types of a function type), so the machinery needs to be used there as well. Change-Id: Iabb458e8e3166c15ed922656fc0729a4a8cf8bbf --- .../parser/tests/ast2/AST2TemplateTests.java | 18 ++++++++++++++++++ .../dom/parser/cpp/semantics/CPPTemplates.java | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index ef03eefa2bc..c26b40da2c0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -9017,6 +9017,24 @@ public class AST2TemplateTests extends AST2CPPTestBase { public void testDecltypeInPackExpansion_486425b() throws Exception { parseAndCheckBindings(); } + + // template + // class meta { + // typedef T type; + // }; + // + // template + // using Alias = void(typename meta::type...); + // + // template + // Alias* async(Ts...); + // + // int main() { + // async(); // ERROR: Invalid arguments + // } + public void testDependentPackExpansionInFunctionType_526684() throws Exception { + parseAndCheckBindings(); + } // template // struct A {}; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index afb93a6fa51..5ae163e256a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1304,12 +1304,21 @@ public class CPPTemplates { IType[] newResult= new IType[result.length + packSize - 1]; System.arraycopy(result, 0, newResult, 0, j); result= newResult; + context.setExpandPack(true); int oldPackOffset = context.getPackOffset(); for (int k= 0; k < packSize; k++) { context.setPackOffset(k); - result[j++]= instantiateType(innerType, context); + IType instantiated = instantiateType(innerType, context); + if (context.isPackExpanded()) { + if (instantiated != null) { + instantiated = new CPPParameterPackType(instantiated); + } + } + result[j++]= instantiated; + } context.setPackOffset(oldPackOffset); + context.setExpandPack(false); continue; } } else {