QualType DestType, QualType SrcType,
const APSInt &Value) {
unsigned DestWidth = Info.Ctx.getIntWidth(DestType);
- APSInt Result = Value;
// Figure out if this is a truncate, extend or noop cast.
// If the input is signed, do a sign extend, noop, or truncate.
- Result = Result.extOrTrunc(DestWidth);
+ APSInt Result = Value.extOrTrunc(DestWidth);
Result.setIsUnsigned(DestType->isUnsignedIntegerOrEnumerationType());
+ if (DestType->isBooleanType())
+ Result = Value.getBoolValue();
return Result;
}
}
static_assert(test_float(), "");
+ constexpr bool test_bool() {
+ bool b = false;
+ b |= 2;
+ if (b != true) return false;
+ b <<= 1;
+ if (b != true) return false;
+ b *= 2;
+ if (b != true) return false;
+ b -= 1;
+ if (b != false) return false;
+ b -= 1;
+ if (b != true) return false;
+ b += -1;
+ if (b != false) return false;
+ b += 1;
+ if (b != true) return false;
+ b += 1;
+ if (b != true) return false;
+ b ^= b;
+ if (b != false) return false;
+ return true;
+ }
+ static_assert(test_bool(), "");
+
constexpr bool test_ptr() {
int arr[123] = {};
int *p = arr;
--a.n;
--a.u;
a.n = -a.n * 3;
- return a.b == false && a.n == 3 && a.u == 31;
+ return a.b == true && a.n == 3 && a.u == 31;
}
static_assert(test(), "");
}