Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorHannes Vogt2019-10-02 05:45:51 +0000
committerHannes Vogt2019-10-02 05:51:46 +0000
commitb52b03a9bc25469d062a19fbf734efd8f369c058 (patch)
treec975ff4c31cc56e18f452d396b7ae3bcc549ee85 /core
parent944ec0e06edcf5869b5af2322da7dd863f3b2dc9 (diff)
downloadorg.eclipse.cdt-b52b03a9bc25469d062a19fbf734efd8f369c058.tar.gz
org.eclipse.cdt-b52b03a9bc25469d062a19fbf734efd8f369c058.tar.xz
org.eclipse.cdt-b52b03a9bc25469d062a19fbf734efd8f369c058.zip
Revert "Bug 549362 - Aggregate init for union-like classes"
This reverts commit 9a6fd2ab976b90a2f41004cfa5c8f716348510d3. A proper implementation is needed to resolve bug 551610. Change-Id: I1ea353ea905a33dc43ceda59dde93c15de2032cd 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.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java57
2 files changed, 14 insertions, 55 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 adfb3bedc7c..bb6cb8876b0 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
@@ -13394,18 +13394,6 @@ public class AST2CPPTests extends AST2CPPTestBase {
bh.assertImplicitName("t{1};", 1, IProblemBinding.class);
}
- // struct MyStruct {
- // union {
- // int num;
- // };
- // };
- // int main() {
- // MyStruct test = { 0 };
- // }
- public void testAggregateInitOfAnonymousUnion_549362() throws Exception {
- parseAndCheckImplicitNameBindings();
- }
-
// namespace std {
// template<typename T> class initializer_list;
// }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java
index c8654abdcd4..a03884ceac6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java
@@ -239,28 +239,11 @@ public class ClassTypeHelper {
IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers();
for (IASTDeclaration decl : decls) {
if (decl instanceof IASTSimpleDeclaration) {
- IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) decl;
- IASTDeclarator[] dtors = simpleDecl.getDeclarators();
- if (dtors.length == 0) {
- // check for union-like classes [class.union.anon]
- ICPPClassType nestedClass = getNestedClass(simpleDecl);
- if (nestedClass != null && nestedClass.getName().length() == 0) {
- if (nestedClass.getFields().length > 0) {
- // TODO(havogt): Here we add only the first field of the anonymous union to the result
- // (as needed for aggregate initialization, see [dcl.init.aggr](c++17)p.16).
- // A proper solution will probably need to return a new implementation of ICPPField for anonymous unions.
- // TODO(havogt): This branch is also taken for anonymous structs (GNU extension), in that case
- // it should add all fields of the anonymous struct.
- binding = nestedClass.getFields()[0];
- result = ArrayUtil.appendAt(result, resultSize++, (ICPPField) binding);
- }
- }
- } else {
- for (IASTDeclarator dtor : dtors) {
- binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
- if (binding instanceof ICPPField)
- result = ArrayUtil.appendAt(result, resultSize++, (ICPPField) binding);
- }
+ IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
+ for (IASTDeclarator dtor : dtors) {
+ binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
+ if (binding instanceof ICPPField)
+ result = ArrayUtil.appendAt(result, resultSize++, (ICPPField) binding);
}
} else if (decl instanceof ICPPASTUsingDeclaration) {
IASTName n = ((ICPPASTUsingDeclaration) decl).getName();
@@ -277,7 +260,6 @@ public class ClassTypeHelper {
}
}
return ArrayUtil.trim(result, resultSize);
-
}
/**
@@ -569,23 +551,6 @@ public class ClassTypeHelper {
return true;
}
- /**
- * @param decl
- * @return if decl declares a nested class: return the class; else return null.
- */
- public static ICPPClassType getNestedClass(IASTSimpleDeclaration decl) {
- IBinding binding = null;
- IASTDeclSpecifier declSpec = decl.getDeclSpecifier();
- if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
- binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding();
- } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && decl.getDeclarators().length == 0) {
- binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding();
- }
- if (binding instanceof ICPPClassType)
- return (ICPPClassType) binding;
- return null;
- }
-
public static ICPPClassType[] getNestedClasses(ICPPInternalClassTypeMixinHost host) {
if (host.getDefinition() == null) {
host.checkForDefinition();
@@ -606,10 +571,16 @@ public class ClassTypeHelper {
while (decl instanceof ICPPASTTemplateDeclaration)
decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) {
- ICPPClassType nestedClass = getNestedClass((IASTSimpleDeclaration) decl);
- if (nestedClass != null) {
- result = ArrayUtil.appendAt(result, resultSize++, nestedClass);
+ IBinding binding = null;
+ IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier();
+ if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
+ binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding();
+ } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier
+ && ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) {
+ binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding();
}
+ if (binding instanceof ICPPClassType)
+ result = ArrayUtil.appendAt(result, resultSize++, (ICPPClassType) binding);
}
}
return ArrayUtil.trim(result, resultSize);

Back to the top