Skip to content

mkv: events: move event data to std::variant

An object like std::shared_ptr cannot be placed into a C-like union because the destructor cannot be safely called. By moving the union to std::variant, we have type-safe guarantees without additional runtime cost and integrate the button_data inside it.

As it removes the need to initialize the union, it fixes the following warning:

In file included from demux/mkv/demux.hpp:32,
                 from demux/mkv/events.cpp:25:
In copy constructor 'mkv::event_thread_t::EventInfo::EventInfo(const mkv::event_thread_t::EventInfo&)',
    inlined from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = mkv::event_thread_t::EventInfo; _Args = {const mkv::event_thread_t::EventInfo&}; _Tp = std::_List_node<mkv::event_thread_t::EventInfo>]' at /usr/include/c++/13/bits/new_allocator.h:191:4,
    inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = mkv::event_thread_t::EventInfo; _Args = {const mkv::event_thread_t::EventInfo&}; _Tp = std::_List_node<mkv::event_thread_t::EventInfo>]' at /usr/include/c++/13/bits/alloc_traits.h:538:17,
    inlined from 'std::__cxx11::list<_Tp, _Alloc>::_Node* std::__cxx11::list<_Tp, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const mkv::event_thread_t::EventInfo&}; _Tp = mkv::event_thread_t::EventInfo; _Alloc = std::allocator<mkv::event_thread_t::EventInfo>]' at /usr/include/c++/13/bits/stl_list.h:713:33,
    inlined from 'void std::__cxx11::list<_Tp, _Alloc>::_M_insert(iterator, _Args&& ...) [with _Args = {const mkv::event_thread_t::EventInfo&}; _Tp = mkv::event_thread_t::EventInfo; _Alloc = std::allocator<mkv::event_thread_t::EventInfo>]' at /usr/include/c++/13/bits/stl_list.h:2005:32,
    inlined from 'void std::__cxx11::list<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = mkv::event_thread_t::EventInfo; _Alloc = std::allocator<mkv::event_thread_t::EventInfo>]' at /usr/include/c++/13/bits/stl_list.h:1306:24,
    inlined from 'void mkv::event_thread_t::QueueEvent(EventInfo)' at demux/mkv/events.hpp:142:33,
    inlined from 'void mkv::event_thread_t::SendData(mkv::mkv_track_t&, block_t*)' at demux/mkv/events.cpp:52:23:
demux/mkv/events.hpp:72:12: warning: '<unnamed>.mkv::event_thread_t::EventInfo::<anonymous>' may be used uninitialized [-Wmaybe-uninitialized]
   72 |     struct EventInfo {
      |            ^~~~~~~~~
  CXX      demux/hls/playlist/libvlc_adaptive_la-Tags.lo
demux/mkv/events.cpp: In member function 'void mkv::event_thread_t::SendData(mkv::mkv_track_t&, block_t*)':
demux/mkv/events.cpp:52:44: note: '<anonymous>' declared here
   52 |             QueueEvent( EventInfo{ p_block } );
      |                                            ^

Merge request reports