diff --git a/llvm/include/llvm/ADT/TinyPtrVector.h b/llvm/include/llvm/ADT/TinyPtrVector.h index 15137f5ebf8c..58590f49dfe4 100644 --- a/llvm/include/llvm/ADT/TinyPtrVector.h +++ b/llvm/include/llvm/ADT/TinyPtrVector.h @@ -25,11 +25,14 @@ namespace llvm { template class TinyPtrVector { public: - typedef llvm::SmallVector VecTy; - typedef typename VecTy::value_type value_type; + using VecTy = llvm::SmallVector; + using value_type = typename VecTy::value_type; + using PtrUnion = llvm::PointerUnion; - llvm::PointerUnion Val; +private: + PtrUnion Val; +public: TinyPtrVector() {} ~TinyPtrVector() { if (VecTy *V = Val.template dyn_cast()) @@ -96,12 +99,13 @@ public: return *this; } - /// Constructor from a single element. - explicit TinyPtrVector(EltTy Elt) : Val(Elt) {} - /// Constructor from an ArrayRef. + /// + /// This also is a constructor for individual array elements due to the single + /// element constructor for ArrayRef. explicit TinyPtrVector(ArrayRef Elts) - : Val(new VecTy(Elts.begin(), Elts.end())) {} + : Val(Elts.size() == 1 ? PtrUnion(Elts[0]) + : PtrUnion(new VecTy(Elts.begin(), Elts.end()))) {} // implicit conversion operator to ArrayRef. operator ArrayRef() const {