1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

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>
This commit is contained in:
Hannes Vogt 2019-09-13 23:44:17 +02:00 committed by Nathan Ridge
parent aee38fb062
commit 944ec0e06e
3 changed files with 53 additions and 2 deletions

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2.cxx17;
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTestBase;
import junit.framework.TestSuite;
public class CXX17ExtensionsTests extends AST2CPPTestBase {
public static TestSuite suite() {
return suite(CXX17ExtensionsTests.class);
}
// struct Base {
// int foo;
// };
// struct MyStruct : public Base {
// int a;
// };
//
// int main() {
// MyStruct test = { {0}, 9 };
// }
public void testAggregateInitializationOfBaseClass_549367() throws Exception {
parseAndCheckImplicitNameBindings();
}
}

View file

@ -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);

View file

@ -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)