From aee38fb062025cf9d0d74c0d4f69bd05f064805c Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Fri, 13 Sep 2019 22:09:45 +0200 Subject: [PATCH] Bug 549036 - Init Type(std::initializer_list) from Type{...} Fix constructor calls of the form Type{...} to a constructor of the form Type(std::initializer_list). So far only Type({...}) was supported. Change-Id: I09e3b8c9c73c30e12c0c370a5c88885079a14746 Signed-off-by: Hannes Vogt --- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 14 ++++++++++++++ .../core/dom/parser/cpp/semantics/EvalTypeId.java | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 40f235a4f4b..adfb3bedc7c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -13405,4 +13405,18 @@ public class AST2CPPTests extends AST2CPPTestBase { public void testAggregateInitOfAnonymousUnion_549362() throws Exception { parseAndCheckImplicitNameBindings(); } + + // namespace std { + // template class initializer_list; + // } + // + // struct A { + // A(std::initializer_list list) + // {} + // }; + // + // auto a = A{1, 2}; + public void testClassFromInitList_549036() throws Exception { + parseAndCheckImplicitNameBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 85bd7612c16..291a175a599 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -300,8 +300,17 @@ public class EvalTypeId extends CPPDependentEvaluation { ICPPClassType classType = (ICPPClassType) simplifiedType; ICPPEvaluation[] arguments = fArguments; ICPPConstructor[] constructors = classType.getConstructors(); - if (arguments.length == 1 && arguments[0] instanceof EvalInitList && !fUsesBracedInitList) { + if (fUsesBracedInitList && arguments.length > 0) { // List-initialization of a class (dcl.init.list-3). + // e.g. A{1,2} + ICPPConstructor[] ctors = getInitializerListConstructors(constructors); + if (ctors.length != 0) { + constructors = ctors; + arguments = new EvalInitList[] { new EvalInitList(arguments, getTemplateDefinition()) }; + } + } else if (arguments.length == 1 && arguments[0] instanceof EvalInitList && !fUsesBracedInitList) { + // List-initialization of a class (dcl.init.list-3). + // e.g. A({1,2}) if (TypeTraits.isAggregateClass(classType)) { // Pretend that aggregate initialization is calling the default constructor. return findDefaultConstructor(classType, constructors);