[libcxx-commits] [libcxx] [libc++][test] Close LWG3018 and add tests (PR #93047)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun May 26 04:24:41 PDT 2024
https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/93047
>From 853f255c867878c573ba238e116c21c8f816267e Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Wed, 22 May 2024 16:24:39 +0100
Subject: [PATCH 1/2] [libc++][test] Close LWG3018 and add tests
---
libcxx/docs/Status/Cxx20Issues.csv | 2 +-
.../pointer_deleter.pass.cpp | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index db57b15256a62..969283613e955 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -191,7 +191,7 @@
"","","","","",""
"`1203 <https://wg21.link/LWG1203>`__","More useful rvalue stream insertion","Prague","|Complete|","12.0"
"`2859 <https://wg21.link/LWG2859>`__","Definition of *reachable* in [ptr.launder] misses pointer arithmetic from pointer-interconvertible object","Prague","",""
-"`3018 <https://wg21.link/LWG3018>`__","``shared_ptr``\ of function type","Prague","",""
+"`3018 <https://wg21.link/LWG3018>`__","``shared_ptr``\ of function type","Prague","|Nothing To Do|",""
"`3050 <https://wg21.link/LWG3050>`__","Conversion specification problem in ``chrono::duration``\ constructor","Prague","|Complete|","19.0","|chrono|"
"`3141 <https://wg21.link/LWG3141>`__","``CopyConstructible``\ doesn't preserve source values","Prague","|Nothing to do|",""
"`3150 <https://wg21.link/LWG3150>`__","``UniformRandomBitGenerator``\ should validate ``min``\ and ``max``\ ","Prague","|Complete|","13.0","|ranges|"
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
index 42225a4b0be7e..f9493c7dd4362 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
@@ -76,6 +76,19 @@ static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int*, bad_deleter>
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int>>::value, "");
#endif
+int f() { return 5; }
+
+// https://cplusplus.github.io/LWG/issue3018
+// LWG 3018. shared_ptr of function type
+void test_function_type() {
+ bool deleter_called = false;
+ {
+ std::shared_ptr<int()> p(&f, [&deleter_called](int (*)()) { deleter_called = true; });
+ assert((*p)() == 5);
+ }
+ assert(deleter_called);
+}
+
int main(int, char**)
{
{
>From 8fb8cc6236ad0ffed94b60f855c2610cffe918dd Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Sun, 26 May 2024 12:24:23 +0100
Subject: [PATCH 2/2] address comment
---
.../pointer_deleter.pass.cpp | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
index f9493c7dd4362..0f4aa0f5c0689 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
@@ -80,10 +80,18 @@ int f() { return 5; }
// https://cplusplus.github.io/LWG/issue3018
// LWG 3018. shared_ptr of function type
+struct function_pointer_deleter {
+ function_pointer_deleter(bool& deleter_called) : deleter_called_(deleter_called) {}
+
+ void operator()(int (*)()) const { deleter_called_ = true; }
+
+ bool& deleter_called_;
+};
+
void test_function_type() {
bool deleter_called = false;
{
- std::shared_ptr<int()> p(&f, [&deleter_called](int (*)()) { deleter_called = true; });
+ std::shared_ptr<int()> p(&f, function_pointer_deleter(deleter_called));
assert((*p)() == 5);
}
assert(deleter_called);
@@ -135,5 +143,6 @@ int main(int, char**)
}
#endif // TEST_STD_VER >= 11
+ test_function_type();
return 0;
}
More information about the libcxx-commits
mailing list