Push notifications example won't compile as-is, unless I explicitly convert raw pointer to unique_ptr?

I came across an error when compiling the JUCE (6.0.5) examples:

The two function calls to CallOutBox::launchAsynchronously() in PushNotificationsDemo.h produce the following error:

no viable conversion from 'juce::ColourSelector *' to 'std::unique_ptr<Component>'

The first parameter passed to the function – the one that causes the error – is a raw pointer to a new ColourSelector object, and clang expects an explicit conversion to a unique pointer. If I wrap the pointer in either of the lines in a unique_ptr constructor, then everything works just fine:

// compiler error:
CallOutBox::launchAsynchronously(paramControls.accentColourSelector, paramControls.accentColourButton.getScreenBounds(), nullptr);

// no error:
CallOutBox::launchAsynchronously(std::unique_ptr<juce::Component>(paramControls.accentColourSelector), paramControls.accentColourButton.getScreenBounds(), nullptr);

I’ve gotten it to work now, but I’m posting this to see if anyone can help me clear up the issue of why the unmodified example doesn’t work?

I’m not that experienced with C++ but it seems that implicit conversion should not be a problem? (And, of course, it can’t be if the example works just fine for everyone else.) I’m using the standard XCode version of clang (12.0.0) – haven’t gotten it to work with gcc at all so far so can’t comment on whether it’s just a compiler issue.

Any insights appreciated.

EDIT: formatting

This has been fixed on the develop branch here:

1 Like

Ah, ok, thanks for clearing that up.

Could you shed some light on why the compiler does not implicitly convert ColourSelector * to unique_ptr<Component>? Is it because unique_ptr is a template?