diff options
author | Hannes Vogt | 2019-09-13 21:44:17 +0000 |
---|---|---|
committer | Nathan Ridge | 2019-09-26 04:12:11 +0000 |
commit | 944ec0e06edcf5869b5af2322da7dd863f3b2dc9 (patch) | |
tree | a9e6d9577006fbd96afb5fb80028f2f4f0ccb8a8 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core | |
parent | aee38fb062025cf9d0d74c0d4f69bd05f064805c (diff) | |
download | org.eclipse.cdt-944ec0e06edcf5869b5af2322da7dd863f3b2dc9.tar.gz org.eclipse.cdt-944ec0e06edcf5869b5af2322da7dd863f3b2dc9.tar.xz org.eclipse.cdt-944ec0e06edcf5869b5af2322da7dd863f3b2dc9.zip |
Bug 549367 - [C++17] Aggregate init of base
Implements http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0017r1.html:
Types with non-private, non-protected, non-virtual base classes can be
aggregate initialized.
Change-Id: Idad341d45d6aaf1d8c36691cf8d7bc7cd049e28b
Signed-off-by: Hannes Vogt <hannes@havogt.de>
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core')
2 files changed, 19 insertions, 2 deletions
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 71790051d2e..49798f6f32c 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 @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; @@ -131,6 +132,15 @@ class AggregateInitialization { */ private Cost checkInitializationOfElements(IType type, Cost worstCost) throws DOMException { if (type instanceof ICPPClassType && isAggregate(type)) { + ICPPBase[] bases = ((ICPPClassType) type).getBases(); + for (ICPPBase base : bases) { + Cost cost = checkElement(base.getBaseClassType(), null, worstCost); + if (!cost.converts()) + return cost; + if (cost.compareTo(worstCost) > 0) { + worstCost = cost; + } + } ICPPField[] fields = getFieldsForAggregateInitialization((ICPPClassType) type); for (ICPPField field : fields) { Cost cost = checkElement(field.getType(), field.getInitialValue(), worstCost); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java index cbba16a0c70..07b7aee8e91 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeTraits.java @@ -271,8 +271,15 @@ public class TypeTraits { // 8.1.5.1 p.2 (N4659): The closure type is not an aggregate type. if (classType instanceof CPPClosureType) return false; - if (classType.getBases().length > 0) - return false; + if (classType.getBases().length > 0) { + // c++17 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0017r1.html + for (ICPPBase base : classType.getBases()) { + if (base.isVirtual()) + return false; + if (base.getVisibility() == ICPPBase.v_private || base.getVisibility() == ICPPBase.v_protected) + return false; + } + } ICPPMethod[] methods = classType.getDeclaredMethods(); for (ICPPMethod m : methods) { if (m instanceof ICPPConstructor) |