From 8091626ee4ead0845d5ef1cb56c0275b88544358 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Mon, 9 Oct 2023 18:57:05 +0300 Subject: [PATCH] Allow aggregate initialization in template body --- .../cdt/core/parser/tests/ast2/AST2TemplateTests.java | 10 ++++++++++ .../parser/cpp/semantics/AggregateInitialization.java | 6 +++++- 2 files changed, 15 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 e2a6fbaf2f7..69d883daa88 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 @@ -11607,4 +11607,14 @@ public class AST2TemplateTests extends AST2CPPTestBase { public void testRecognizeConstructorWithSemicolonAfterBody() throws Exception { parseAndCheckImplicitNameBindings(); } + + // template + // void f() { + // struct S { + // T t; + // } s {}; + // }; + public void testAllowAggregateInitializationInTemplateBody() throws Exception { + parseAndCheckImplicitNameBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java index 0f6eae40b77..c4dde1cd9e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java @@ -64,7 +64,11 @@ class AggregateInitialization { * else recurses into the subaggregate. */ private Cost checkElement(IType type, IValue initialValue, Cost worstCost) throws DOMException { - assert !CPPTemplates.isDependentType(type); + if (CPPTemplates.isDependentType(type)) { + // We can only get here looking for initialization constructor while scanning for implicit names. + // Return trivial conversion cost and no constructor because type is unknown at this point. + return new Cost(type, type, Rank.IDENTITY); + } IType nestedType = SemanticUtil.getNestedType(type, SemanticUtil.TDEF); if (fIndex >= fInitializers.length) // TODO for arrays we could short-circuit default init instead of trying to init each element