Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java19
2 files changed, 22 insertions, 10 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 cc62e33d4a4..ee85ec451fb 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
@@ -12992,6 +12992,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;
// };
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
index d18585b19d5..292a6886bf7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
@@ -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())

Back to the top