1 /* Test operation of -Wbad-function-cast. */
2 /* Based on gcc.dg/Wbad-function-cast-1.c. */
3
4 /* { dg-do compile } */
5 /* { dg-options "-Wbad-function-cast" } */
6
7 int if1(void);
8 char if2(void);
9 long if3(void);
10 float rf1(void);
11 double rf2(void);
12 _Decimal32 rf3(void);
13 _Decimal64 rf4(void);
14 _Decimal128 rf5(void);
15 _Complex double cf(void);
16
17 void
foo(void)18 foo(void)
19 {
20 /* Casts to void types are always OK. */
21 (void)rf3();
22 (void)rf4();
23 (void)rf5();
24 (const void)rf3();
25 /* Casts to the same type or similar types are OK. */
26 (_Decimal32)rf1();
27 (_Decimal64)rf2();
28 (_Decimal128)rf3();
29 (_Decimal128)rf4();
30 (_Decimal128)rf5();
31 (float)rf3();
32 (double)rf4();
33 (long double)rf5();
34 /* Casts to types with different TREE_CODE (which is how this
35 warning has been defined) are not OK, except for casts to void
36 types. */
37 (_Decimal32)if1(); /* { dg-warning "cast from function call of type 'int' to non-matching type '_Decimal32'" } */
38 (_Decimal64)if2(); /* { dg-warning "cast from function call of type 'char' to non-matching type '_Decimal64'" } */
39 (_Decimal128)if3(); /* { dg-warning "cast from function call of type 'long int' to non-matching type '_Decimal128'" } */
40 (int)rf3(); /* { dg-warning "cast from function call of type '_Decimal32' to non-matching type 'int'" } */
41 (long)rf4(); /* { dg-warning "cast from function call of type '_Decimal64' to non-matching type 'long int'" } */
42 (long int)rf5(); /* { dg-warning "cast from function call of type '_Decimal128' to non-matching type 'long int'" } */
43 (_Decimal32)cf(); /* { dg-warning "cast from function call of type 'complex double' to non-matching type '_Decimal32'" } */
44 }
45