[libcxx-commits] [libcxx] [libc++] Make sure LWG2070 is implemented as a DR (PR #65998)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 12 08:01:24 PDT 2023
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/65998:
>From bfb0c5a26098e67478fc04e585357b9def3ea858 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 11 Sep 2023 14:56:33 -0400
Subject: [PATCH] [libc++] Make sure LWG2070 is implemented as a DR
When we implemented C++20's P0674R1, we didn't enable the part of P0674R1
that was resolving LWG2070 as a DR. This patch fixes that and makes sure
that we consistently go through the allocator when constructing and
destroying the underlying object in std::allocate_shared.
Fixes #54365.
---
libcxx/include/__memory/shared_ptr.h | 8 +++++--
...s.cpp => allocate_shared.lwg2070.pass.cpp} | 8 ++++---
.../allocate_shared.pass.cpp | 23 -------------------
3 files changed, 11 insertions(+), 28 deletions(-)
rename libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/{allocate_shared_construct.pass.cpp => allocate_shared.lwg2070.pass.cpp} (92%)
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 845882ad31134d2..65b08f487f7839d 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -300,7 +300,9 @@ struct __shared_ptr_emplace
allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), _VSTD::forward<_Args>(__args)...);
}
#else
- ::new ((void*)__get_elem()) _Tp(_VSTD::forward<_Args>(__args)...);
+ using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
+ _TpAlloc __tmp(*__get_alloc());
+ allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), _VSTD::forward<_Args>(__args)...);
#endif
}
@@ -321,7 +323,9 @@ struct __shared_ptr_emplace
allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem());
}
#else
- __get_elem()->~_Tp();
+ using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
+ _TpAlloc __tmp(*__get_alloc());
+ allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem());
#endif
}
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_construct.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.lwg2070.pass.cpp
similarity index 92%
rename from libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_construct.pass.cpp
rename to libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.lwg2070.pass.cpp
index 4281cc1aa9e0db8..89b6cb6c11a361f 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_construct.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.lwg2070.pass.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: c++03, c++11, c++14
// <memory>
@@ -15,8 +15,10 @@
// template<class T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
-// This test checks that allocator_traits::construct is used in allocate_shared
-// as requested in C++20 (via P0674R1).
+// This test checks that allocator_traits::construct and allocator_traits::destroy
+// are used in allocate_shared as requested for the resolution of LWG2070. Note
+// that LWG2070 was resolved by P0674R1 (which is a C++20 paper), but we implement
+// LWG issue resolutions as DRs per our policy.
#include "test_macros.h"
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
index ac7a9913b0e9182..341a442c90a1674 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
@@ -90,22 +90,6 @@ struct Three
int Three::count = 0;
-template<class T>
-struct AllocNoConstruct : std::allocator<T>
-{
- AllocNoConstruct() = default;
-
- template <class T1>
- AllocNoConstruct(AllocNoConstruct<T1>) {}
-
- template <class T1>
- struct rebind {
- typedef AllocNoConstruct<T1> other;
- };
-
- void construct(void*) { assert(false); }
-};
-
template <class Alloc>
void test()
{
@@ -182,12 +166,5 @@ int main(int, char**)
assert(p2 != nullptr);
}
- // Test that we don't call construct before C++20.
-#if TEST_STD_VER < 20
- {
- (void)std::allocate_shared<int>(AllocNoConstruct<int>());
- }
-#endif // TEST_STD_VER < 20
-
return 0;
}
More information about the libcxx-commits
mailing list