• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -ffixed-point -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 _Fract ff1(void);
16 
17 void
foo(void)18 foo(void)
19 {
20 
21   /* default, no cast, should always be ok */
22   ff1();
23   /* Casts to void types are always OK.  */
24   (void)vf();
25   (void)if1();
26   (void)cf();
27   (const void)bf();
28   (void)ff1();
29   /* Casts to the same type or similar types are OK.  */
30   (int)if1();
31   (long)if2();
32   (char)if3();
33   (float)rf1();
34   (long double)rf2();
35   (_Complex float)cf();
36   (enum f { F1 })ef();
37   (_Bool)bf();
38   (void *)pf1();
39   (char *)pf2();
40   (_Fract) ff1();
41   /* All following casts issue warning */
42   (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */
43   (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */
44   (_Bool)if3(); /* expected-warning {{cast from function call of type 'long' to non-matching type '_Bool'}} */
45   (int)rf1(); /* expected-warning {{cast from function call of type 'float' to non-matching type 'int'}} */
46   (long)rf2(); /* expected-warning {{cast from function call of type 'double' to non-matching type 'long'}} */
47   (double)cf(); /* expected-warning {{cast from function call of type '_Complex double' to non-matching type 'double'}} */
48   (int)ef(); /* expected-warning {{cast from function call of type 'enum e' to non-matching type 'int'}} */
49   (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */
50   (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */
51   (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */
52   (_Fract) if1();          /* expected-warning{{cast from function call of type 'int' to non-matching type '_Fract'}} */
53   (int)ff1();              /* expected-warning{{cast from function call of type '_Fract' to non-matching type 'int'}} */
54 }
55 
56