1 /* Check if the @defs() construct preserves the correct
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
4 /* { dg-options "-lobjc" } */
8 #include <objc/Object.h>
10 extern void abort(void);
12 #define CHECK_IF(expr) if(!(expr)) abort();
14 @interface Base: Object {
22 @interface Derived: Base {
37 @implementation Derived
51 Derived *derived = [[Derived alloc] init];
52 struct Derived_defs *derived_defs = (struct Derived_defs *)derived;
54 CHECK_IF(derived->a == derived_defs->a && derived_defs->a == 123);
55 CHECK_IF(derived->b == derived_defs->b && derived_defs->b == (float)1.23);
56 CHECK_IF(derived->c == derived_defs->c && derived_defs->c == 'c');
57 CHECK_IF(derived->d == derived_defs->d && derived_defs->d == (double)123.456);
58 CHECK_IF(derived->e == derived_defs->e && derived_defs->e == 456);
59 CHECK_IF(derived->f == derived_defs->f && derived_defs->f == derived_defs->isa);
61 /* Try out the "inline" notation as well. */
62 CHECK_IF(((struct { @defs(Derived); } *)derived)->a == 123);
63 CHECK_IF(((struct { @defs(Derived); } *)derived)->c == 'c');
64 CHECK_IF(((struct { @defs(Derived); } *)derived)->e == 456);