| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Wuseless-cast" } */ |
| 3 |
|
| 4 |
void foo(void) |
| 5 |
{ |
| 6 |
// casts to the same type |
| 7 |
int i = 0; |
| 8 |
const int ic = 0; |
| 9 |
struct foo { int x; } x = { 0 }; |
| 10 |
int q[3]; |
| 11 |
(int)ic; /* { dg-warning "useless cast" } */ |
| 12 |
(int)i; /* { dg-warning "useless cast" } */ |
| 13 |
(const int)ic; /* { dg-warning "useless cast" } */ |
| 14 |
(const int)i; /* { dg-warning "useless cast" } */ |
| 15 |
(struct foo)x; /* { dg-warning "useless cast" } */ |
| 16 |
(int(*)[3])&q; /* { dg-warning "useless cast" } */ |
| 17 |
(_Atomic(int))i; /* { dg-warning "useless cast" } */ |
| 18 |
|
| 19 |
// not the same |
| 20 |
int n = 3; |
| 21 |
(int(*)[n])&q; // no warning |
| 22 |
int j = (int)0UL; |
| 23 |
enum X { A = 1 } xx = { A }; |
| 24 |
enum Y { B = 1 } yy = (enum Y)xx; |
| 25 |
} |
| 26 |
|