1 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify -Wvla
3 int array
[(long)(char *)0]; // expected-warning {{variable length array used}} \
4 // expected-warning {{variable length array folded to constant array as an extension}} \
5 // expected-note {{this conversion is not allowed in a constant expression}}
7 typedef struct { unsigned long bits
[(((1) + (64) - 1) / (64))]; } cpumask_t
;
15 b
= (double)a
; // expected-error {{pointer cannot be cast to type}}
16 a
= (char*)b
; // expected-error {{cannot be cast to a pointer type}}
19 long bar1(long *next
) {
20 return (long)(*next
)++;
27 typedef double Double
;
28 typedef _Complex
int CInt
;
29 typedef _Complex
long CLong
;
30 typedef _Complex
float CFloat
;
31 typedef _Complex
double CDouble
;
32 typedef void *VoidPtr
;
33 typedef char *CharPtr
;
35 void testBool(Bool v
) {
59 (void) (VoidPtr
) v
; // expected-warning{{cast to 'VoidPtr' (aka 'void *') from smaller integer type 'Int' (aka 'int')}}
60 (void) (CharPtr
) v
; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}
62 // Test that casts to void* can be controlled separately
63 // from other -Wint-to-pointer-cast warnings.
64 #pragma clang diagnostic push
65 #pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
66 (void) (VoidPtr
) v
; // no-warning
67 (void) (CharPtr
) v
; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}
68 #pragma clang diagnostic pop
71 void testLong(Long v
) {
85 void testFloat(Float v
) {
97 void testDouble(Double v
) {
109 void testCI(CInt v
) {
121 void testCLong(CLong v
) {
133 void testCFloat(CFloat v
) {
145 void testCDouble(CDouble v
) {
157 void testVoidPtr(VoidPtr v
) {
159 (void) (Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
163 // Test that casts to void* can be controlled separately
164 // from other -Wpointer-to-int-cast warnings.
165 #pragma clang diagnostic push
166 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
167 (void)(Int
) v
; // no-warning
168 #pragma clang diagnostic pop
171 void testCharPtr(CharPtr v
) {
173 (void) (Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
177 // Test that casts to void* can be controlled separately
178 // from other -Wpointer-to-int-cast warnings.
179 #pragma clang diagnostic push
180 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
181 (void)(Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
182 #pragma clang diagnostic pop
185 typedef enum { x_a
, x_b
} X
;
186 void *intToPointerCast2(X x
) {
190 void *intToPointerCast3(void) {
191 return (void*)(1 + 3);
194 void voidPointerToEnumCast(VoidPtr v
) {
195 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'VoidPtr' (aka 'void *')}}
196 // Test that casts to void* can be controlled separately
197 // from other -Wpointer-to-enum-cast warnings.
198 #pragma clang diagnostic push
199 #pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"
200 (void)(X
) v
; // no-warning
201 #pragma clang diagnostic pop
204 void pointerToEnumCast(CharPtr v
) {
205 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}
206 // Test that casts to void* can be controlled separately
207 // from other -Wpointer-to-enum-cast warnings.
208 #pragma clang diagnostic push
209 #pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"
210 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}
211 #pragma clang diagnostic pop