2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
|
2009-01-15 12:51:39 +08:00
|
|
|
|
2010-10-08 05:20:44 +08:00
|
|
|
union u { int i; unsigned : 3; };
|
2009-01-15 12:51:39 +08:00
|
|
|
void f(union u);
|
|
|
|
|
|
|
|
void test(int x) {
|
|
|
|
f((union u)x); // expected-warning {{C99 forbids casts to union type}}
|
|
|
|
f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}}
|
2010-10-08 05:20:44 +08:00
|
|
|
f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}}
|
2009-01-15 12:51:39 +08:00
|
|
|
}
|
2009-01-16 00:44:45 +08:00
|
|
|
|
|
|
|
union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}}
|
|
|
|
union u ww = (union u)1.0; // expected-error{{cast to union type from type 'double' not present in union}}
|
2010-04-10 01:53:29 +08:00
|
|
|
union u x = 7; // expected-error{{initializing 'union u' with an expression of incompatible type 'int'}}
|
2009-01-16 00:44:45 +08:00
|
|
|
int i;
|
|
|
|
union u zz = (union u)i; // expected-error{{initializer element is not a compile-time constant}} expected-warning {{C99 forbids casts to union type}}
|
|
|
|
|
|
|
|
struct s {int a, b;};
|
|
|
|
struct s y = { 1, 5 };
|
|
|
|
struct s z = (struct s){ 1, 5 };
|