From: Aaryaman Sagar Date: Tue, 9 Aug 2016 01:43:01 +0000 (-0700) Subject: Removing noexcept specifications in constructors for Synchronized that call contextua... X-Git-Tag: v2016.08.15.00~36 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=b26ef8ac2f904cff06d68f260134cb5a174fba95 Removing noexcept specifications in constructors for Synchronized that call contextualLock() and contextualRLock() 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 --- diff --git a/folly/Synchronized.h b/folly/Synchronized.h index 1966087f..10c711ca 100644 --- a/folly/Synchronized.h +++ b/folly/Synchronized.h @@ -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()) {} /**