Index: include/llvm/ADT/SmallPtrSet.h =================================================================== --- include/llvm/ADT/SmallPtrSet.h +++ include/llvm/ADT/SmallPtrSet.h @@ -18,6 +18,7 @@ #include "llvm/Config/abi-breaking.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/PointerLikeTypeTraits.h" +#include "llvm/Support/type_traits.h" #include #include #include @@ -343,7 +344,9 @@ /// to avoid encoding a particular small size in the interface boundary. template class SmallPtrSetImpl : public SmallPtrSetImplBase { + using ConstPtrType = typename add_const_past_pointer::type; typedef PointerLikeTypeTraits PtrTraits; + typedef PointerLikeTypeTraits ConstPtrTraits; protected: // Constructors that forward to the base. @@ -375,13 +378,12 @@ bool erase(PtrType Ptr) { return erase_imp(PtrTraits::getAsVoidPointer(Ptr)); } - /// count - Return 1 if the specified pointer is in the set, 0 otherwise. - size_type count(PtrType Ptr) const { + size_type count(ConstPtrType Ptr) const { return find(Ptr) != endPtr() ? 1 : 0; } - iterator find(PtrType Ptr) const { - auto *P = find_imp(PtrTraits::getAsVoidPointer(Ptr)); + iterator find(ConstPtrType Ptr) const { + auto *P = find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)); return iterator(P, EndPointer()); } Index: include/llvm/Support/PointerLikeTypeTraits.h =================================================================== --- include/llvm/Support/PointerLikeTypeTraits.h +++ include/llvm/Support/PointerLikeTypeTraits.h @@ -60,6 +60,20 @@ enum { NumLowBitsAvailable = 2 }; }; +// Provide PointerLikeTypeTraits for const things. +template class PointerLikeTypeTraits { + typedef PointerLikeTypeTraits NonConst; + +public: + static inline const void *getAsVoidPointer(const T P) { + return NonConst::getAsVoidPointer(P); + } + static inline const T getFromVoidPointer(const void *P) { + return NonConst::getFromVoidPointer(const_cast(P)); + } + enum { NumLowBitsAvailable = NonConst::NumLowBitsAvailable }; +}; + // Provide PointerLikeTypeTraits for const pointers. template class PointerLikeTypeTraits { typedef PointerLikeTypeTraits NonConst;