[clang] f30c09e - [clang][Interp][NFC] Use a templated conversion operator
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 19:50:44 PDT 2024
Author: Timm Bäder
Date: 2024-07-16T04:49:05+02:00
New Revision: f30c09e2d3107e117faf8311c6d8642fa95680af
URL: https://github.com/llvm/llvm-project/commit/f30c09e2d3107e117faf8311c6d8642fa95680af
DIFF: https://github.com/llvm/llvm-project/commit/f30c09e2d3107e117faf8311c6d8642fa95680af.diff
LOG: [clang][Interp][NFC] Use a templated conversion operator
Added:
Modified:
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/Integral.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 336f7941dfc47..1bfb26b1b669f 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -45,15 +45,10 @@ class Boolean final {
Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); }
Boolean operator~() const { return Boolean(true); }
- explicit operator int8_t() const { return V; }
- explicit operator uint8_t() const { return V; }
- explicit operator int16_t() const { return V; }
- explicit operator uint16_t() const { return V; }
- explicit operator int32_t() const { return V; }
- explicit operator uint32_t() const { return V; }
- explicit operator int64_t() const { return V; }
- explicit operator uint64_t() const { return V; }
- explicit operator bool() const { return V; }
+ template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
+ explicit operator Ty() const {
+ return V;
+ }
APSInt toAPSInt() const {
return APSInt(APInt(1, static_cast<uint64_t>(V), false), true);
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index cc1cab8f39fb1..db4cc9ae45b49 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -98,10 +98,10 @@ template <unsigned Bits, bool Signed> class Integral final {
return Integral<DstBits, DstSign>(V);
}
- explicit operator unsigned() const { return V; }
- explicit operator int64_t() const { return V; }
- explicit operator uint64_t() const { return V; }
- explicit operator int32_t() const { return V; }
+ template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
+ explicit operator Ty() const {
+ return V;
+ }
APSInt toAPSInt() const {
return APSInt(APInt(Bits, static_cast<uint64_t>(V), Signed), !Signed);
More information about the cfe-commits
mailing list