Skip to content

Commit

Permalink
Merge pull request #11981 from Swiftb0y/refactor/parented_ptr
Browse files Browse the repository at this point in the history
Refactor(parented_ptr): make trivially destructible in release mode, delete move operations
  • Loading branch information
daschuer committed Sep 17, 2023
2 parents d7afa37 + 6801d6b commit 658cb7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/util/parented_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ class parented_ptr final {
explicit parented_ptr(T* t) noexcept
: m_ptr{t} {
}

// Only generate destructor if not empty, otherwise its empty but will
// cause the parented_ptr to be not trivially destructible even though it could be.
#ifdef MIXXX_DEBUG_ASSERTIONS_ENABLED
~parented_ptr() noexcept {
DEBUG_ASSERT(!m_ptr || static_cast<const QObject*>(m_ptr)->parent());
}

// Delete copy constructor and copy assignment operator
#else
// explicitly generate trivial destructor (since decltype(m_ptr) is not a class type)
~parented_ptr() noexcept = default;
#endif
// Rule of 5
parented_ptr(const parented_ptr<T>&) = delete;
parented_ptr& operator=(const parented_ptr<T>&) = delete;
parented_ptr(const parented_ptr<T>&& other) = delete;
parented_ptr& operator=(const parented_ptr<T>&& other) = delete;

// If U* is convertible to T* then parented_ptr<U> is convertible to parented_ptr<T>
template<
Expand Down
11 changes: 3 additions & 8 deletions src/widget/findonwebmenufactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ namespace mixxx {
namespace library {

void createFindOnWebSubmenus(QMenu* pFindOnWebMenu, const Track& track) {
auto pFindOnWebMenuSoundcloud = make_parented<QMenu>(
new FindOnWebMenuSoundcloud(pFindOnWebMenu, track));

auto pFindOnWebMenuDiscogs = make_parented<QMenu>(
new FindOnWebMenuDiscogs(pFindOnWebMenu, track));

auto pFindOnWebMenuLastfm = make_parented<QMenu>(
new FindOnWebMenuLastfm(pFindOnWebMenu, track));
make_parented<QMenu>(new FindOnWebMenuSoundcloud(pFindOnWebMenu, track));
make_parented<QMenu>(new FindOnWebMenuDiscogs(pFindOnWebMenu, track));
make_parented<QMenu>(new FindOnWebMenuLastfm(pFindOnWebMenu, track));
}

} // namespace library
Expand Down

0 comments on commit 658cb7c

Please sign in to comment.