1 /* Check if the @defs() construct preserves the correct
2 layout of bitfields. */
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
4 /* { dg-options "-lobjc -Wpadded" } */
7 #include <objc/Object.h>
10 extern void abort(void);
11 extern int strcmp(const char *str1, const char *str2);
13 #define CHECK_IF(expr) if(!(expr)) abort()
15 enum Enum { one, two, three, four };
17 @interface Base: Object {
22 } /* { dg-warning "padding struct size to alignment boundary" } */
25 @interface Derived: Base {
32 /* Note that the semicolon after @defs(...) is optional. */
34 typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */
35 typedef struct { @defs(Derived); } Derived_t;
39 CHECK_IF(sizeof(Base_t) == sizeof(Base));
40 CHECK_IF(sizeof(Derived_t) == sizeof(Derived));
42 #ifdef __NEXT_RUNTIME__
43 CHECK_IF(!strcmp(@encode(Base), "{Base=#b2b3b4b5}"));
44 CHECK_IF(!strcmp(@encode(Derived), "{Derived=#b2b3b4b5b5b4b3}"));
46 CHECK_IF(!strcmp(@encode(Base_t), "{?=#b2b3b4b5}"));
47 CHECK_IF(!strcmp(@encode(Derived_t), "{?=#b2b3b4b5b5b4b3}"));
48 #endif /* __NEXT_RUNTIME__ */