]>
Commit | Line | Data |
---|---|---|
f339eb66 MP |
1 | // PR c++/90805 - detect narrowing in case values. |
2 | // { dg-do compile { target c++11 } } | |
3 | ||
4 | void f(int i, char c, unsigned u) | |
5 | { | |
6 | switch (i) | |
7 | { | |
8 | case 2149056512u:; // { dg-error "narrowing conversion of .2149056512. from .unsigned int. to .int." } | |
9 | case (long long int) 1e10:; // { dg-error "narrowing conversion of .10000000000. from .long long int. to .int." } | |
10 | // { dg-warning "overflow in conversion" "overflow" { target *-*-* } .-1 } | |
11 | } | |
12 | ||
13 | switch (c) | |
14 | // No narrowing, the adjusted type is int. | |
15 | case 300:; // { dg-warning "exceeds maximum value for type" } | |
16 | ||
17 | switch (u) | |
18 | case -42:; // { dg-error "narrowing conversion of .-42. from .int. to .unsigned int." } | |
19 | } |