Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2019-06-29 02:44:22 -0400
committerNathan Ridge2019-06-29 02:44:22 -0400
commit451fa86e3557e8be5617f85d7a980c7fb0a53ce7 (patch)
treec4fc32f2ca35245813e59d66c7612ce05fc0c486 /core
parent996d7193c045c75c7cb4ec7b4482f24a116de75b (diff)
downloadorg.eclipse.cdt-451fa86e3557e8be5617f85d7a980c7fb0a53ce7.tar.gz
org.eclipse.cdt-451fa86e3557e8be5617f85d7a980c7fb0a53ce7.tar.xz
org.eclipse.cdt-451fa86e3557e8be5617f85d7a980c7fb0a53ce7.zip
Bug 467346 - Retain attribute after struct key in C
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java7
2 files changed, 20 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 3f42935de6..381c576ce2 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
@@ -7783,4 +7784,18 @@ public class AST2Tests extends AST2TestBase {
assertNotNull(expr);
assertFalse(expr.getExpressionType() instanceof IProblemType);
}
+
+ // typedef struct __attribute__ ((__packed__)) {
+ // unsigned char a;
+ // unsigned char b;
+ // } example2_s;
+ public void testStructAttribute_467346() throws Exception {
+ BindingAssertionHelper helper = getAssertionHelper(C);
+ IASTDeclaration[] decls = helper.getTranslationUnit().getDeclarations();
+ assertEquals(1, decls.length);
+ assertInstance(decls[0], IASTSimpleDeclaration.class);
+ IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decls[0]).getDeclSpecifier();
+ IASTAttributeSpecifier[] attributes = declSpec.getAttributeSpecifiers();
+ assertEquals(1, attributes.length);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 78e0b3ebf8..88e1f9afc7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -1311,7 +1311,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
// if __attribute__ or __declspec occurs after struct/union/class and before the identifier
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ List<IASTAttributeSpecifier> attributes = __attribute_decl_seq(supportAttributeSpecifiers,
+ supportDeclspecSpecifiers);
// class name
IASTName name = null;
@@ -1320,7 +1321,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
// if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ;
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers));
if (LT(1) != IToken.tLBRACE) {
IToken errorPoint = LA(1);
@@ -1333,6 +1335,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
ICASTCompositeTypeSpecifier result = getNodeFactory().newCompositeTypeSpecifier(classKind, name);
declarationListInBraces(result, offset, DeclarationOptions.C_MEMBER);
+ addAttributeSpecifiers(attributes, result);
return result;
}

Back to the top