Bug with OwnedArray on lastest develop branch

Hello @t0m !

I’ve just got a compilation error with the lastest JUCE on develop when trying to declare an OwnedArray on Windows 8.1 / VS2017:

c:\sdks\juce5\modules\juce_core\containers\juce_ownedarray.h(235): error C2440: ‘return’: cannot convert from ‘ObjectClass *const *’ to ‘ObjectClass **’

The function data() const should be data() instead maybe ?

And there is something else happening with ArrayBase:

c:\sdks\juce5\modules\juce_core\containers\juce_arraybase.h(330): error C2662: ‘ObjectClass **juce::OwnedArray<ObjectClass,juce::DummyCriticalSection>::data(void) noexcept’: cannot convert ‘this’ pointer from ‘const OtherArrayType’ to ‘juce::OwnedArray<stuff,juce::DummyCriticalSection> &’

Is it something linked with my code or an issue with the SDK on Windows ?

Thanks in advance !

What are you compiling? Looks like you’ve got some const incorrectness going on when calling some Array methods?

I think this is the issue:

    inline ObjectClass* const* begin() const noexcept
    {
        return values.begin();
    }


    inline ObjectClass** data() const noexcept
    {
        return begin();
    }

The const overload of begin() returns ObjectClass* const*, which doesn’t convert to ObjectClass** returned by data().

I wonder why these methods are explicitly inline :thinking:

I think the line in my code causing the issue is something like this:

arrayComponents.addArray(*arrayAudioComp, 0, arrayAudioComp->size())

The error is linked with data() and begin() code above, and also what happens in ArrayBase…

Replacing addArray with a for loop with add on each element works fine

This looks like a candidate for some function templating to add const to the type to clear up the final return type, maybe?
https://en.cppreference.com/w/cpp/types/add_cv

Mmmmm…Hi @IvanC ? I guess this was a typo to address me here? :wink:
My comment would be: the compiler is always right :wink:

1 Like

Ho sorry I wanted to address @t0m instead with a zero instead of a o :joy::joy::joy:

@reuk has the fix for at least the first error. I’ll get that pushed.

Thank you for reporting!

1 Like