diff options
author | Hannes Vogt | 2019-09-13 20:09:45 +0000 |
---|---|---|
committer | Nathan Ridge | 2019-09-24 05:03:27 +0000 |
commit | aee38fb062025cf9d0d74c0d4f69bd05f064805c (patch) | |
tree | dcc125cea5d17d7884dcc3739c95c7d803811159 | |
parent | cf7e1f87c9b0a258c48b4fb3063d2aa4c37111fd (diff) | |
download | org.eclipse.cdt-aee38fb062025cf9d0d74c0d4f69bd05f064805c.tar.gz org.eclipse.cdt-aee38fb062025cf9d0d74c0d4f69bd05f064805c.tar.xz org.eclipse.cdt-aee38fb062025cf9d0d74c0d4f69bd05f064805c.zip |
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<T>).
So far only Type({...}) was supported.
Change-Id: I09e3b8c9c73c30e12c0c370a5c88885079a14746
Signed-off-by: Hannes Vogt <hannes@havogt.de>
2 files changed, 24 insertions, 1 deletions
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<typename T> class initializer_list; + // } + // + // struct A { + // A(std::initializer_list<int> 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); |