From 2b639d5c7e74a4c7482f3d6c7a2f4bde2e256409 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Mon, 3 Nov 2025 09:08:06 +0800 Subject: [PATCH 1/2] mark gnu::const to some method - which help to some static analysis --- include/fast_io_dsal/impl/list.h | 14 ++++++++++---- include/fast_io_dsal/impl/queue.h | 13 +++++++++++++ include/fast_io_dsal/impl/stack.h | 13 +++++++++++++ include/fast_io_dsal/impl/string.h | 15 ++++++++++++++- include/fast_io_dsal/impl/string_view.h | 9 +++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/include/fast_io_dsal/impl/list.h b/include/fast_io_dsal/impl/list.h index d395e3866..4b7a4d332 100644 --- a/include/fast_io_dsal/impl/list.h +++ b/include/fast_io_dsal/impl/list.h @@ -605,11 +605,17 @@ class list return const_reverse_iterator({__builtin_addressof(imp)}); } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif [[nodiscard]] inline constexpr bool empty() const noexcept { return imp.next == __builtin_addressof(imp); } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif [[nodiscard]] inline constexpr bool is_empty() const noexcept { return imp.next == __builtin_addressof(imp); @@ -908,9 +914,9 @@ class list inline constexpr list(list &&other) noexcept : imp(other.imp) - #if 0 +#if 0 , allochdl(std::move(other.allochdl)) - #endif +#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); @@ -924,9 +930,9 @@ class list { this->destroy(); imp = other.imp; - #if 0 +#if 0 allochdl = ::std::move(other.allochdl); - #endif +#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); diff --git a/include/fast_io_dsal/impl/queue.h b/include/fast_io_dsal/impl/queue.h index 07e27dbfc..2b4eac8f2 100644 --- a/include/fast_io_dsal/impl/queue.h +++ b/include/fast_io_dsal/impl/queue.h @@ -69,6 +69,10 @@ class queue return container.back_unchecked(); } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool empty() const noexcept { if constexpr (requires() { @@ -83,11 +87,19 @@ class queue } } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool is_empty() const noexcept { return container.is_empty(); } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr size_type size() const noexcept requires(requires() { container.size(); @@ -95,6 +107,7 @@ class queue { return container.size(); } + inline constexpr void push(value_type const &value) { container.push_back(value); diff --git a/include/fast_io_dsal/impl/stack.h b/include/fast_io_dsal/impl/stack.h index 5fab80c19..f31fe8135 100644 --- a/include/fast_io_dsal/impl/stack.h +++ b/include/fast_io_dsal/impl/stack.h @@ -87,6 +87,10 @@ class stack } } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool empty() const noexcept { if constexpr (requires() { @@ -101,11 +105,19 @@ class stack } } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool is_empty() const noexcept { return container.is_empty(); } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr size_type size() const noexcept requires(requires() { container.size(); @@ -113,6 +125,7 @@ class stack { return container.size(); } + inline constexpr void push(value_type const &value) { if constexpr (requires() { diff --git a/include/fast_io_dsal/impl/string.h b/include/fast_io_dsal/impl/string.h index 5f4eedf72..3c3263155 100644 --- a/include/fast_io_dsal/impl/string.h +++ b/include/fast_io_dsal/impl/string.h @@ -218,20 +218,33 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return imp.begin_ptr; } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool is_empty() const noexcept { return imp.begin_ptr == imp.curr_ptr; } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr bool empty() const noexcept { return imp.begin_ptr == imp.curr_ptr; } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif + [[nodiscard]] inline constexpr size_type size() const noexcept { return static_cast(imp.curr_ptr - imp.begin_ptr); } + inline constexpr size_type size_bytes() const noexcept { return static_cast(imp.curr_ptr - imp.begin_ptr) * sizeof(value_type); @@ -524,7 +537,7 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE this->assign_impl(other.imp.begin_ptr, static_cast<::std::size_t>(other.imp.curr_ptr - other.imp.begin_ptr)); return *this; } - inline constexpr basic_string& operator=(string_view_type const &other) noexcept + inline constexpr basic_string &operator=(string_view_type const &other) noexcept { this->assign(other); return *this; diff --git a/include/fast_io_dsal/impl/string_view.h b/include/fast_io_dsal/impl/string_view.h index ac377d3c0..24c73a230 100644 --- a/include/fast_io_dsal/impl/string_view.h +++ b/include/fast_io_dsal/impl/string_view.h @@ -66,16 +66,25 @@ class basic_string_view const_pointer ptr{}; size_type n{}; +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif [[nodiscard]] inline constexpr bool is_empty() const noexcept { return !n; } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif [[nodiscard]] inline constexpr bool empty() const noexcept { return !n; } +#if __has_cpp_attribute(__gnu__::__const__) + [[__gnu__::__const__]] +#endif [[nodiscard]] inline constexpr size_type size() const noexcept { return n; From ff8dc8f620019bd0a46282545da77c1d55370154 Mon Sep 17 00:00:00 2001 From: Arendelle Date: Mon, 3 Nov 2025 23:20:01 +0800 Subject: [PATCH 2/2] replace gnu::const to gnu::pure --- include/fast_io_dsal/impl/list.h | 8 ++++---- include/fast_io_dsal/impl/queue.h | 12 ++++++------ include/fast_io_dsal/impl/stack.h | 12 ++++++------ include/fast_io_dsal/impl/string.h | 12 ++++++------ include/fast_io_dsal/impl/string_view.h | 12 ++++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/fast_io_dsal/impl/list.h b/include/fast_io_dsal/impl/list.h index 4b7a4d332..3a302749a 100644 --- a/include/fast_io_dsal/impl/list.h +++ b/include/fast_io_dsal/impl/list.h @@ -605,16 +605,16 @@ class list return const_reverse_iterator({__builtin_addressof(imp)}); } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool empty() const noexcept { return imp.next == __builtin_addressof(imp); } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool is_empty() const noexcept { diff --git a/include/fast_io_dsal/impl/queue.h b/include/fast_io_dsal/impl/queue.h index 2b4eac8f2..7f86ec858 100644 --- a/include/fast_io_dsal/impl/queue.h +++ b/include/fast_io_dsal/impl/queue.h @@ -69,8 +69,8 @@ class queue return container.back_unchecked(); } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool empty() const noexcept @@ -87,8 +87,8 @@ class queue } } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool is_empty() const noexcept @@ -96,8 +96,8 @@ class queue return container.is_empty(); } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr size_type size() const noexcept diff --git a/include/fast_io_dsal/impl/stack.h b/include/fast_io_dsal/impl/stack.h index f31fe8135..8773f90bb 100644 --- a/include/fast_io_dsal/impl/stack.h +++ b/include/fast_io_dsal/impl/stack.h @@ -87,8 +87,8 @@ class stack } } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool empty() const noexcept @@ -105,8 +105,8 @@ class stack } } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool is_empty() const noexcept @@ -114,8 +114,8 @@ class stack return container.is_empty(); } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr size_type size() const noexcept diff --git a/include/fast_io_dsal/impl/string.h b/include/fast_io_dsal/impl/string.h index 3c3263155..057e2309a 100644 --- a/include/fast_io_dsal/impl/string.h +++ b/include/fast_io_dsal/impl/string.h @@ -218,8 +218,8 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return imp.begin_ptr; } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool is_empty() const noexcept @@ -227,8 +227,8 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return imp.begin_ptr == imp.curr_ptr; } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool empty() const noexcept @@ -236,8 +236,8 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return imp.begin_ptr == imp.curr_ptr; } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr size_type size() const noexcept diff --git a/include/fast_io_dsal/impl/string_view.h b/include/fast_io_dsal/impl/string_view.h index 24c73a230..dd0dc8f74 100644 --- a/include/fast_io_dsal/impl/string_view.h +++ b/include/fast_io_dsal/impl/string_view.h @@ -66,24 +66,24 @@ class basic_string_view const_pointer ptr{}; size_type n{}; -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool is_empty() const noexcept { return !n; } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr bool empty() const noexcept { return !n; } -#if __has_cpp_attribute(__gnu__::__const__) - [[__gnu__::__const__]] +#if __has_cpp_attribute(__gnu__::__pure__) + [[__gnu__::__pure__]] #endif [[nodiscard]] inline constexpr size_type size() const noexcept {