Skip to content

Commit

Permalink
Annotate throwing destructors with noexcept(false) (facebookincubat…
Browse files Browse the repository at this point in the history
…or#250)

Summary:
In C++11 destructors default to `noexcept(true)`.
Both gcc and clang will treat `throw` in destructor as `terminate()` call
Pull Request resolved: facebookincubator#250

Test Plan: CI

Reviewed By: ezyang

Differential Revision: D20473464

Pulled By: malfet

fbshipit-source-id: 8ab36c23868ff7d5a34258ed2441b5151b4a801c
  • Loading branch information
malfet authored and facebook-github-bot committed Mar 17, 2020
1 parent b2ff1aa commit 7356410
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gloo/algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Algorithm::Algorithm(const std::shared_ptr<Context>& context)
contextSize_(context_->size) {}

// Have to provide implementation for pure virtual destructor.
Algorithm::~Algorithm() {}
Algorithm::~Algorithm() noexcept(false) {}

std::unique_ptr<transport::Pair>& Algorithm::getPair(int i) {
return context_->getPair(i);
Expand Down
4 changes: 2 additions & 2 deletions gloo/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern const size_t kOnDeviceThreshold;
class Algorithm {
public:
explicit Algorithm(const std::shared_ptr<Context>&);
virtual ~Algorithm() = 0;
virtual ~Algorithm() noexcept(false) = 0;

virtual void run() = 0;

Expand Down Expand Up @@ -101,7 +101,7 @@ const ReductionFunction<T>* ReductionFunction<T>::max =
template <typename T>
class LocalOp {
public:
virtual ~LocalOp() {}
virtual ~LocalOp() noexcept(false) {}
virtual void runAsync() = 0;
virtual void wait() = 0;

Expand Down
6 changes: 3 additions & 3 deletions gloo/cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CudaStream::CudaStream(CudaStream&& other) noexcept
other.event_ = nullptr;
}

CudaStream::~CudaStream() {
CudaStream::~CudaStream() noexcept(false) {
if (deviceId_ == kInvalidDeviceId) {
return;
}
Expand Down Expand Up @@ -216,7 +216,7 @@ CudaDevicePointer<T>& CudaDevicePointer<T>::operator=(
}

template<typename T>
CudaDevicePointer<T>::~CudaDevicePointer() {
CudaDevicePointer<T>::~CudaDevicePointer() noexcept(false) {
if (deviceId_ == kInvalidDeviceId) {
return;
}
Expand Down Expand Up @@ -266,7 +266,7 @@ CudaHostPointer<T>& CudaHostPointer<T>::operator=(CudaHostPointer<T>&& other) {
}

template<typename T>
CudaHostPointer<T>::~CudaHostPointer() {
CudaHostPointer<T>::~CudaHostPointer() noexcept(false) {
if (owner_) {
std::lock_guard<std::mutex> lock(CudaShared::getMutex());
CUDA_CHECK(cudaFreeHost(host_));
Expand Down
6 changes: 3 additions & 3 deletions gloo/cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CudaStream {
// Move constructor
CudaStream(CudaStream&& other) noexcept;

~CudaStream();
~CudaStream() noexcept(false);

cudaStream_t operator*() const {
return stream_;
Expand Down Expand Up @@ -125,7 +125,7 @@ class CudaDevicePointer {
}

CudaDevicePointer(CudaDevicePointer&&) noexcept;
~CudaDevicePointer();
~CudaDevicePointer() noexcept(false);

// Default constructor creates invalid instance
CudaDevicePointer()
Expand Down Expand Up @@ -195,7 +195,7 @@ class CudaHostPointer {
}

CudaHostPointer(CudaHostPointer&&) noexcept;
~CudaHostPointer();
~CudaHostPointer() noexcept(false);

// Default constructor creates invalid instance
CudaHostPointer() : CudaHostPointer(nullptr, 0, false) {}
Expand Down
2 changes: 1 addition & 1 deletion gloo/cuda_private.cu
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CudaMemory<T>::CudaMemory(CudaMemory<T>&& other) noexcept
}

template<typename T>
CudaMemory<T>::~CudaMemory() {
CudaMemory<T>::~CudaMemory() noexcept(false) {
CudaDeviceScope scope(device_);
if (ptr_ != nullptr) {
// Sychronize memory allocation with NCCL operations
Expand Down
4 changes: 2 additions & 2 deletions gloo/cuda_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CudaDeviceGuard {
CudaDeviceGuard() : previous_(getCurrentGPUID()) {
}

~CudaDeviceGuard() {
~CudaDeviceGuard() noexcept(false) {
CUDA_CHECK(cudaSetDevice(previous_));
}

Expand All @@ -124,7 +124,7 @@ class CudaMemory {
public:
explicit CudaMemory(size_t elements);
CudaMemory(CudaMemory&&) noexcept;
~CudaMemory();
~CudaMemory() noexcept(false);

T* operator*() const {
return ptr_;
Expand Down

0 comments on commit 7356410

Please sign in to comment.