PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / testsuite / gcc.dg / c99-tag-1.c
blobd7011d2cbec7befbd8a4a3dba28b68eadbd3a051
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" } */
6 void
7 foo (void)
9 /* Forward declarations of structs and unions are OK; those of enums are
10 not. */
12 struct s0;
13 struct s1 *x0;
14 union u0;
15 union u1 *x1;
16 enum e0; /* { dg-bogus "warning" "warning in place of error" } */
17 /* { dg-error "forward" "enum forward 1" { target *-*-* } .-1 } */
18 enum e1 *x2; /* { dg-bogus "warning" "warning in place of error" } */
19 /* { dg-error "forward" "enum forward 2" { target *-*-* } .-1 } */
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 *-*-* } .-1 } */
24 /* A specific type shall have its content defined at most once. But we
25 may redeclare the tag in different scopes. */
27 struct s0 { int i; }; /* { dg-message "note: originally defined here" } */
29 struct s0 { long l; };
32 union s0 { long l; };
34 struct s0 { int i; }; /* { dg-bogus "warning" "warning in place of error" } */
35 /* { dg-error "rede" "struct redef" { target *-*-* } .-1 } */
36 union u0 { int i; }; /* { dg-message "note: originally defined here" } */
38 union u0 { long l; };
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 *-*-* } .-1 } */
45 enum e0 { E0A }; /* { dg-message "note: originally defined here" } */
47 enum e0 { E0B };
50 struct e0 { long l; };
52 enum e0 { E0B }; /* { dg-bogus "warning" "warning in place of error" } */
53 /* { dg-error "rede" "enum redef" { target *-*-* } .-1 } */
55 /* Structure, union and enumerated types have a single namespace of tags. */
57 struct s0;
58 struct s1;
59 struct s2 { int i; };
60 struct s2;
61 struct s3 { int i; };
62 struct s2 sv;
63 union u0;
64 union u2 { int i; };
65 union u2;
66 union u2 uv;
67 enum e0 { E0A };
68 enum e1 { E1A };
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 *-*-* } .-1 } */
72 union s1 { int i; }; /* { dg-bogus "warning" "warning in place of error" } */
73 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
74 union s2; /* { dg-bogus "warning" "warning in place of error" } */
75 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
76 union s3 { int i; }; /* { dg-bogus "warning" "warning in place of error" } */
77 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
78 enum u0 { U0A }; /* { dg-bogus "warning" "warning in place of error" } */
79 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
80 enum u2 { U2A }; /* { dg-bogus "warning" "warning in place of error" } */
81 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
82 struct e0; /* { dg-bogus "warning" "warning in place of error" } */
83 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
84 struct e1 { int i; }; /* { dg-bogus "warning" "warning in place of error" } */
85 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
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. */
91 struct s0;
92 struct s1;
93 struct s2 { int i; };
94 struct s2;
95 struct s3 { int i; };
96 struct s2 sv;
97 union u0;
98 union u2 { int i; };
99 union u2;
100 union u2 uv;
101 enum e0 { E0A };
102 enum e1 { E1A };
104 union s0;
105 union s1;
106 union s2;
107 union s3;
108 struct u0;
109 struct u2;
110 struct e0;
111 union e1;
114 union s0 *x0; /* { dg-bogus "warning" "warning in place of error" } */
115 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
116 int x1[sizeof (union s1 *)]; /* { dg-bogus "warning" "warning in place of error" } */
117 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
118 struct t;
119 union s2 *x2;
120 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
121 int x3[sizeof (union s3 *)]; /* { dg-bogus "warning" "warning in place of error" } */
122 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
123 struct u;
124 enum u0 *y0; /* { dg-bogus "warning" "warning in place of error" } */
125 /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } .-1 } */
126 int y1[sizeof (enum u2 *)]; /* { dg-bogus "warning" "warning in place of error" } */
127 /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } .-1 } */
128 struct v;
129 struct e0 *z0; /* { dg-bogus "warning" "warning in place of error" } */
130 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
131 int z1[sizeof (struct e1 *)]; /* { dg-bogus "warning" "warning in place of error" } */
132 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
133 struct w;
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
137 rejected. */
139 union s0;
140 union s0 *x0;
141 union s1;
142 struct s1 *x1; /* { dg-bogus "warning" "warning in place of error" } */
143 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */
144 union s2;
145 union s2 *x2;
146 union s3;
147 struct s3 *x3; /* { dg-bogus "warning" "warning in place of error" } */
148 /* { dg-error "wrong" "wrong tag type" { target *-*-* } .-1 } */