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