[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / warn-bad-function-cast.c
blob0172c9b37c97d9c3bc357293608fd4ce571348ff
1 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -triple x86_64-unknown-unknown -verify
3 void vf(void);
4 int if1(void);
5 char if2(void);
6 long if3(void);
7 float rf1(void);
8 double rf2(void);
9 _Complex double cf(void);
10 enum e { E1 } ef(void);
11 _Bool bf(void);
12 char *pf1(void);
13 int *pf2(void);
14 _Fract ff1(void);
16 void
17 foo(void)
20 /* default, no cast, should always be ok */
21 ff1();
22 /* Casts to void types are always OK. */
23 (void)vf();
24 (void)if1();
25 (void)cf();
26 (const void)bf();
27 (void)ff1();
28 /* Casts to the same type or similar types are OK. */
29 (int)if1();
30 (long)if2();
31 (char)if3();
32 (float)rf1();
33 (long double)rf2();
34 (_Complex float)cf();
35 (enum f { F1 })ef();
36 (_Bool)bf();
37 (void *)pf1();
38 (char *)pf2();
39 (_Fract) ff1();
40 /* All following casts issue warning */
41 (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */
42 (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */
43 (_Bool)if3(); /* expected-warning {{cast from function call of type 'long' to non-matching type '_Bool'}} */
44 (int)rf1(); /* expected-warning {{cast from function call of type 'float' to non-matching type 'int'}} */
45 (long)rf2(); /* expected-warning {{cast from function call of type 'double' to non-matching type 'long'}} */
46 (double)cf(); /* expected-warning {{cast from function call of type '_Complex double' to non-matching type 'double'}} */
47 (int)ef(); /* expected-warning {{cast from function call of type 'enum e' to non-matching type 'int'}} */
48 (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
49 (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
50 (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
51 (_Fract) if1(); /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
52 (int)ff1(); /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */