1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

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>
This commit is contained in:
Hannes Vogt 2019-09-13 22:09:45 +02:00 committed by Nathan Ridge
parent cf7e1f87c9
commit aee38fb062
2 changed files with 24 additions and 1 deletions

View file

@ -13405,4 +13405,18 @@ public class AST2CPPTests extends AST2CPPTestBase {
public void testAggregateInitOfAnonymousUnion_549362() throws Exception { public void testAggregateInitOfAnonymousUnion_549362() throws Exception {
parseAndCheckImplicitNameBindings(); 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();
}
} }

View file

@ -300,8 +300,17 @@ public class EvalTypeId extends CPPDependentEvaluation {
ICPPClassType classType = (ICPPClassType) simplifiedType; ICPPClassType classType = (ICPPClassType) simplifiedType;
ICPPEvaluation[] arguments = fArguments; ICPPEvaluation[] arguments = fArguments;
ICPPConstructor[] constructors = classType.getConstructors(); 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). // 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)) { if (TypeTraits.isAggregateClass(classType)) {
// Pretend that aggregate initialization is calling the default constructor. // Pretend that aggregate initialization is calling the default constructor.
return findDefaultConstructor(classType, constructors); return findDefaultConstructor(classType, constructors);