1// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify
2// rdar://9103192
3
4void vf(void);
5int if1(void);
6char if2(void);
7long if3(void);
8float rf1(void);
9double rf2(void);
10_Complex double cf(void);
11enum e { E1 } ef(void);
12_Bool bf(void);
13char *pf1(void);
14int *pf2(void);
15
16void
17foo(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