diff --git a/include/fast_io_dsal/impl/list.h b/include/fast_io_dsal/impl/list.h index d395e3866..bacaaf652 100644 --- a/include/fast_io_dsal/impl/list.h +++ b/include/fast_io_dsal/impl/list.h @@ -907,15 +907,19 @@ class list } inline constexpr list(list &&other) noexcept - : imp(other.imp) #if 0 - , allochdl(std::move(other.allochdl)) + : allochdl(std::move(other.allochdl)) #endif { - auto prev = static_cast<::fast_io::containers::details::list_node_common *>(imp.prev); - auto next = static_cast<::fast_io::containers::details::list_node_common *>(imp.next); - next->prev = prev->next = __builtin_addressof(imp); - other.imp = {__builtin_addressof(other.imp), __builtin_addressof(other.imp)}; + if (other.is_empty()) { + imp = {__builtin_addressof(imp), __builtin_addressof(imp)}; + } else { + imp = other.imp; + auto prev = static_cast<::fast_io::containers::details::list_node_common *>(imp.prev); + auto next = static_cast<::fast_io::containers::details::list_node_common *>(imp.next); + next->prev = prev->next = __builtin_addressof(imp); + other.imp = {__builtin_addressof(other.imp), __builtin_addressof(other.imp)}; + } } inline constexpr list &operator=(list &&other) noexcept diff --git a/tests/0026.container/0002.list/list_move.cc b/tests/0026.container/0002.list/list_move.cc new file mode 100644 index 000000000..9f9e348c8 --- /dev/null +++ b/tests/0026.container/0002.list/list_move.cc @@ -0,0 +1,27 @@ + +#include + +int main() { + ::fast_io::list l1{}; + if (!l1.is_empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l2(::std::move(l1)); + if (!l2.is_empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l3{}; + l3.emplace_back(1); + if (l3.is_empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l4(::std::move(l3)); + if (l4.is_empty()) { + ::fast_io::fast_terminate(); + } + + return 0; +}