juce_Array Array initialization and funky nullptr dereferencing

So I was trying my hand at doing some midi io. And I noticed some times .swapWith seemed to be failing. I had something like:

juce::MidiBuffer output_midi{};
output_midi.ensureSize( some_number );

AudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& input_midi) {
	for (int i = 0; i < buffer.getNumSamples(); ++i) {
		thingie.process(input_midi, output_midi, i, get_bpm());
	}
	
	input_midi.swapWith(output_midi);
	assert(output_midi.isEmpty());
}

I expected that assert to catch me not properly accounting for all inbound midi.

However it found .swapWith was failing on empty input_midi MidiBuffers. I had expected a populated input_midi and an empty output_midi (as in my test there was no input and I expect to be clearing it as used later and I was outputing some test midi), but found them unchanged after .swapWith.

It turns out it just didn’t do anything since swapWith is noexcept and that the Array object storage in input_midi wasn’t initialized. This is not an allocation issue. Empty stuff is fine.

My fix was simply:
On line 1106 of juce_Array.h from:

		ArrayBase<ElementType, TypeOfCriticalSectionToUse> values;

To:

		ArrayBase<ElementType, TypeOfCriticalSectionToUse> values{};

And to be complete juce_ArrayBase.h line 581 from:

		HeapBlock<ElementType> elements;

To:

		HeapBlock<ElementType> elements{};

Fixed. Now .switchWith works as intended. ArrayBase and HeapBlock don’t do anything crazy. all the {}'s just boil down to an = nullptr which is fine.

Now these container classes look to me like they were written sort of pre c++11’s wide adoption (okay yeah 2004). That took forever too, and don’t fix what ain’t broke etc.

But absolutely now that initialization has been ironed out and c++11 is well supported; that’s broken. I’m being handed a reference to an object that I didn’t create and silently can’t use .swapWith with. That was a surprise.

Though one could do input_midi.ensureSize(some_bytes) to force an allocation and then do .swapWith. That will also make things function.

However the safest option is to default init all that templated storage stuff (now it properly can be). Which sadly is non trivial since someone has to go read it all and double check that it is in fact sane to do so (but it’s probably sane (but you do need to check)). I have to think there must be more lurking nullptr dereferences with the noexcepts and the uninitialized base class storage; if I found one after all. (I did check the develop branch JIC; same issue)