[clang] [clang][Interp] Fix truncateCast() (PR #69911)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 06:24:22 PDT 2023
================
@@ -81,14 +89,20 @@ template <bool Signed> class IntegralAP final {
}
explicit operator bool() const { return !V.isZero(); }
- explicit operator int8_t() const { return truncateCast<int8_t>(V); }
- explicit operator uint8_t() const { return truncateCast<uint8_t>(V); }
- explicit operator int16_t() const { return truncateCast<int16_t>(V); }
- explicit operator uint16_t() const { return truncateCast<uint16_t>(V); }
- explicit operator int32_t() const { return truncateCast<int32_t>(V); }
- explicit operator uint32_t() const { return truncateCast<uint32_t>(V); }
- explicit operator int64_t() const { return truncateCast<int64_t>(V); }
- explicit operator uint64_t() const { return truncateCast<uint64_t>(V); }
+ explicit operator int8_t() const { return truncateCast<int8_t, Signed>(V); }
+ explicit operator uint8_t() const { return truncateCast<uint8_t, Signed>(V); }
+ explicit operator int16_t() const { return truncateCast<int16_t, Signed>(V); }
+ explicit operator uint16_t() const {
+ return truncateCast<uint16_t, Signed>(V);
+ }
+ explicit operator int32_t() const { return truncateCast<int32_t, Signed>(V); }
+ explicit operator uint32_t() const {
+ return truncateCast<uint32_t, Signed>(V);
+ }
+ explicit operator int64_t() const { return truncateCast<int64_t, Signed>(V); }
+ explicit operator uint64_t() const {
+ return truncateCast<uint64_t, Signed>(V);
+ }
----------------
AaronBallman wrote:
This might be a terrible idea, but I wish we could remove the duplication with something along the lines of:
```
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
explicit operator Ty() const { return truncateCast<Ty, Signed>(V); }
```
instead of having to repeat ourselves so much. CC @cor3ntin
https://github.com/llvm/llvm-project/pull/69911
More information about the cfe-commits
mailing list