1 /* Test for handling of tags (6.7.2.3). */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
9 /* Forward declarations of structs and unions are OK; those of enums are
16 enum e0
; /* { dg-bogus "warning" "warning in place of error" } */
17 /* { dg-error "forward" "enum forward 1" { target *-*-* } 16 } */
18 enum e1
*x2
; /* { dg-bogus "warning" "warning in place of error" } */
19 /* { dg-error "forward" "enum forward 2" { target *-*-* } 18 } */
20 /* GCC used to fail to diagnose a use of an enum inside its definition. */
21 enum e2
{ E2A
= sizeof (enum e2
*) }; /* { dg-bogus "warning" "warning in place of error" } */
22 /* { dg-error "forward" "enum forward 3" { target *-*-* } 21 } */
24 /* A specific type shall have its content defined at most once. But we
25 may redeclare the tag in different scopes. */
29 struct s0
{ long l
; };
34 struct s0
{ int i
; }; /* { dg-bogus "warning" "warning in place of error" } */
35 /* { dg-error "rede" "struct redef" { target *-*-* } 34 } */
41 struct u0
{ long l
; };
43 union u0
{ int i
; }; /* { dg-bogus "warning" "warning in place of error" } */
44 /* { dg-error "rede" "union redef" { target *-*-* } 43 } */
50 struct e0
{ long l
; };
52 enum e0
{ E0B
}; /* { dg-bogus "warning" "warning in place of error" } */
53 /* { dg-error "rede" "enum redef" { target *-*-* } 52 } */
55 /* Structure, union and enumerated types have a single namespace of tags. */
69 /* None of the following are allowed; some were not detected by GCC. */
70 union s0
; /* { dg-bogus "warning" "warning in place of error" } */
71 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 70 } */
72 union s1
{ int i
; }; /* { dg-bogus "warning" "warning in place of error" } */
73 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 72 } */
74 union s2
; /* { dg-bogus "warning" "warning in place of error" } */
75 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 74 } */
76 union s3
{ int i
; }; /* { dg-bogus "warning" "warning in place of error" } */
77 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 76 } */
78 enum u0
{ U0A
}; /* { dg-bogus "warning" "warning in place of error" } */
79 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 78 } */
80 enum u2
{ U2A
}; /* { dg-bogus "warning" "warning in place of error" } */
81 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 80 } */
82 struct e0
; /* { dg-bogus "warning" "warning in place of error" } */
83 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 82 } */
84 struct e1
{ int i
; }; /* { dg-bogus "warning" "warning in place of error" } */
85 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 84 } */
87 /* Explicit shadowing in inner scopes is OK, but references to the tag
88 that don't explicitly shadow it must (whether in declarations or
89 expressions) use the correct one of struct/union/enum. */
114 union s0
*x0
; /* { dg-bogus "warning" "warning in place of error" } */
115 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 114 } */
116 int x1
[sizeof (union s1
*)]; /* { dg-bogus "warning" "warning in place of error" } */
117 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 116 } */
120 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 119 } */
121 int x3
[sizeof (union s3
*)]; /* { dg-bogus "warning" "warning in place of error" } */
122 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 121 } */
124 enum u0
*y0
; /* { dg-bogus "warning" "warning in place of error" } */
125 /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } 124 } */
126 int y1
[sizeof (enum u2
*)]; /* { dg-bogus "warning" "warning in place of error" } */
127 /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } 126 } */
129 struct e0
*z0
; /* { dg-bogus "warning" "warning in place of error" } */
130 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 129 } */
131 int z1
[sizeof (struct e1
*)]; /* { dg-bogus "warning" "warning in place of error" } */
132 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 131 } */
135 /* When explicitly shadowed to be a tag of a different type, references
136 to the new type of tag must be accepted and those to the old type
142 struct s1
*x1
; /* { dg-bogus "warning" "warning in place of error" } */
143 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 142 } */
147 struct s3
*x3
; /* { dg-bogus "warning" "warning in place of error" } */
148 /* { dg-error "wrong" "wrong tag type" { target *-*-* } 147 } */