blob: ce65095873ef66d7ec9fdcc2f81179219db43fce [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
Douglas Gregor3218c4b2009-01-09 22:42:13 +00002
3/* This test checks the introduction of struct and union types based
4 on a type specifier of the form "struct-or-union identifier" when they
5 type has not yet been declared. See C99 6.7.2.3p8. */
6
7typedef struct S1 {
8 union {
9 struct S2 *x;
10 struct S3 *y;
11 } u1;
12} S1;
13
14int test_struct_scope(S1 *s1, struct S2 *s2, struct S3 *s3) {
15 if (s1->u1.x == s2) return 1;
16 if (s1->u1.y == s3) return 1;
17 return 0;
18}
19
20int test_struct_scope_2(S1 *s1) {
21 struct S2 { int x; } *s2 = 0;
22 if (s1->u1.x == s2) return 1; /* expected-warning {{comparison of distinct pointer types ('struct S2 *' and 'struct S2 *')}} */
23 return 0;
24}
25
26// FIXME: We do not properly implement C99 6.2.1p4, which says that
27// the type "struct S4" declared in the function parameter list has
28// block scope within the function definition. The problem, in this
29// case, is that the code is ill-formed but we warn about the two S4's
30// being incompatible (we think they are two different types).
31int test_struct_scope_3(struct S4 * s4) { // expected-warning{{declaration of 'struct S4' will not be visible outside of this function}}
32 struct S4 { int y; } *s4_2 = 0;
33 /* if (s4 == s4_2) return 1; */
34 return 0;
35}
36
37void f(struct S5 { int y; } s5); // expected-warning{{declaration of 'struct S5' will not be visible outside of this function}}
Douglas Gregor1a0d31a2009-01-12 18:45:55 +000038
39// PR clang/3312
40struct S6 {
41 enum { BAR } e;
42};
43
44void test_S6() {
45 struct S6 a;
46 a.e = BAR;
47}
48
49// <rdar://problem/6487669>
50typedef struct z_foo_s {
51 struct bar_baz *baz;
52} z_foo;
53typedef z_foo *z_foop;
54struct bar_baz {
55 enum {
56 SQUAT, FLAG, DICT4, DICT3, DICT2, DICT1, DICT0, HOP, CHECK4, CHECK3, CHECK2, CHECK1, DONE, BAD
57 } mode;
58 int nowrap;
59};
Mike Stumpd1969d82009-07-22 00:43:08 +000060void
Douglas Gregor1a0d31a2009-01-12 18:45:55 +000061wizbiz_quxPoof(z)
62 z_foop z;
63{
64 z->baz->mode = z->baz->nowrap ? HOP : SQUAT;
65}