1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

ListenerList: Assert if initialisation could throw for any reason other than a bad allocation

This commit is contained in:
Anthony Nicholls 2024-06-13 14:25:47 +01:00
parent 06fb8f4ea2
commit 0d8f2c63ec
5 changed files with 17 additions and 8 deletions

View file

@ -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

View file

@ -54,13 +54,16 @@ class ArrayBase : public TypeOfCriticalSectionToUse
private:
using ParameterType = typename TypeHelpers::ParameterType<ElementType>::type;
static_assert (std::is_nothrow_constructible_v<TypeOfCriticalSectionToUse>,
"The critical section type used must not throw during construction");
template <class OtherElementType, class OtherCriticalSection>
using AllowConversion = std::enable_if_t<! std::is_same_v<std::tuple<ElementType, TypeOfCriticalSectionToUse>,
std::tuple<OtherElementType, OtherCriticalSection>>>;
public:
//==============================================================================
ArrayBase() = default;
ArrayBase() noexcept = default;
~ArrayBase()
{

View file

@ -388,6 +388,12 @@ private:
if (state.compare_exchange_strong (expected, State::initialising))
{
static_assert (std::is_nothrow_constructible_v<ArrayType>,
"Any ListenerList ArrayType must have a noexcept default constructor");
static_assert (std::is_nothrow_constructible_v<SafeIterators>,
"Please notify the JUCE team if you encounter this assertion");
listeners = std::make_shared<ArrayType>();
iterators = std::make_shared<SafeIterators>();
state = State::initialised;

View file

@ -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<TestCriticalSection>;
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;