Skip to content

Commit e7d5635

Browse files
committed
[libc++] Revert LWG3223 Broken requirements for shared_ptr converting constructors (#93071)
This reverts commit d868f09, which was shown to break some code and we don't know yet whether the code should be valid or not. Reverting until we've had time to figure it out next week.
1 parent ade28a7 commit e7d5635

File tree

7 files changed

+77
-113
lines changed

7 files changed

+77
-113
lines changed

libcxx/docs/Status/Cxx20Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
"`3200 <https://wg21.link/LWG3200>`__","``midpoint``\ should not constrain ``T``\ is complete","Prague","|Nothing To Do|",""
201201
"`3201 <https://wg21.link/LWG3201>`__","``lerp``\ should be marked as ``noexcept``\ ","Prague","|Complete|",""
202202
"`3226 <https://wg21.link/LWG3226>`__","``zoned_time``\ constructor from ``string_view``\ should accept ``zoned_time<Duration2, TimeZonePtr2>``\ ","Prague","","","|chrono|"
203-
"`3233 <https://wg21.link/LWG3233>`__","Broken requirements for ``shared_ptr``\ converting constructors","Prague","|Complete|","19.0"
203+
"`3233 <https://wg21.link/LWG3233>`__","Broken requirements for ``shared_ptr``\ converting constructors","Prague","",""
204204
"`3237 <https://wg21.link/LWG3237>`__","LWG 3038 and 3190 have inconsistent PRs","Prague","|Complete|","16.0"
205205
"`3238 <https://wg21.link/LWG3238>`__","Insufficiently-defined behavior of ``std::function``\ deduction guides","Prague","|Nothing To Do|",""
206206
"`3242 <https://wg21.link/LWG3242>`__","``std::format``\ : missing rules for ``arg-id``\ in ``width``\ and ``precision``\ ","Prague","|Complete|","14.0","|format|"

libcxx/include/__memory/shared_ptr.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ struct __shared_ptr_deleter_ctor_reqs {
403403
__well_formed_deleter<_Dp, _Yp*>::value;
404404
};
405405

406-
template <class _Dp, class _Tp>
407-
using __shared_ptr_nullptr_deleter_ctor_reqs = _And<is_move_constructible<_Dp>, __well_formed_deleter<_Dp, nullptr_t> >;
408-
409406
#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI)
410407
# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__))
411408
#else
@@ -501,7 +498,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
501498
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
502499
}
503500

