diff --git a/modules/juce_audio_processors/format_types/juce_VST3Utilities.h b/modules/juce_audio_processors/format_types/juce_VST3Utilities.h index 14867972b0..a621ea89df 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3Utilities.h +++ b/modules/juce_audio_processors/format_types/juce_VST3Utilities.h @@ -166,8 +166,19 @@ class VSTComSmartPtr { public: VSTComSmartPtr() = default; - VSTComSmartPtr (const VSTComSmartPtr& other) noexcept : source (other.source) { if (source != nullptr) source->addRef(); } - ~VSTComSmartPtr() { if (source != nullptr) source->release(); } + + ~VSTComSmartPtr() + { + if (source != nullptr) + source->release(); + } + + VSTComSmartPtr (const VSTComSmartPtr& other) noexcept + : VSTComSmartPtr (other.get(), true) {} + + template , int> = 0> + VSTComSmartPtr (const VSTComSmartPtr& other) noexcept + : VSTComSmartPtr (other.get(), true) {} explicit operator bool() const noexcept { return operator!= (nullptr); } ObjectType* get() const noexcept { return source; } @@ -181,6 +192,12 @@ public: return *this; } + template , int> = 0> + VSTComSmartPtr& operator= (const VSTComSmartPtr& other) + { + return operator= (VSTComSmartPtr { other }); + } + VSTComSmartPtr& operator= (std::nullptr_t) { return operator= (VSTComSmartPtr{}); @@ -215,7 +232,13 @@ public: } private: - explicit VSTComSmartPtr (ObjectType* object, bool autoAddRef) noexcept : source (object) { if (source != nullptr && autoAddRef) source->addRef(); } + VSTComSmartPtr (ObjectType* object, bool autoAddRef) noexcept + : source (object) + { + if (source != nullptr && autoAddRef) + source->addRef(); + } + ObjectType* source = nullptr; };