diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index f487f3c831..67e6888908 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -23,6 +23,53 @@ namespace juce { +#ifndef DOXYGEN +/** The contents of this namespace are used to implement AudioBuffer and should + not be used elsewhere. Their interfaces (and existence) are liable to change! +*/ +namespace detail +{ + /** On iOS/arm7 the alignment of `double` is greater than the alignment of + `std::max_align_t`, so we can't trust max_align_t. Instead, we query + lots of primitive types and use the maximum alignment of all of them. + + We're putting this stuff outside AudioBuffer itself to avoid creating + unnecessary copies for each distinct template instantiation of + AudioBuffer. + + MSVC 2015 doesn't like when we write getMaxAlignment as a loop which + accumulates the max alignment (declarations not allowed in constexpr + function body) so instead we use this recursive version which + instantiates a zillion templates. + */ + + template struct Type {}; + + constexpr size_t getMaxAlignment() noexcept { return 0; } + + template + constexpr size_t getMaxAlignment (Type, Type... tail) noexcept + { + return jmax (alignof (Head), getMaxAlignment (tail...)); + } + + constexpr size_t maxAlignment = getMaxAlignment (Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}, + Type{}); +} // namespace detail +#endif + //============================================================================== /** A multi-channel buffer containing floating point audio samples. @@ -1076,7 +1123,7 @@ private: void allocateData() { #if (! JUCE_GCC) || (__GNUC__ * 100 + __GNUC_MINOR__) >= 409 - static_assert (std::alignment_of::value <= std::alignment_of::value, + static_assert (alignof (Type) <= detail::maxAlignment, "AudioBuffer cannot hold types with alignment requirements larger than that guaranteed by malloc"); #endif jassert (size >= 0);