C++: Tests showing problems with casts of typedefs

This commit is contained in:
Jonas Jensen
2019-03-26 16:19:46 +01:00
parent 10585e719d
commit 1c71c74ce5

View File

@@ -265,3 +265,23 @@ int negative_zero(double dbl) {
}
return 0;
}
typedef unsigned char u8;
int widening_cast1(u8 c) {
if (c == 0) {
if ((int)c > 0) { // BAD [NOT DETECTED]
return 1;
}
}
return 0;
}
int widening_cast2(u8 c) {
if (c <= 10)
return -1;
else if ((c >= 11) /* BAD [NOT DETECTED] */ && (c <= 47))
return 0;
else
return 1;
}