1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Allow aggregate initialization in template body

This commit is contained in:
Igor V. Kovalenko 2023-10-09 18:57:05 +03:00 committed by Jonah Graham
parent 84322c30f4
commit 8091626ee4
2 changed files with 15 additions and 1 deletions

View file

@ -11607,4 +11607,14 @@ public class AST2TemplateTests extends AST2CPPTestBase {
public void testRecognizeConstructorWithSemicolonAfterBody() throws Exception {
parseAndCheckImplicitNameBindings();
}
// template<typename T>
// void f() {
// struct S {
// T t;
// } s {};
// };
public void testAllowAggregateInitializationInTemplateBody() throws Exception {
parseAndCheckImplicitNameBindings();
}
}

View file

@ -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