Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorHannes Vogt2019-03-30 16:05:17 -0400
committerNathan Ridge2019-03-30 19:10:09 -0400
commitc2779e8d3e2a57f9cc879d7bc3f1bf8e386dee54 (patch)
treed01d9caa29ab5dc3a7c7add8387a486ff1d6b5f3 /core
parentfc45110844ac22ab4726cc5360ccae8c677dbaf6 (diff)
downloadorg.eclipse.cdt-c2779e8d3e2a57f9cc879d7bc3f1bf8e386dee54.tar.gz
org.eclipse.cdt-c2779e8d3e2a57f9cc879d7bc3f1bf8e386dee54.tar.xz
org.eclipse.cdt-c2779e8d3e2a57f9cc879d7bc3f1bf8e386dee54.zip
Bug 545957 - Fix for brace elision rule
Change-Id: Ie470c1d9a986beb1b177e3d3d571071f6ed1b8f8 Signed-off-by: Hannes Vogt <hannes@havogt.de>
Diffstat (limited to 'core')
-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 37d4cb0e64..a1bdad7bcc 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
@@ -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;
// };
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 d18585b19d..292a6886bf 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