[solved] FormatManager.createReaderFor and MemoryInputStream question

Hi,

I recently updated a plugin to build with VS2019 and a later version of JUCE (“final JUCE 5 commit”), and had to go through a few fixes related to ScopedPointer being phased out.
All fairly simple to fix, but there was another case where I didn’t find right away how to solve it, and for which I could use some feedback here:

This is the old code, that used to compile in VS2015 and a slightly older version of JUCE:

MemoryInputStream* stream = new MemoryInputStream(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(stream);

but in VS2019 and with the newer JUCE version now gives compilation error:

Error	C2664	'juce::AudioFormatReader *juce::AudioFormatManager::createReaderFor(const juce::File &)': cannot convert argument 1 from 'juce::MemoryInputStream *' to 'const juce::File &'

As the newer JUCE method signature uses std::unique_ptr, I then tried this (note that the createReaderFor method takes a std::unique_ptr<InputStream> and not a std::unique_ptr<MemoryInputStream>):

std::unique_ptr<InputStream> stream = std::make_unique<MemoryInputStream>(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(stream);

but that gave compilation error:

Error	C2280	'std::unique_ptr<ObjectType,std::default_delete<ObjectType>>::unique_ptr(const std::unique_ptr<ObjectType,std::default_delete<ObjectType>> &)': attempting to reference a deleted function

The way I got it to work was using a std::move, like so:

std::unique_ptr<InputStream> stream = std::make_unique<MemoryInputStream>(fileData, true);
AudioFormatReader* reader = m_FormatManager.createReaderFor(std::move(stream));

Is it normal that I need that explicit std::move here?

Yes, as the documentation for createReaderFor says :

Ah, missed that… That explains it, thanks!