1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 467346 - Retain attribute after struct key in C

Change-Id: I35a25bc635039c37b66d1f1e4037e943ffcb0d39
This commit is contained in:
Nathan Ridge 2019-06-29 02:44:22 -04:00
parent 996d7193c0
commit 451fa86e35
2 changed files with 20 additions and 2 deletions

View file

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

View file

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