libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / anon-struct-11.c
blob622fb7cacc68ec176497dfeb98d9897b7f3a33d6
1 /* { dg-do compile } */
3 /* Also turn off the default -pedantic-errors option. */
4 /* { dg-options "-fpermissive" } */
6 /* When not using -fplan9-extensions, we don't support automatic
7 conversion of pointer types, and we don't support referring to a
8 typedef name directly. */
10 extern void exit (int);
11 extern void abort (void);
13 struct A { char a; };
15 struct B {
16 char b;
17 struct A; /* { dg-warning "does not declare anything" } */
18 char c;
21 void
22 f1 (struct A *p) /* { dg-message "expected" } */
24 p->a = 1;
27 void
28 test1 (void)
30 struct B b;
31 struct A *p;
33 b.b = 2;
34 b.c = 3;
35 f1 (&b); /* { dg-warning "incompatible pointer type" } */
36 if (b.a != 1) /* { dg-error "no member" } */
37 abort ();
38 if (b.b != 2 || b.c != 3)
39 abort ();
40 p = &b; /* { dg-warning "incompatible pointer type" } */
41 if (p->a != 1)
42 abort ();
45 typedef struct { char d; } D;
47 struct E {
48 char b;
49 struct F { char f; }; /* { dg-warning "does not declare anything" } */
50 char c;
51 union {
52 D; /* { dg-warning "does not declare anything" } */
54 char e;
57 void
58 f2 (struct F *p) /* { dg-message "expected" } */
60 p->f = 6;
63 void
64 f3 (D *p) /* { dg-message "expected" } */
66 p->d = 4;
69 void
70 f4 (D d)
74 void
75 test2 (void)
77 struct E e;
78 struct F *pf;
79 D *pd;
80 D d;
82 e.b = 2;
83 e.c = 3;
84 e.e = 5;
85 f2 (&e); /* { dg-warning "incompatible pointer type" } */
86 f3 (&e); /* { dg-warning "incompatible pointer type" } */
87 if (e.d != 4) /* { dg-error "no member" } */
88 abort ();
89 if (e.f != 6) /* { dg-error "no member" } */
90 abort ();
91 if (e.b != 2 || e.c != 3 || e.e != 5)
92 abort ();
93 pf = &e; /* { dg-warning "incompatible pointer type" } */
94 if (pf->f != 6)
95 abort ();
96 pd = &e; /* { dg-warning "incompatible pointer type" } */
97 if (pd->d != 4)
98 abort ();
99 d = e.D; /* { dg-error "no member" } */
100 f3 (&e.D); /* { dg-error "no member" } */
101 f4 (e.D); /* { dg-error "no member" } */
105 main ()
107 test1 ();
108 test2 ();
109 exit (0);