504-
template <class _Dp, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp, _Tp>::value, int> = 0 >
501+
template <class _Dp>
505502
_LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d) : __ptr_(nullptr) {
506503
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
507504
try {
@@ -521,7 +518,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
521518
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
522519
}
523520

524-
template <class _Dp, class _Alloc, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp, _Tp>::value, int> = 0 >
521+
template <class _Dp, class _Alloc>
525522
_LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) : __ptr_(nullptr) {
526523
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
527524
try {

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "test_macros.h"
1818
#include "deleter_types.h"
1919

20-
#include "types.h"
2120
struct A
2221
{
2322
static int count;
@@ -29,25 +28,6 @@ struct A
2928

3029
int A::count = 0;
3130

32-
// LWG 3233. Broken requirements for shared_ptr converting constructors
33-
// https://cplusplus.github.io/LWG/issue3233
34-
static_assert( std::is_constructible<std::shared_ptr<int>, std::nullptr_t, test_deleter<int> >::value, "");
35-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, bad_deleter>::value, "");
36-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, no_nullptr_deleter>::value, "");
37-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, no_move_deleter>::value, "");
38-
39-
#if TEST_STD_VER >= 17
40-
static_assert( std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, test_deleter<int> >::value, "");
41-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, bad_deleter>::value, "");
42-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, no_nullptr_deleter>::value, "");
43-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, no_move_deleter>::value, "");
44-
45-
static_assert( std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, test_deleter<int> >::value, "");
46-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, bad_deleter>::value, "");
47-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, no_nullptr_deleter>::value, "");
48-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, no_move_deleter>::value, "");
49-
#endif
50-
5131
int main(int, char**)
5232
{
5333
{

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "test_allocator.h"
1818
#include "min_allocator.h"
1919

20-
#include "types.h"
21-
2220
struct A
2321
{
2422
static int count;
@@ -30,25 +28,6 @@ struct A
3028

3129
int A::count = 0;
3230

33-
// LWG 3233. Broken requirements for shared_ptr converting constructors
34-
// https://cplusplus.github.io/LWG/issue3233
35-
static_assert( std::is_constructible<std::shared_ptr<int>, std::nullptr_t, test_deleter<int>, test_allocator<int> >::value, "");
36-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, bad_deleter, test_allocator<int> >::value, "");
37-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, no_nullptr_deleter, test_allocator<int> >::value, "");
38-
static_assert(!std::is_constructible<std::shared_ptr<int>, std::nullptr_t, no_move_deleter, test_allocator<int> >::value, "");
39-
40-
#if TEST_STD_VER >= 17
41-
static_assert( std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, test_deleter<int>, test_allocator<int> >::value, "");
42-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, bad_deleter, test_allocator<int> >::value, "");
43-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, no_nullptr_deleter, test_allocator<int> >::value, "");
44-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, std::nullptr_t, no_move_deleter, test_allocator<int> >::value, "");
45-
46-
static_assert( std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, test_deleter<int>, test_allocator<int> >::value, "");
47-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, bad_deleter, test_allocator<int> >::value, "");
48-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, no_nullptr_deleter, test_allocator<int> >::value, "");
49-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, std::nullptr_t, no_move_deleter, test_allocator<int> >::value, "");
50-
#endif
51-
5231
int main(int, char**)
5332
{
5433
test_allocator_statistics alloc_stats;

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "test_macros.h"
1818
#include "deleter_types.h"
1919

20-
#include "types.h"
21-
2220
struct A
2321
{
2422
static int count;
@@ -30,8 +28,38 @@ struct A
3028

3129
int A::count = 0;
3230

33-
// LWG 3233. Broken requirements for shared_ptr converting constructors
34-
// https://cplusplus.github.io/LWG/issue3233
31+
struct bad_ty { };
32+
33+
struct bad_deleter
34+
{
35+
void operator()(bad_ty) { }
36+
};
37+
38+
struct no_move_deleter
39+
{
40+
no_move_deleter(no_move_deleter const&) = delete;
41+
no_move_deleter(no_move_deleter &&) = delete;
42+
void operator()(int*) { }
43+
};
44+
45+
static_assert(!std::is_move_constructible<no_move_deleter>::value, "");
46+
47+
struct Base { };
48+
struct Derived : Base { };
49+
50+
template<class T>
51+
class MoveDeleter
52+
{
53+
MoveDeleter();
54+
MoveDeleter(MoveDeleter const&);
55+
public:
56+
MoveDeleter(MoveDeleter&&) {}
57+
58+
explicit MoveDeleter(int) {}
59+
60+
void operator()(T* ptr) { delete ptr; }
61+
};
62+
3563
// https://llvm.org/PR60258
3664
// Invalid constructor SFINAE for std::shared_ptr's array ctors
3765
static_assert( std::is_constructible<std::shared_ptr<int>, int*, test_deleter<int> >::value, "");
@@ -40,12 +68,12 @@ static_assert( std::is_constructible<std::shared_ptr<Base>, Derived*, test_dele
4068
static_assert(!std::is_constructible<std::shared_ptr<A>, int*, test_deleter<A> >::value, "");
4169

4270
#if TEST_STD_VER >= 17
43-
static_assert( std::is_constructible<std::shared_ptr<int[]>, int*, test_deleter<int> >::value, "");
71+
static_assert( std::is_constructible<std::shared_ptr<int[]>, int*, test_deleter<int>>::value, "");
4472
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int*, bad_deleter>::value, "");
45-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int(*)[], test_deleter<int> >::value, "");
46-
static_assert( std::is_constructible<std::shared_ptr<int[5]>, int*, test_deleter<int> >::value, "");
73+
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int(*)[], test_deleter<int>>::value, "");
74+
static_assert( std::is_constructible<std::shared_ptr<int[5]>, int*, test_deleter<int>>::value, "");
4775
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int*, bad_deleter>::value, "");
48-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int> >::value, "");
76+
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int>>::value, "");
4977
#endif
5078

