Debian Codegraph @

gcc/testsuite/gcc.dg/anon-struct-11.c

raw
1 /* { dg-do compile } */
2
3 /* Also turn off the default -pedantic-errors option. */
4 /* { dg-options "-fpermissive" } */
5
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. */
9
10 extern void exit (int);
11 extern void abort (void);
12
13 struct A { char a; };
14
15 struct B {
16 char b;
17 struct A; /* { dg-warning "does not declare anything" } */
18 char c;
19 };
20
21 void
22 f1 (struct A *p) /* { dg-message "expected" } */
23 {
24 p->a = 1;
25 }
26
27 void
28 test1 (void)
29 {
30 struct B b;
31 struct A *p;
32
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 ();
43 }
44
45 typedef struct { char d; } D;
46
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" } */
53 };
54 char e;
55 };
56
57 void
58 f2 (struct F *p) /* { dg-message "expected" } */
59 {
60 p->f = 6;
61 }
62
63 void
64 f3 (D *p) /* { dg-message "expected" } */
65 {
66 p->d = 4;
67 }
68
69 void
70 f4 (D d)
71 {
72 }
73
74 void
75 test2 (void)
76 {
77 struct E e;
78 struct F *pf;
79 D *pd;
80 D d;
81
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" } */
102 }
103
104 int
105 main ()
106 {
107 test1 ();
108 test2 ();
109 exit (0);
110 }