Bug 1271182 - Add some deleted assignment operators and copy constructors. r=khuey
authorL. David Baron <dbaron@dbaron.org>
Wed, 25 May 2016 18:04:35 -0700
changeset 338052 bd4cebf613e67bc4e04e94a5239879194819f4c0
parent 338051 26b2ba6d410853e03239e684c6255fc44252b1c1
child 338053 abafa95db1b11babb82ee2b32cd8c0bac784711c
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1271182
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1271182 - Add some deleted assignment operators and copy constructors. r=khuey These are generally good practice for reference-counted objects; they catch cases where these operations are used by accident, breaking reference-counting. This doesn't show any existing problems, though. MozReview-Commit-ID: EvRkNCymOqT
xpcom/glue/nsThreadUtils.h
xpcom/threads/TimerThread.cpp
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -227,31 +227,39 @@ class Runnable : public nsIRunnable
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   Runnable() {}
 
 protected:
   virtual ~Runnable() {}
+private:
+  Runnable(const Runnable&) = delete;
+  Runnable& operator=(const Runnable&) = delete;
+  Runnable& operator=(const Runnable&&) = delete;
 };
 
 // This class is designed to be subclassed.
 class CancelableRunnable : public Runnable,
                            public nsICancelableRunnable
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   // nsICancelableRunnable
   virtual nsresult Cancel() override;
 
   CancelableRunnable() {}
 
 protected:
   virtual ~CancelableRunnable() {}
+private:
+  CancelableRunnable(const CancelableRunnable&) = delete;
+  CancelableRunnable& operator=(const CancelableRunnable&) = delete;
+  CancelableRunnable& operator=(const CancelableRunnable&&) = delete;
 };
 
 } // namespace mozilla
 
 // An event that can be used to call a C++11 functions or function objects,
 // including lambdas. The function must have no required arguments, and must
 // return void.
 template<typename Function>
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -183,16 +183,20 @@ public:
 
   void SetTimer(already_AddRefed<nsTimerImpl> aTimer)
   {
     mTimer = aTimer;
     mGeneration = mTimer->GetGeneration();
   }
 
 private:
+  nsTimerEvent(const nsTimerEvent&) = delete;
+  nsTimerEvent& operator=(const nsTimerEvent&) = delete;
+  nsTimerEvent& operator=(const nsTimerEvent&&) = delete;
+
   ~nsTimerEvent()
   {
     MOZ_COUNT_DTOR(nsTimerEvent);
 
     MOZ_ASSERT(!sCanDeleteAllocator || sAllocatorUsers > 0,
                "This will result in us attempting to deallocate the nsTimerEvent allocator twice");
     sAllocatorUsers--;
   }