blob: 03f6a53d059a04834c5cb6084c4980a65290a1b2 [file] [log] [blame]
Daniel Dunbar80737ad2009-12-15 22:01:24 +00001// RUN: %clang -fsyntax-only -Xclang -verify %s
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00002typedef union {
3 int *ip;
4 float *fp;
5} TU __attribute__((transparent_union));
6
7void f(TU);
8
9void g(int *ip, float *fp, char *cp) {
10 f(ip);
11 f(fp);
12 f(cp); // expected-error{{incompatible type}}
13 f(0);
14
15 TU tu_ip = ip; // expected-error{{incompatible type}}
16 TU tu;
17 tu.ip = ip;
18}
19
20/* FIXME: we'd like to just use an "int" here and align it differently
21 from the normal "int", but if we do so we lose the alignment
22 information from the typedef within the compiler. */
23typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
24
25typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
26typedef union {
27 aligned_struct4 s4; // expected-note{{alignment of first field}}
28 aligned_struct8 s8; // expected-warning{{alignment of field}}
29} TU1 __attribute__((transparent_union));
30
31typedef union {
32 char c; // expected-note{{size of first field is 8 bits}}
33 int i; // expected-warning{{size of field}}
34} TU2 __attribute__((transparent_union));
35
36typedef union {
37 float f; // expected-warning{{floating}}
38} TU3 __attribute__((transparent_union));
39
40typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}