Skip to content

Commit f30c09e

Browse files
committed
[clang][Interp][NFC] Use a templated conversion operator
1 parent 563ae62 commit f30c09e

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

clang/lib/AST/Interp/Boolean.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,10 @@ class Boolean final {
4545
Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); }
4646
Boolean operator~() const { return Boolean(true); }
4747

48-
explicit operator int8_t() const { return V; }
49-
explicit operator uint8_t() const { return V; }
50-
explicit operator int16_t() const { return V; }
51-
explicit operator uint16_t() const { return V; }
52-
explicit operator int32_t() const { return V; }
53-
explicit operator uint32_t() const { return V; }
54-
explicit operator int64_t() const { return V; }
55-
explicit operator uint64_t() const { return V; }
56-
explicit operator bool() const { return V; }
48+
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
49+
explicit operator Ty() const {
50+
return V;
51+
}
5752

5853
APSInt toAPSInt() const {
5954
return APSInt(APInt(1, static_cast<uint64_t>(V), false), true);

clang/lib/AST/Interp/Integral.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ template <unsigned Bits, bool Signed> class Integral final {
9898
return Integral<DstBits, DstSign>(V);
9999
}
100100

101-
explicit operator unsigned() const { return V; }
102-
explicit operator int64_t() const { return V; }
103-
explicit operator uint64_t() const { return V; }
104-
explicit operator int32_t() const { return V; }
101+
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
102+
explicit operator Ty() const {
103+
return V;
104+
}
105105

106106
APSInt toAPSInt() const {
107107
return APSInt(APInt(Bits, static_cast<uint64_t>(V), Signed), !Signed);

0 commit comments

Comments
 (0)