Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s |
Seo Sanghyeon | eff2cd5 | 2009-01-15 04:51:39 +0000 | [diff] [blame] | 2 | |
Abramo Bagnara | 8c4bfe5 | 2010-10-07 21:20:44 +0000 | [diff] [blame] | 3 | union u { int i; unsigned : 3; }; |
Seo Sanghyeon | eff2cd5 | 2009-01-15 04:51:39 +0000 | [diff] [blame] | 4 | void f(union u); |
| 5 | |
| 6 | void test(int x) { |
| 7 | f((union u)x); // expected-warning {{C99 forbids casts to union type}} |
| 8 | f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}} |
Abramo Bagnara | 8c4bfe5 | 2010-10-07 21:20:44 +0000 | [diff] [blame] | 9 | f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}} |
Seo Sanghyeon | eff2cd5 | 2009-01-15 04:51:39 +0000 | [diff] [blame] | 10 | } |
Nuno Lopes | 6ed2ef8 | 2009-01-15 16:44:45 +0000 | [diff] [blame] | 11 | |
| 12 | union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}} |
| 13 | union u ww = (union u)1.0; // expected-error{{cast to union type from type 'double' not present in union}} |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 14 | union u x = 7; // expected-error{{initializing 'union u' with an expression of incompatible type 'int'}} |
Nuno Lopes | 6ed2ef8 | 2009-01-15 16:44:45 +0000 | [diff] [blame] | 15 | int i; |
| 16 | union u zz = (union u)i; // expected-error{{initializer element is not a compile-time constant}} expected-warning {{C99 forbids casts to union type}} |
| 17 | |
| 18 | struct s {int a, b;}; |
| 19 | struct s y = { 1, 5 }; |
| 20 | struct s z = (struct s){ 1, 5 }; |