1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual -verify %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -fsyntax-only -Wcast-qual -verify %s
7 const char *const ptr
= 0;
8 const char *const *ptrptr
= 0;
9 char *const *ptrcptr
= 0;
11 char *y
= (char *)ptr
; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
12 char **y1
= (char **)ptrptr
; // expected-warning {{cast from 'const char *const *' to 'char **' drops const qualifier}}
13 const char **y2
= (const char **)ptrptr
; // expected-warning {{cast from 'const char *const *' to 'const char **' drops const qualifier}}
14 char *const *y3
= (char *const *)ptrptr
; // expected-warning {{cast from 'const char *const' to 'char *const' drops const qualifier}}
15 const char **y4
= (const char **)ptrcptr
; // expected-warning {{cast from 'char *const *' to 'const char **' drops const qualifier}}
17 char *z
= (char *)(uintptr_t)(const void *)ptr
; // no warning
18 char *z1
= (char *)(const void *)ptr
; // expected-warning {{cast from 'const void *' to 'char *' drops const qualifier}}
20 volatile char *vol
= 0;
21 char *vol2
= (char *)vol
; // expected-warning {{cast from 'volatile char *' to 'char *' drops volatile qualifier}}
22 const volatile char *volc
= 0;
23 char *volc2
= (char *)volc
; // expected-warning {{cast from 'const volatile char *' to 'char *' drops const and volatile qualifiers}}
26 const int **intptrptrc
= (const int **)intptrptr
; // expected-warning {{cast from 'int **' to 'const int **' must have all intermediate pointers const qualified}}
27 volatile int **intptrptrv
= (volatile int **)intptrptr
; // expected-warning {{cast from 'int **' to 'volatile int **' must have all intermediate pointers const qualified}}
30 const int *intptrc
= (const int *)intptr
; // no warning
32 const char **charptrptrc
;
33 char **charptrptr
= (char **)charptrptrc
; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
35 const char *constcharptr
;
36 char *charptr
= (char *)constcharptr
; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
37 const char *constcharptr2
= (char *)constcharptr
; // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
38 const char *charptr2
= (char *)charptr
; // no warning
41 using CharPtr
= char *;
42 using CharPtrPtr
= char **;
43 using ConstCharPtrPtr
= const char **;
44 using CharPtrConstPtr
= char *const *;
46 char *fy
= CharPtr(ptr
); // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
47 char **fy1
= CharPtrPtr(ptrptr
); // expected-warning {{cast from 'const char *const *' to 'char **' drops const qualifier}}
48 const char **fy2
= ConstCharPtrPtr(ptrptr
); // expected-warning {{cast from 'const char *const *' to 'const char **' drops const qualifier}}
49 char *const *fy3
= CharPtrConstPtr(ptrptr
); // expected-warning {{cast from 'const char *const' to 'char *const' drops const qualifier}}
50 const char **fy4
= ConstCharPtrPtr(ptrcptr
); // expected-warning {{cast from 'char *const *' to 'const char **' drops const qualifier}}
52 using ConstVoidPtr
= const void *;
53 char *fz
= CharPtr(uintptr_t(ConstVoidPtr(ptr
))); // no warning
54 char *fz1
= CharPtr(ConstVoidPtr(ptr
)); // expected-warning {{cast from 'const void *' to 'char *' drops const qualifier}}
56 char *fvol2
= CharPtr(vol
); // expected-warning {{cast from 'volatile char *' to 'char *' drops volatile qualifier}}
57 char *fvolc2
= CharPtr(volc
); // expected-warning {{cast from 'const volatile char *' to 'char *' drops const and volatile qualifiers}}
59 using ConstIntPtrPtr
= const int **;
60 using VolitileIntPtrPtr
= volatile int **;
61 const int **fintptrptrc
= ConstIntPtrPtr(intptrptr
); // expected-warning {{cast from 'int **' to 'ConstIntPtrPtr' (aka 'const int **') must have all intermediate pointers const qualified}}
62 volatile int **fintptrptrv
= VolitileIntPtrPtr(intptrptr
); // expected-warning {{cast from 'int **' to 'VolitileIntPtrPtr' (aka 'volatile int **') must have all intermediate pointers const qualified}}
64 using ConstIntPtr
= const int *;
65 const int *fintptrc
= ConstIntPtr(intptr
); // no warning
67 char **fcharptrptr
= CharPtrPtr(charptrptrc
); // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
69 char *fcharptr
= CharPtr(constcharptr
); // expected-warning {{cast from 'const char *' to 'char *' drops const qualifier}}
70 const char *fcharptr2
= CharPtr(charptr
); // no warning
80 const struct C S
= {0, 0};
82 *(int *)(&S
.a
) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
83 *(int *)(&S
.b
) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
87 *(IntPtr(&S
.a
)) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
88 *(IntPtr(&S
.b
)) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
99 S
.b
= 0; // no warning
101 *(int *)(&S
.a
) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
102 *(int *)(&S
.b
) = 0; // no warning
105 using IntPtr
= int *;
106 *(IntPtr(&S
.a
)) = 0; // expected-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
107 *(IntPtr(&S
.b
)) = 0; // no warning