xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/cast-to-union.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc union u { int i; unsigned : 3; };
4*f4a2713aSLionel Sambuc void f(union u);
5*f4a2713aSLionel Sambuc 
test(int x)6*f4a2713aSLionel Sambuc void test(int x) {
7*f4a2713aSLionel Sambuc   f((union u)x); // expected-warning {{cast to union type is a GNU extension}}
8*f4a2713aSLionel Sambuc   f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}}
9*f4a2713aSLionel Sambuc   f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}}
10*f4a2713aSLionel Sambuc }
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc union u w = (union u)2; // expected-warning {{cast to union type is a GNU extension}}
13*f4a2713aSLionel Sambuc union u ww = (union u)1.0; // expected-error{{cast to union type from type 'double' not present in union}}
14*f4a2713aSLionel Sambuc union u x = 7; // expected-error{{initializing 'union u' with an expression of incompatible type 'int'}}
15*f4a2713aSLionel Sambuc int i;
16*f4a2713aSLionel Sambuc union u zz = (union u)i; // expected-error{{initializer element is not a compile-time constant}}  expected-warning {{cast to union type is a GNU extension}}
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc struct s {int a, b;};
19*f4a2713aSLionel Sambuc struct s y = { 1, 5 };
20*f4a2713aSLionel Sambuc struct s z = (struct s){ 1, 5 };
21