diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-07-18 21:58:49 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-07-18 21:58:49 +0000 |
commit | 6ef4996b095ef6c0d902798d2455716a79bd0a3d (patch) | |
tree | 836b22960c27c036aedec22c3bc75f469c1c2909 | |
parent | 62a89f5808bbb620767d95adb784978ed2e7bff0 (diff) | |
download | external_llvm-6ef4996b095ef6c0d902798d2455716a79bd0a3d.zip external_llvm-6ef4996b095ef6c0d902798d2455716a79bd0a3d.tar.gz external_llvm-6ef4996b095ef6c0d902798d2455716a79bd0a3d.tar.bz2 |
Allow PointerIntPairs to be created from const void *.
For a measure of safety, this conversion is only permitted if the
stored pointer type can also be created from a const void *.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160456 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/PointerIntPair.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/include/llvm/ADT/PointerIntPair.h b/include/llvm/ADT/PointerIntPair.h index ccdcd1a..fcc758b 100644 --- a/include/llvm/ADT/PointerIntPair.h +++ b/include/llvm/ADT/PointerIntPair.h @@ -108,7 +108,14 @@ public: static PointerIntPair getFromOpaqueValue(void *V) { PointerIntPair P; P.setFromOpaqueValue(V); return P; } - + + // Allow PointerIntPairs to be created from const void * if and only if the + // pointer type could be created from a const void *. + static PointerIntPair getFromOpaqueValue(const void *V) { + (void)PtrTraits::getFromVoidPointer(V); + return getFromOpaqueValue(const_cast<void *>(V)); + } + bool operator==(const PointerIntPair &RHS) const {return Value == RHS.Value;} bool operator!=(const PointerIntPair &RHS) const {return Value != RHS.Value;} bool operator<(const PointerIntPair &RHS) const {return Value < RHS.Value;} @@ -158,6 +165,10 @@ public: getFromVoidPointer(void *P) { return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); } + static inline PointerIntPair<PointerTy, IntBits, IntType> + getFromVoidPointer(const void *P) { + return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); + } enum { NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits }; |