diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 63e088dae2..c39622d550 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -72,7 +72,7 @@ private: public: //============================================================================== /** Creates an empty array. */ - Array() = default; + Array() noexcept = default; /** Creates a copy of another array. @param other the array to copy diff --git a/modules/juce_core/containers/juce_ArrayBase.h b/modules/juce_core/containers/juce_ArrayBase.h index d322191365..8ae8997271 100644 --- a/modules/juce_core/containers/juce_ArrayBase.h +++ b/modules/juce_core/containers/juce_ArrayBase.h @@ -54,13 +54,16 @@ class ArrayBase : public TypeOfCriticalSectionToUse private: using ParameterType = typename TypeHelpers::ParameterType::type; + static_assert (std::is_nothrow_constructible_v, + "The critical section type used must not throw during construction"); + template using AllowConversion = std::enable_if_t, std::tuple>>; public: //============================================================================== - ArrayBase() = default; + ArrayBase() noexcept = default; ~ArrayBase() { diff --git a/modules/juce_core/containers/juce_ListenerList.h b/modules/juce_core/containers/juce_ListenerList.h index 563921951c..2b45c35f09 100644 --- a/modules/juce_core/containers/juce_ListenerList.h +++ b/modules/juce_core/containers/juce_ListenerList.h @@ -388,6 +388,12 @@ private: if (state.compare_exchange_strong (expected, State::initialising)) { + static_assert (std::is_nothrow_constructible_v, + "Any ListenerList ArrayType must have a noexcept default constructor"); + + static_assert (std::is_nothrow_constructible_v, + "Please notify the JUCE team if you encounter this assertion"); + listeners = std::make_shared(); iterators = std::make_shared(); state = State::initialised; diff --git a/modules/juce_core/containers/juce_ListenerList_test.cpp b/modules/juce_core/containers/juce_ListenerList_test.cpp index 8df2d5a81e..e8da6236d7 100644 --- a/modules/juce_core/containers/juce_ListenerList_test.cpp +++ b/modules/juce_core/containers/juce_ListenerList_test.cpp @@ -384,11 +384,11 @@ public: struct TestCriticalSection { - TestCriticalSection() { isAlive() = true; } - ~TestCriticalSection() { isAlive() = false; } + TestCriticalSection() noexcept { isAlive() = true; } + ~TestCriticalSection() noexcept { isAlive() = false; } static void enter() noexcept { numOutOfScopeCalls() += isAlive() ? 0 : 1; } - static void exit() noexcept { numOutOfScopeCalls() += isAlive() ? 0 : 1; } + static void exit() noexcept { numOutOfScopeCalls() += isAlive() ? 0 : 1; } static bool tryEnter() noexcept { @@ -398,13 +398,13 @@ public: using ScopedLockType = GenericScopedLock; - static bool& isAlive() + static bool& isAlive() noexcept { static bool inScope = false; return inScope; } - static int& numOutOfScopeCalls() + static int& numOutOfScopeCalls() noexcept { static int numOutOfScopeCalls = 0; return numOutOfScopeCalls; diff --git a/modules/juce_core/memory/juce_HeapBlock.h b/modules/juce_core/memory/juce_HeapBlock.h index 4b7a05e0b3..f459fadc81 100644 --- a/modules/juce_core/memory/juce_HeapBlock.h +++ b/modules/juce_core/memory/juce_HeapBlock.h @@ -109,7 +109,7 @@ public: After creation, you can resize the array using the malloc(), calloc(), or realloc() methods. */ - HeapBlock() = default; + HeapBlock() noexcept = default; /** Creates a HeapBlock containing a number of elements.