1 | // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify |
2 | // rdar://9103192 |
3 | |
4 | void vf(void); |
5 | int if1(void); |
6 | char if2(void); |
7 | long if3(void); |
8 | float rf1(void); |
9 | double rf2(void); |
10 | _Complex double cf(void); |
11 | enum e { E1 } ef(void); |
12 | _Bool bf(void); |
13 | char *pf1(void); |
14 | int *pf2(void); |
15 | |
16 | void |
17 | foo(void) |
18 | { |
19 | /* Casts to void types are always OK. */ |
20 | (void)vf(); |
21 | (void)if1(); |
22 | (void)cf(); |
23 | (const void)bf(); |
24 | /* Casts to the same type or similar types are OK. */ |
25 | (int)if1(); |
26 | (long)if2(); |
27 | (char)if3(); |
28 | (float)rf1(); |
29 | (long double)rf2(); |
30 | (_Complex float)cf(); |
31 | (enum f { F1 })ef(); |
32 | (_Bool)bf(); |
33 | (void *)pf1(); |
34 | (char *)pf2(); |
35 | /* All following casts issue warning */ |
36 | (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */ |
37 | (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */ |
38 | (_Bool)if3(); /* expected-warning {{cast from function call of type 'long' to non-matching type '_Bool'}} */ |
39 | (int)rf1(); /* expected-warning {{cast from function call of type 'float' to non-matching type 'int'}} */ |
40 | (long)rf2(); /* expected-warning {{cast from function call of type 'double' to non-matching type 'long'}} */ |
41 | (double)cf(); /* expected-warning {{cast from function call of type '_Complex double' to non-matching type 'double'}} */ |
42 | (int)ef(); /* expected-warning {{cast from function call of type 'enum e' to non-matching type 'int'}} */ |
43 | (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */ |
44 | (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */ |
45 | (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */ |
46 | } |
47 | |
48 | |