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