Skip to content

Commit 4bc779e

Browse files
committed
[out_ptr] Address review comments + new tests
1 parent 84770c8 commit 4bc779e

20 files changed

+122
-42
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Status
426426
--------------------------------------------------- -----------------
427427
``__cpp_lib_linalg`` *unimplemented*
428428
--------------------------------------------------- -----------------
429-
``__cpp_lib_out_ptr`` *unimplemented*
429+
``__cpp_lib_out_ptr`` ``202311L``
430430
--------------------------------------------------- -----------------
431431
``__cpp_lib_ratio`` ``202306L``
432432
--------------------------------------------------- -----------------

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"`3515 <https://wg21.link/LWG3515>`__","§[stacktrace.basic.nonmem]: ``operator<<`` should be less templatized", "November 2022","","",""
193193
"`3545 <https://wg21.link/LWG3545>`__","``std::pointer_traits`` should be SFINAE-friendly", "November 2022","|Complete|","18.0",""
194194
"`3569 <https://wg21.link/LWG3569>`__","``join_view`` fails to support ranges of ranges with non-default_initializable iterators", "November 2022","","","|ranges|"
195-
"`3594 <https://wg21.link/LWG3594>`__","``inout_ptr`` — inconsistent ``release()`` in destructor", "November 2022","|Complete|","17.0",""
195+
"`3594 <https://wg21.link/LWG3594>`__","``inout_ptr`` — inconsistent ``release()`` in destructor", "November 2022","|Complete|","18.0",""
196196
"`3597 <https://wg21.link/LWG3597>`__","Unsigned integer types don't model advanceable", "November 2022","","","|ranges|"
197197
"`3600 <https://wg21.link/LWG3600>`__","Making ``istream_iterator`` copy constructor trivial is an ABI break", "November 2022","","",""
198198
"`3629 <https://wg21.link/LWG3629>`__","``make_error_code`` and ``make_error_condition`` are customization points","November 2022","|Complete|","16.0",""
@@ -282,7 +282,7 @@
282282
"`3645 <https://wg21.link/LWG3645>`__","``resize_and_overwrite`` is overspecified to call its callback with lvalues","February 2023","|Complete|","14.0",""
283283
"`3655 <https://wg21.link/LWG3655>`__","The ``INVOKE`` operation and union types","February 2023","|Complete|","18.0",""
284284
"`3723 <https://wg21.link/LWG3723>`__","``priority_queue::push_range`` needs to ``append_range``","February 2023","","","|ranges|"
285-
"`3734 <https://wg21.link/LWG3734>`__","Inconsistency in ``inout_ptr`` and ``out_ptr`` for empty case","February 2023","|Complete|","17.0",""
285+
"`3734 <https://wg21.link/LWG3734>`__","Inconsistency in ``inout_ptr`` and ``out_ptr`` for empty case","February 2023","|Complete|","18.0",""
286286
"`3772 <https://wg21.link/LWG3772>`__","``repeat_view``'s ``piecewise`` constructor is missing Postconditions","February 2023","","","|ranges|"
287287
"`3786 <https://wg21.link/LWG3786>`__","Flat maps' deduction guide needs to default ``Allocator`` to be useful","February 2023","","",""
288288
"`3803 <https://wg21.link/LWG3803>`__","``flat_foo`` constructors taking ``KeyContainer`` lack ``KeyCompare`` parameter","February 2023","","",""

libcxx/docs/Status/Cxx23Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"","","","","","",""
1414
"`P0401R6 <https://wg21.link/P0401R6>`__","LWG","Providing size feedback in the Allocator interface","June 2021","|Complete|","15.0"
1515
"`P0448R4 <https://wg21.link/P0448R4>`__","LWG","A strstream replacement using span<charT> as buffer","June 2021","",""
16-
"`P1132R8 <https://wg21.link/P1132R8>`__","LWG","out_ptr - a scalable output pointer abstraction","June 2021","|Complete|","17.0"
16+
"`P1132R8 <https://wg21.link/P1132R8>`__","LWG","out_ptr - a scalable output pointer abstraction","June 2021","|Complete|","18.0"
1717
"`P1328R1 <https://wg21.link/P1328R1>`__","LWG","Making std::type_info::operator== constexpr","June 2021","|Complete|","17.0"
1818
"`P1425R4 <https://wg21.link/P1425R4>`__","LWG","Iterators pair constructors for stack and queue","June 2021","|Complete|","14.0","|ranges|"
1919
"`P1518R2 <https://wg21.link/P1518R2>`__","LWG","Stop overconstraining allocators in container deduction guides","June 2021","|Complete|","13.0"

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"`3749 <https://wg21.link/LWG3749>`__","``common_iterator`` should handle integer-class difference types","Kona November 2023","","",""
2525
"`3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","Kona November 2023","","",""
2626
"`3892 <https://wg21.link/LWG3892>`__","Incorrect formatting of nested ranges and tuples","Kona November 2023","|Complete|","17.0","|format|"
27-
"`3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","Kona November 2023","","",""
27+
"`3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","Kona November 2023","|Complete|","18.0",""
2828
"`3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","Kona November 2023","","",""
2929
"`3947 <https://wg21.link/LWG3947>`__","Unexpected constraints on ``adjacent_transform_view::base()``","Kona November 2023","","","|ranges|"
3030
"`3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","Kona November 2023","","","|ranges|"

