Removing noexcept specifications in constructors for Synchronized that call contextua...
authorAaryaman Sagar <aary@instagram.com>
Tue, 9 Aug 2016 01:43:01 +0000 (18:43 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Tue, 9 Aug 2016 01:53:27 +0000 (18:53 -0700)
Summary:
Most mutex lock() functions do not have a noexcept guarantee, saying that the
constructor for Synchronized based on whether the underlying constructor for
the type stored is not enough.  Although this will *rarely* cause bugs, it
probably can be fixed

Reviewed By: simpkins

Differential Revision: D3682974

fbshipit-source-id: ec0bb701d0af41ffc79128fe8db7935a5f19bc70

folly/Synchronized.h

index 1966087f844acfe7e3167bae31c740b8e03676fd..10c711cadf7ad3f7db144365508d0bcc6fdd5581 100644 (file)
@@ -335,15 +335,24 @@ struct Synchronized : public SynchronizedBase<
    * Copy constructor copies the data (with locking the source and
    * all) but does NOT copy the mutex. Doing so would result in
    * deadlocks.
+   *
+   * Note that the copy constructor may throw because it acquires a lock in
+   * the contextualRLock() method
    */
-  Synchronized(const Synchronized& rhs) noexcept(nxCopyCtor)
+  Synchronized(const Synchronized& rhs) /* may throw */
       : Synchronized(rhs, rhs.contextualRLock()) {}
 
   /**
    * Move constructor moves the data (with locking the source and all)
    * but does not move the mutex.
+   *
+   * Note that the move constructor may throw because it acquires a lock.
+   * Since the move constructor is not declared noexcept, when objects of this
+   * class are used as elements in a vector or a similar container.  The
+   * elements might not be moved around when resizing.  They might be copied
+   * instead.  You have been warned.
    */
-  Synchronized(Synchronized&& rhs) noexcept(nxMoveCtor)
+  Synchronized(Synchronized&& rhs) /* may throw */
       : Synchronized(std::move(rhs), rhs.contextualLock()) {}
 
   /**