[PATCH] D24811: [sanitizer_common] Delete some copy/move methods in InternalScopedBuffer

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 10:44:02 PDT 2016


vsk created this revision.
vsk added reviewers: kcc, samsonov, eugenis.
vsk added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.

The copy assignment operator for InternalScopedBuffer hasn't been deleted properly. This patch deletes the {copy, move} {constructors, assignment operators} and does a clang-format.

This came up because I'd like to write code that takes ownership of an InternalScopedString. We'd need some kind of std::move function available in compiler-rt to do this. I rolled a custom one (since #including <utility> isn't allowed?), but would like to gather feedback on the idea before uploading more patches.

https://reviews.llvm.org/D24811

Files:
  lib/sanitizer_common/sanitizer_common.h

Index: lib/sanitizer_common/sanitizer_common.h
===================================================================
--- lib/sanitizer_common/sanitizer_common.h
+++ lib/sanitizer_common/sanitizer_common.h
@@ -118,26 +118,26 @@
 // keep frame size low.
 // FIXME: use InternalAlloc instead of MmapOrDie once
 // InternalAlloc is made libc-free.
-template<typename T>
+template <typename T>
 class InternalScopedBuffer {
  public:
   explicit InternalScopedBuffer(uptr cnt) {
     cnt_ = cnt;
-    ptr_ = (T*)MmapOrDie(cnt * sizeof(T), "InternalScopedBuffer");
-  }
-  ~InternalScopedBuffer() {
-    UnmapOrDie(ptr_, cnt_ * sizeof(T));
+    ptr_ = (T *)MmapOrDie(cnt * sizeof(T), "InternalScopedBuffer");
   }
+  ~InternalScopedBuffer() { UnmapOrDie(ptr_, cnt_ * sizeof(T)); }
   T &operator[](uptr i) { return ptr_[i]; }
   T *data() { return ptr_; }
   uptr size() { return cnt_ * sizeof(T); }
 
  private:
   T *ptr_;
   uptr cnt_;
-  // Disallow evil constructors.
-  InternalScopedBuffer(const InternalScopedBuffer&);
-  void operator=(const InternalScopedBuffer&);
+  // Disallow copies and moves.
+  InternalScopedBuffer(const InternalScopedBuffer &) = delete;
+  InternalScopedBuffer &operator=(const InternalScopedBuffer &) = delete;
+  InternalScopedBuffer(InternalScopedBuffer &&) = delete;
+  InternalScopedBuffer &operator=(InternalScopedBuffer &&) = delete;
 };
 
 class InternalScopedString : public InternalScopedBuffer<char> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24811.72085.patch
Type: text/x-patch
Size: 1440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160921/b48b732f/attachment.bin>


More information about the llvm-commits mailing list