1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 545957 - Fix for brace elision rule

Change-Id: Ie470c1d9a986beb1b177e3d3d571071f6ed1b8f8
Signed-off-by: Hannes Vogt <hannes@havogt.de>
This commit is contained in:
Hannes Vogt 2019-03-30 21:05:17 +01:00 committed by Nathan Ridge
parent fc45110844
commit c2779e8d3e
2 changed files with 22 additions and 10 deletions

View file

@ -13010,6 +13010,19 @@ public class AST2CPPTests extends AST2CPPTestBase {
parseAndCheckBindings();
}
// struct S1 {
// };
// struct S2 {
// S1 s1;
// };
// auto f() {
// auto s1 = S1 { };
// return S2 { s1 };
// }
public void testBraceElisionForAggregateInit7_545957() throws Exception {
parseAndCheckImplicitNameBindings();
}
// struct type{
// int a;
// };

View file

@ -66,24 +66,23 @@ class AggregateInitialization {
return checkInitializationFromDefaultMemberInitializer(nestedType, initialValue, worstCost);
worstCost = new Cost(fInitializers[fIndex].getType(), nestedType, Rank.IDENTITY);
if (fInitializers[fIndex].isInitializerList() || !isAggregate(nestedType)) { // no braces are elided
ICPPEvaluation initializer = fInitializers[fIndex];
Cost costWithoutElision = Conversions.checkImplicitConversionSequence(nestedType, initializer.getType(),
initializer.getValueCategory(), UDCMode.ALLOWED, Context.ORDINARY);
if (costWithoutElision.converts()) {
// p3: The elements of the initializer list are taken as initializers for the elements
// of the aggregate, in order.
ICPPEvaluation initializer = fInitializers[fIndex];
fIndex++;
Cost cost = Conversions.checkImplicitConversionSequence(nestedType, initializer.getType(),
initializer.getValueCategory(), UDCMode.ALLOWED, Context.ORDINARY);
if (!cost.converts()) {
return cost;
}
// [dcl.init.aggr] If the initializer-clause is an expression and a narrowing conversion is
// required to convert the expression, the program is ill-formed.
if (!(initializer instanceof EvalInitList) && cost.isNarrowingConversion()) {
if (!(initializer instanceof EvalInitList) && costWithoutElision.isNarrowingConversion()) {
return Cost.NO_CONVERSION;
}
if (cost.compareTo(worstCost) > 0) {
worstCost = cost;
if (costWithoutElision.compareTo(worstCost) > 0) {
worstCost = costWithoutElision;
}
} else if (fInitializers[fIndex].isInitializerList() || !isAggregate(nestedType)) { // cannot elide braces
return costWithoutElision; // doesn't convert
} else { // braces are elided: need to check on subaggregates
Cost cost = checkInitializationOfElements(nestedType, worstCost);
if (!cost.converts())