1/* { dg-do compile } */
2
3/* No special options--in particular, turn off the default
4   -pedantic-errors option.  */
5/* { dg-options "" } */
6
7/* When not using -fplan9-extensions, we don't support automatic
8   conversion of pointer types, and we don't support referring to a
9   typedef name directly.  */
10
11extern void exit (int);
12extern void abort (void);
13
14struct A { char a; };
15
16struct B {
17  char b;
18  struct A;		/* { dg-warning "does not declare anything" } */
19  char c;
20};
21
22void
23f1 (struct A *p)	/* { dg-message "expected" } */
24{
25  p->a = 1;
26}
27
28void
29test1 (void)
30{
31  struct B b;
32  struct A *p;
33
34  b.b = 2;
35  b.c = 3;
36  f1 (&b);		/* { dg-warning "incompatible pointer type" } */
37  if (b.a != 1)		/* { dg-error "no member" } */
38    abort ();
39  if (b.b != 2 || b.c != 3)
40    abort ();
41  p = &b;		/* { dg-warning "incompatible pointer type" } */
42  if (p->a != 1)
43    abort ();
44}
45
46typedef struct { char d; } D;
47
48struct E {
49  char b;
50  struct F { char f; };	/* { dg-warning "does not declare anything" } */
51  char c;
52  union {
53    D;			/* { dg-warning "does not declare anything" } */
54  };
55  char e;
56};
57
58void
59f2 (struct F *p)	/* { dg-message "expected" } */
60{
61  p->f = 6;
62}
63
64void
65f3 (D *p)		/* { dg-message "expected" } */
66{
67  p->d = 4;
68}
69
70void
71f4 (D d)
72{
73}
74
75void
76test2 (void)
77{
78  struct E e;
79  struct F *pf;
80  D *pd;
81  D d;
82
83  e.b = 2;
84  e.c = 3;
85  e.e = 5;
86  f2 (&e);		/* { dg-warning "incompatible pointer type" } */
87  f3 (&e);		/* { dg-warning "incompatible pointer type" } */
88  if (e.d != 4)		/* { dg-error "no member" } */
89    abort ();
90  if (e.f != 6)		/* { dg-error "no member" } */
91    abort ();
92  if (e.b != 2 || e.c != 3 || e.e != 5)
93    abort ();
94  pf = &e;		/* { dg-warning "incompatible pointer type" } */
95  if (pf->f != 6)
96    abort ();
97  pd = &e;		/* { dg-warning "incompatible pointer type" } */
98  if (pd->d != 4)
99    abort ();
100  d = e.D;		/* { dg-error "no member" } */
101  f3 (&e.D);		/* { dg-error "no member" } */
102  f4 (e.D);		/* { dg-error "no member" } */
103}
104
105int
106main ()
107{
108  test1 ();
109  test2 ();
110  exit (0);
111}
112