libcxx/include/__memory/inout_ptr.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ class _LIBCPP_TEMPLATE_VIS inout_ptr_t {
5151
_LIBCPP_HIDE_FROM_ABI inout_ptr_t(const inout_ptr_t&) = delete;
5252

5353
_LIBCPP_HIDE_FROM_ABI ~inout_ptr_t() {
54-
if (!__p_) {
55-
return;
54+
if constexpr (!is_pointer_v<_Smart>) {
55+
if (!__p_) {
56+
return;
57+
}
5658
}
5759

5860
using _SP = __pointer_of_or_t<_Smart, _Pointer>;
@@ -90,7 +92,7 @@ class _LIBCPP_TEMPLATE_VIS inout_ptr_t {
9092
template <class _Pointer = void, class _Smart, class... _Args>
9193
_LIBCPP_HIDE_FROM_ABI auto inout_ptr(_Smart& __s, _Args&&... __args) {
9294
using _Ptr = conditional_t<is_void_v<_Pointer>, __pointer_of_t<_Smart>, _Pointer>;
93-
return std::inout_ptr_t<_Smart, _Ptr, _Args&&...>{__s, std::forward<_Args>(__args)...};
95+
return std::inout_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...);
9496
}
9597

9698
#endif // _LIBCPP_STD_VER >= 23

libcxx/include/__memory/out_ptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class _LIBCPP_TEMPLATE_VIS out_ptr_t {
8787
template <class _Pointer = void, class _Smart, class... _Args>
8888
_LIBCPP_HIDE_FROM_ABI auto out_ptr(_Smart& __s, _Args&&... __args) {
8989
using _Ptr = conditional_t<is_void_v<_Pointer>, __pointer_of_t<_Smart>, _Pointer>;
90-
return std::out_ptr_t<_Smart, _Ptr, _Args&&...>{__s, std::forward<_Args>(__args)...};
90+
return std::out_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...);
9191
}
9292

9393
#endif // _LIBCPP_STD_VER >= 23

libcxx/include/__memory/pointer_traits.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
#include <__type_traits/conditional.h>
1616
#include <__type_traits/conjunction.h>
1717
#include <__type_traits/decay.h>
18-
#include <__type_traits/enable_if.h>
1918
#include <__type_traits/is_class.h>
2019
#include <__type_traits/is_function.h>
2120
#include <__type_traits/is_void.h>
22-
#include <__type_traits/negation.h>
2321
#include <__type_traits/void_t.h>
2422
#include <__utility/declval.h>
2523
#include <__utility/forward.h>

libcxx/include/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
502502
// # define __cpp_lib_hazard_pointer 202306L
503503
// # define __cpp_lib_linalg 202311L
504504
# undef __cpp_lib_out_ptr
505-
// # define __cpp_lib_out_ptr 202311L
505+
# define __cpp_lib_out_ptr 202311L
506506
# define __cpp_lib_ratio 202306L
507507
// # define __cpp_lib_rcu 202306L
508508
// # define __cpp_lib_saturation_arithmetic 202311L

libcxx/test/std/language.support/support.limits/support.limits.general/memory.version.compile.pass.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,11 @@
616616
# error "__cpp_lib_make_unique should have the value 201304L in c++26"
617617
# endif
618618

619-
# if !defined(_LIBCPP_VERSION)
620-
# ifndef __cpp_lib_out_ptr
621-
# error "__cpp_lib_out_ptr should be defined in c++26"
622-
# endif
623-
# if __cpp_lib_out_ptr != 202311L
624-
# error "__cpp_lib_out_ptr should have the value 202311L in c++26"
625-
# endif
626-
# else // _LIBCPP_VERSION
627-
# ifdef __cpp_lib_out_ptr
628-
# error "__cpp_lib_out_ptr should not be defined because it is unimplemented in libc++!"
629-
# endif
619+
# ifndef __cpp_lib_out_ptr
620+
# error "__cpp_lib_out_ptr should be defined in c++26"
621+
# endif
622+
# if __cpp_lib_out_ptr != 202311L
623+
# error "__cpp_lib_out_ptr should have the value 202311L in c++26"
630624
# endif
631625

632626
# ifndef __cpp_lib_ranges

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6917,17 +6917,11 @@
69176917
# error "__cpp_lib_optional should have the value 202110L in c++26"
69186918
# endif
69196919

6920-
# if !defined(_LIBCPP_VERSION)
6921-
# ifndef __cpp_lib_out_ptr
6922-
# error "__cpp_lib_out_ptr should be defined in c++26"
6923-
# endif
6924-
# if __cpp_lib_out_ptr != 202311L
6925-
# error "__cpp_lib_out_ptr should have the value 202311L in c++26"
6926-
# endif
6927-
# else // _LIBCPP_VERSION
6928-
# ifdef __cpp_lib_out_ptr
6929-
# error "__cpp_lib_out_ptr should not be defined because it is unimplemented in libc++!"
6930-
# endif
6920+
# ifndef __cpp_lib_out_ptr
6921+
# error "__cpp_lib_out_ptr should be defined in c++26"
6922+
# endif
6923+
# if __cpp_lib_out_ptr != 202311L
6924+
# error "__cpp_lib_out_ptr should have the value 202311L in c++26"
69316925
# endif
69326926

69336927
# if !defined(_LIBCPP_VERSION)

libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.compile.pass.cpp renamed to libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.general.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ int main(int, char**) {
2121
std::unique_ptr<int> uPtr;
2222

2323
auto inoutUPtr1 = std::inout_ptr(uPtr);
24+
(void)inoutUPtr1;
2425
auto inoutUPtr2 = std::inout_ptr<int*>(uPtr);
26+
(void)inoutUPtr2;
2527
}
2628
{
2729
auto deleter = [](auto* p) { delete p; };
2830
std::unique_ptr<int, decltype(deleter)> uPtr;
2931

3032
auto inoutUPtr1 = std::inout_ptr(uPtr, deleter);
33+
(void)inoutUPtr1;
3134
auto inoutUPtr2 = std::inout_ptr<int*>(uPtr, deleter);
35+
(void)inoutUPtr2;
3236
}
3337

3438
return 0;

libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.pass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
// <memory>
1212

13-
// [inout.ptr.t], class template inout_ptr_t
14-
// template<class Smart, class Pointer, class... Args>
15-
// class inout_ptr_t; // since c++23
16-
1713
// [inout.ptr], function template inout_ptr
1814
// template<class Pointer = void, class Smart, class... Args>
1915
// auto inout_ptr(Smart& s, Args&&... args); // since c++23
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <memory>
12+
13+
// [inout.ptr.t], class template inout_ptr_t
14+
// template<class Smart, class Pointer, class... Args>
15+
// class inout_ptr_t; // since c++23
16+
17+
// explicit inout_ptr_t(Smart&, Args...);
18+
19+
#include <memory>
20+
21+
#include "test_convertible.h"
22+
23+
int main(int, char**) {
24+
{
25+
std::unique_ptr<int> uPtr;
26+
27+
std::inout_ptr_t<std::unique_ptr<int>, int*>{uPtr};
28+
29+
static_assert(
30+
!test_convertible<std::inout_ptr_t<std::unique_ptr<int>, int*>>(), "This constructor must be explicit");
31+
}
32+
{
33+
auto deleter = [](auto* p) { delete p; };
34+
std::unique_ptr<int, decltype(deleter)> uPtr;
35+
36+
std::inout_ptr_t<std::unique_ptr<int, decltype(deleter)>, int*>{uPtr};
37+
38+
static_assert(!test_convertible<std::inout_ptr_t<std::unique_ptr<int, decltype(deleter)>, int*>>(),
39+
"This constructor must be explicit");
40+
}
41+
42+
return 0;
43+
}

libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.t.compile.pass.cpp renamed to libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.t.deref.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// template<class Smart, class Pointer, class... Args>
1515
// class inout_ptr_t; // since c++23
1616

17+
// operator Pointer*() const noexcept;
18+
// operator void**() const noexcept;
19+
1720
#include <memory>
1821

1922
int main(int, char**) {

libcxx/test/std/utilities/smartptr/adapt/inout.ptr/inout.ptr.verify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int main(int, char**) {
2323

2424
// expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement '!__is_specialization_v<std::shared_ptr<int>, std::shared_ptr>'{{.*}}std::shared_ptr<> is not supported}}
2525
auto inoutUPtr1 = std::inout_ptr(sPtr);
26+
// expected-error@*:* {{no matching conversion for functional-style cast from 'std::shared_ptr<int>' to 'std::inout_ptr_t<shared_ptr<int>, _Ptr>' (aka 'inout_ptr_t<std::shared_ptr<int>, int *>'}}
2627
auto inoutUPtr2 = std::inout_ptr<int*>(sPtr);
2728
}
2829

libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.compile.pass.cpp renamed to libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.general.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ int main(int, char**) {
2121
std::unique_ptr<int> uPtr;
2222

2323
auto outUPtr1 = std::out_ptr(uPtr);
24+
(void)outUPtr1;
2425
auto outUPtr2 = std::out_ptr<int*>(uPtr);
26+
(void)outUPtr2;
2527
}
2628
{
2729
std::shared_ptr<int> sPtr;
2830

2931
auto outSPtr1 = std::out_ptr(sPtr, [](auto* p) { delete p; });
32+
(void)outSPtr1;
3033
auto outSPtr2 = std::out_ptr<int*>(sPtr, [](auto* p) { delete p; });
34+
(void)outSPtr2;
3135
}
3236

3337
return 0;

libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.pass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
// <memory>
1212

13-
// [out.ptr.t], class template out_ptr_t
14-
// template<class Smart, class Pointer, class... Args>
15-
// class out_ptr_t; // since c++23
16-
1713
// [out.ptr], function template out_ptr
1814
// template<class Pointer = void, class Smart, class... Args>
1915
// auto out_ptr(Smart& s, Args&&... args); // since c++23
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <memory>
12+
13+
// [out.ptr.t], class template out_ptr_t
14+
// template<class Smart, class Pointer, class... Args>
15+
// class out_ptr_t; // since c++23
16+
17+
// explicit out_ptr_t(Smart&, Args...);
18+
19+
#include <memory>
20+
21+
#include "test_convertible.h"
22+
23+
int main(int, char**) {
24+
{
25+
std::unique_ptr<int> uPtr;
26+
27+
std::out_ptr_t<std::unique_ptr<int>, int*>{uPtr};
28+
29+
static_assert(!test_convertible<std::out_ptr_t<std::unique_ptr<int>, int*>>(), "This constructor must be explicit");
30+
}
31+
{
32+
std::unique_ptr<int, std::default_delete<int>> uPtr;
33+
34+
std::out_ptr_t<decltype(uPtr), int*, std::default_delete<int>>{uPtr, std::default_delete<int>{}};
35+
36+
static_assert(!test_convertible<std::out_ptr_t<decltype(uPtr), int*, std::default_delete<int>>>(),
37+
"This constructor must be explicit");
38+
}
39+
40+
return 0;
41+
}

libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.t.compile.pass.cpp renamed to libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.t.deref.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// template<class Smart, class Pointer, class... Args>
1515
// class out_ptr_t; // since c++23
1616

17+
// operator Pointer*() const noexcept;
18+
// operator void**() const noexcept;
19+
1720
#include <memory>
1821

1922
int main(int, char**) {

libcxx/test/std/utilities/smartptr/adapt/out.ptr/out.ptr.verify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int main(int, char**) {
2323

2424
// expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement '!__is_specialization_v<std::shared_ptr<int>, std::shared_ptr> || sizeof...(_Args) > 0'{{.*}}Specialization of std::shared_ptr<> requires a deleter.}}
2525
auto outSPtr1 = std::out_ptr(sPtr);
26+
// expected-error@*:* {{no matching conversion for functional-style cast from 'std::shared_ptr<int>' to 'std::out_ptr_t<shared_ptr<int>, _Ptr>' (aka 'out_ptr_t<std::shared_ptr<int>, int *>')}}
2627
auto outSPtr2 = std::out_ptr<int*>(sPtr);
2728
}
2829

0 commit comments

Comments
 (0)