steinbergmedia / vstgui

A user interface toolkit mainly for audio plug-ins
Other
880 stars 124 forks source link

std::unique_ptr of forward-declared types #315

Closed sophiapoirier closed 10 months ago

sophiapoirier commented 10 months ago

vstgui/vstgui/lib/vstguifwd.h forward-declares a number of abstract base types and then also invalidly declares a bunch of type aliases of std::unique_ptr of those forward-declared types. This is not supported by the standard library as the std::unique_ptr's default deleter requires the size of the wrapped type, which is not available for a forward-declared type. It would appear that something about the organization of system headers has changed in some manner with C++23 enabled in the Xcode 15 toolchain such as to reveal this error, such as in the case of including vstgui.h:

In file included from vstgui/vstgui/vstgui.h:8:
In file included from vstgui/vstgui/lib/vstguibase.h:552:
In file included from vstgui/vstgui/lib/vstguidebug.h:30:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/memory:898:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/shared_ptr.h:31:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'VSTGUI::IPlatformGraphicsPath'
    static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
                  ^~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:297:7: note: in instantiation of member function 'std::default_delete<VSTGUI::IPlatformGraphicsPath>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:263:75: note: in instantiation of member function 'std::unique_ptr<VSTGUI::IPlatformGraphicsPath>::reset' requested here
  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
                                                                          ^
In file included from vstgui/vstgui/plugin-bindings/plugguieditor.cpp:6:
In file included from vstgui/vstgui/plugin-bindings/plugguieditor.h:8:
In file included from vstgui/vstgui/plugin-bindings/../vstgui.h:22:
vstgui/vstgui/lib/cgraphicspath.h:96:41: note: in instantiation of member function 'std::unique_ptr<VSTGUI::IPlatformGraphicsPath>::~unique_ptr' requested here
                                   PlatformGraphicsPathPtr&& path = nullptr);
                                                                    ^
In file included from vstgui/vstgui/plugin-bindings/plugguieditor.cpp:6:
In file included from vstgui/vstgui/plugin-bindings/plugguieditor.h:8:
In file included from vstgui/vstgui/plugin-bindings/../vstgui.h:9:
In file included from vstgui/vstgui/lib/cbitmap.h:7:
vstgui/vstgui/lib/vstguifwd.h:333:7: note: forward declaration of 'VSTGUI::IPlatformGraphicsPath'
class IPlatformGraphicsPath;
      ^

Similarly in vstgui/lib/platform/mac/macfactory.h VSTGUI:: MacFactory has an instance of std::unique_ptr<Impl> where Impl is forward-declared in the header:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__algorithm/inplace_merge.h:28:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'VSTGUI::MacFactory::Impl'
    static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
                  ^~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:297:7: note: in instantiation of member function 'std::default_delete<VSTGUI::MacFactory::Impl>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/__memory/unique_ptr.h:263:75: note: in instantiation of member function 'std::unique_ptr<VSTGUI::MacFactory::Impl>::reset' requested here
  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
                                                                          ^
vstgui/vstgui/lib/platform/mac/macfactory.h:15:7: note: in instantiation of member function 'std::unique_ptr<VSTGUI::MacFactory::Impl>::~unique_ptr' requested here
class MacFactory final : public IPlatformFactory
      ^
vstgui/vstgui/lib/platform/mac/macfactory.h:15:7: note: in implicit destructor for 'VSTGUI::MacFactory' first required here
vstgui/vstgui/lib/platform/mac/macfactory.h:142:9: note: forward declaration of 'VSTGUI::MacFactory::Impl'
        struct Impl;
               ^
scheffle commented 10 months ago

Thanks for the heads up. Currently vstgui is only tested in c++17 mode. There's no guarantee that it will work correctly in newer c++ modes at the moment. This is likely to change in the near future.