1 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify
3 typedef struct { unsigned long bits
[(((1) + (64) - 1) / (64))]; } cpumask_t
;
11 b
= (double)a
; // expected-error {{pointer cannot be cast to type}}
12 a
= (char*)b
; // expected-error {{cannot be cast to a pointer type}}
15 long bar1(long *next
) {
16 return (long)(*next
)++;
23 typedef double Double
;
24 typedef _Complex
int CInt
;
25 typedef _Complex
long CLong
;
26 typedef _Complex
float CFloat
;
27 typedef _Complex
double CDouble
;
28 typedef void *VoidPtr
;
29 typedef char *CharPtr
;
31 void testBool(Bool v
) {
55 (void) (VoidPtr
) v
; // expected-warning{{cast to 'VoidPtr' (aka 'void *') from smaller integer type 'Int' (aka 'int')}}
56 (void) (CharPtr
) v
; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}
58 // Test that casts to void* can be controlled separately
59 // from other -Wint-to-pointer-cast warnings.
60 #pragma clang diagnostic push
61 #pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
62 (void) (VoidPtr
) v
; // no-warning
63 (void) (CharPtr
) v
; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}
64 #pragma clang diagnostic pop
67 void testLong(Long v
) {
81 void testFloat(Float v
) {
93 void testDouble(Double v
) {
105 void testCI(CInt v
) {
117 void testCLong(CLong v
) {
129 void testCFloat(CFloat v
) {
141 void testCDouble(CDouble v
) {
153 void testVoidPtr(VoidPtr v
) {
155 (void) (Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
159 // Test that casts to void* can be controlled separately
160 // from other -Wpointer-to-int-cast warnings.
161 #pragma clang diagnostic push
162 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
163 (void)(Int
) v
; // no-warning
164 #pragma clang diagnostic pop
167 void testCharPtr(CharPtr v
) {
169 (void) (Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
173 // Test that casts to void* can be controlled separately
174 // from other -Wpointer-to-int-cast warnings.
175 #pragma clang diagnostic push
176 #pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
177 (void)(Int
) v
; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
178 #pragma clang diagnostic pop
181 typedef enum { x_a
, x_b
} X
;
182 void *intToPointerCast2(X x
) {
186 void *intToPointerCast3(void) {
187 return (void*)(1 + 3);
190 void voidPointerToEnumCast(VoidPtr v
) {
191 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'VoidPtr' (aka 'void *')}}
192 // Test that casts to void* can be controlled separately
193 // from other -Wpointer-to-enum-cast warnings.
194 #pragma clang diagnostic push
195 #pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"
196 (void)(X
) v
; // no-warning
197 #pragma clang diagnostic pop
200 void pointerToEnumCast(CharPtr v
) {
201 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}
202 // Test that casts to void* can be controlled separately
203 // from other -Wpointer-to-enum-cast warnings.
204 #pragma clang diagnostic push
205 #pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"
206 (void)(X
) v
; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}
207 #pragma clang diagnostic pop