[libcxx-commits] [libcxx] [libc++] Update the status for lwg-3120 (PR #116772)
Peng Xie via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 7 23:35:23 PST 2025
https://github.com/love1angel updated https://github.com/llvm/llvm-project/pull/116772
>From 1bdb2068a90fa875d3452ad511264c1394f40814 Mon Sep 17 00:00:00 2001
From: Peng Xie <helianthus547 at gmail.com>
Date: Tue, 19 Nov 2024 16:24:00 +0800
Subject: [PATCH] [libc++] Update the status for lwg-3120
Current implementation already have struct __initial_descriptor which
saves the initial state.
When release() called, we will reset ptr __initial_descriptor.__cur_,
next buffer size never changed.
This patch update the lwg 3120 issue latest status and add test.
---
libcxx/docs/Status/Cxx23Issues.csv | 2 +-
.../release_reset_initial_status.pass.cpp | 52 +++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
create mode 100644 libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp
diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index 1215f21985eb945..421ae8c8e3d711b 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -14,7 +14,7 @@
"`LWG2731 <https://wg21.link/LWG2731>`__","Existence of ``lock_guard<MutexTypes...>::mutex_type`` typedef unclear","2020-11 (Virtual)","|Complete|","5",""
"`LWG2743 <https://wg21.link/LWG2743>`__","P0083R3 ``node_handle`` private members missing ""exposition only"" comment","2020-11 (Virtual)","|Nothing To Do|","",""
"`LWG2820 <https://wg21.link/LWG2820>`__","Clarify ``<cstdint>`` macros","2020-11 (Virtual)","|Nothing To Do|","",""
-"`LWG3120 <https://wg21.link/LWG3120>`__","Unclear behavior of ``monotonic_buffer_resource::release()``","2020-11 (Virtual)","","",""
+"`LWG3120 <https://wg21.link/LWG3120>`__","Unclear behavior of ``monotonic_buffer_resource::release()``","2020-11 (Virtual)","|Complete|","16",""
"`LWG3170 <https://wg21.link/LWG3170>`__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","2020-11 (Virtual)","|Complete|","18",""
"`LWG3036 <https://wg21.link/LWG3036>`__","``polymorphic_allocator::destroy`` is extraneous","2020-11 (Virtual)","|Nothing To Do|","","Reverted by P2875R4"
"`LWG3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","2020-11 (Virtual)","|Complete|","14",""
diff --git a/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp
new file mode 100644
index 000000000000000..2492b4536c95280
--- /dev/null
+++ b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: availability-pmr-missing
+
+// <memory_resource>
+
+// class monotonic_buffer_resource
+
+#include <memory_resource>
+#include <cassert>
+
+#include "count_new.h"
+#include "test_macros.h"
+
+int main(int, char**) {
+ {
+ // https://cplusplus.github.io/LWG/issue3120
+ {
+ // when init given a next buffer size, after release(), reset/not change next buffer size from initial state
+ constexpr auto expect_next_buffer_size{512ULL};
+ std::pmr::monotonic_buffer_resource mr{nullptr, expect_next_buffer_size, std::pmr::new_delete_resource()};
+
+ for (int i = 0; i < 100; ++i) {
+ std::ignore = mr.allocate(1);
+ mr.release();
+ ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkLastNewSizeGe(expect_next_buffer_size));
+ }
+ }
+ {
+ // Given
+ // when init given a buffer, after release(), initial ptr will reset to it's initial state
+ constexpr auto buffer_size{512ULL};
+ char buffer[buffer_size];
+ std::pmr::monotonic_buffer_resource mr{buffer, buffer_size, std::pmr::null_memory_resource()};
+
+ auto expect_mem_start = mr.allocate(1);
+ for (int i = 0; i < 100; ++i) {
+ mr.release();
+ auto ths_mem_start = mr.allocate(1);
+ assert(expect_mem_start == ths_mem_start);
+ }
+ }
+ }
+}
More information about the libcxx-commits
mailing list