From aae1b51a731d9777da34e308a6d93c9803395ef8 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Sun, 16 Nov 2025 00:40:41 +0800 Subject: [PATCH 1/2] Bugfix: move construct an empty fast_io::list - before this patch, the list_move.cc#L10 will crash --- include/fast_io_dsal/impl/list.h | 16 +++++++----- tests/0026.container/0002.list/list_move.cc | 27 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tests/0026.container/0002.list/list_move.cc diff --git a/include/fast_io_dsal/impl/list.h b/include/fast_io_dsal/impl/list.h index d395e3866..3e91bc48b 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.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..2a63e7473 --- /dev/null +++ b/tests/0026.container/0002.list/list_move.cc @@ -0,0 +1,27 @@ + +#include + +int main() { + ::fast_io::list l1{}; + if (!l1.empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l2(::std::move(l1)); + if (!l2.empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l3{}; + l3.emplace_back(1); + if (l3.empty()) { + ::fast_io::fast_terminate(); + } + + ::fast_io::list l4(::std::move(l3)); + if (l4.empty()) { + ::fast_io::fast_terminate(); + } + + return 0; +} From 455c86979baa813d3808009719a3cef950e42bb5 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Sun, 16 Nov 2025 10:33:43 +0800 Subject: [PATCH 2/2] replace list.empty to list.is_empty --- include/fast_io_dsal/impl/list.h | 2 +- tests/0026.container/0002.list/list_move.cc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/fast_io_dsal/impl/list.h b/include/fast_io_dsal/impl/list.h index 3e91bc48b..bacaaf652 100644 --- a/include/fast_io_dsal/impl/list.h +++ b/include/fast_io_dsal/impl/list.h @@ -911,7 +911,7 @@ class list : allochdl(std::move(other.allochdl)) #endif { - if (other.empty()) { + if (other.is_empty()) { imp = {__builtin_addressof(imp), __builtin_addressof(imp)}; } else { imp = other.imp; diff --git a/tests/0026.container/0002.list/list_move.cc b/tests/0026.container/0002.list/list_move.cc index 2a63e7473..9f9e348c8 100644 --- a/tests/0026.container/0002.list/list_move.cc +++ b/tests/0026.container/0002.list/list_move.cc @@ -3,23 +3,23 @@ int main() { ::fast_io::list l1{}; - if (!l1.empty()) { + if (!l1.is_empty()) { ::fast_io::fast_terminate(); } ::fast_io::list l2(::std::move(l1)); - if (!l2.empty()) { + if (!l2.is_empty()) { ::fast_io::fast_terminate(); } ::fast_io::list l3{}; l3.emplace_back(1); - if (l3.empty()) { + if (l3.is_empty()) { ::fast_io::fast_terminate(); } ::fast_io::list l4(::std::move(l3)); - if (l4.empty()) { + if (l4.is_empty()) { ::fast_io::fast_terminate(); }