5179
int f() { return 5; }

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "test_allocator.h"
1818
#include "min_allocator.h"
1919

20-
#include "types.h"
2120
struct A
2221
{
2322
static int count;
@@ -29,8 +28,38 @@ struct A
2928

3029
int A::count = 0;
3130

32-
// LWG 3233. Broken requirements for shared_ptr converting constructors
33-
// https://cplusplus.github.io/LWG/issue3233
31+
struct bad_ty { };
32+
33+
struct bad_deleter
34+
{
35+
void operator()(bad_ty) { }
36+
};
37+
38+
struct no_move_deleter
39+
{
40+
no_move_deleter(no_move_deleter const&) = delete;
41+
no_move_deleter(no_move_deleter &&) = delete;
42+
void operator()(int*) { }
43+
};
44+
45+
static_assert(!std::is_move_constructible<no_move_deleter>::value, "");
46+
47+
struct Base { };
48+
struct Derived : Base { };
49+
50+
template<class T>
51+
class MoveDeleter
52+
{
53+
MoveDeleter();
54+
MoveDeleter(MoveDeleter const&);
55+
public:
56+
MoveDeleter(MoveDeleter&&) {}
57+
58+
explicit MoveDeleter(int) {}
59+
60+
void operator()(T* ptr) { delete ptr; }
61+
};
62+
3463
// https://llvm.org/PR60258
3564
// Invalid constructor SFINAE for std::shared_ptr's array ctors
3665
static_assert( std::is_constructible<std::shared_ptr<int>, int*, test_deleter<int>, test_allocator<int> >::value, "");
@@ -39,12 +68,12 @@ static_assert( std::is_constructible<std::shared_ptr<Base>, Derived*, test_dele
3968
static_assert(!std::is_constructible<std::shared_ptr<A>, int*, test_deleter<A>, test_allocator<A> >::value, "");
4069

4170
#if TEST_STD_VER >= 17
42-
static_assert( std::is_constructible<std::shared_ptr<int[]>, int*, test_deleter<int>, test_allocator<int> >::value, "");
43-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int*, bad_deleter, test_allocator<int> >::value, "");
44-
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int(*)[], test_deleter<int>, test_allocator<int> >::value, "");
45-
static_assert( std::is_constructible<std::shared_ptr<int[5]>, int*, test_deleter<int>, test_allocator<int> >::value, "");
46-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int*, bad_deleter, test_allocator<int> >::value, "");
47-
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int>, test_allocator<int> >::value, "");
71+
static_assert( std::is_constructible<std::shared_ptr<int[]>, int*, test_deleter<int>, test_allocator<int>>::value, "");
72+
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int*, bad_deleter, test_allocator<int>>::value, "");
73+
static_assert(!std::is_constructible<std::shared_ptr<int[]>, int(*)[], test_deleter<int>, test_allocator<int>>::value, "");
74+
static_assert( std::is_constructible<std::shared_ptr<int[5]>, int*, test_deleter<int>, test_allocator<int>>::value, "");
75+
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int*, bad_deleter, test_allocator<int>>::value, "");
76+
static_assert(!std::is_constructible<std::shared_ptr<int[5]>, int(*)[5], test_deleter<int>, test_allocator<int>>::value, "");
4877
#endif
4978

5079

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/types.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)