Skip to content

Commit 29e51f8

Browse files
authored
[libc++] Simplify the implementation of LWG2762 (noexcept for unique_ptr) (#102032)
I had originally made some comments in https://reviews.llvm.org/D128214 that were followed when we implemented LWG2762. I don't understand why I made these comments anymore, but either way it seems like I was wrong since using `unique_ptr<void>::operator*` should be ill-formed. All other implementations also make that ill-formed.
1 parent ad6558c commit 29e51f8

File tree

4 files changed

+1
-50
lines changed

4 files changed

+1
-50
lines changed

libcxx/include/__memory/unique_ptr.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <__type_traits/is_trivially_relocatable.h>
3737
#include <__type_traits/is_void.h>
3838
#include <__type_traits/remove_extent.h>
39-
#include <__type_traits/remove_pointer.h>
4039
#include <__type_traits/type_identity.h>
4140
#include <__utility/declval.h>
4241
#include <__utility/forward.h>
@@ -52,17 +51,6 @@ _LIBCPP_PUSH_MACROS
5251

5352
_LIBCPP_BEGIN_NAMESPACE_STD
5453

55-
#ifndef _LIBCPP_CXX03_LANG
56-
57-
template <class _Ptr>
58-
struct __is_noexcept_deref_or_void {
59-
static constexpr bool value = noexcept(*std::declval<_Ptr>());
60-
};
61-
62-
template <>
63-
struct __is_noexcept_deref_or_void<void*> : true_type {};
64-
#endif
65-
6654
template <class _Tp>
6755
struct _LIBCPP_TEMPLATE_VIS default_delete {
6856
static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types");
@@ -266,7 +254,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
266254
}
267255

268256
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const
269-
_NOEXCEPT_(__is_noexcept_deref_or_void<pointer>::value) {
257+
_NOEXCEPT_(_NOEXCEPT_(*std::declval<pointer>())) {
270258
return *__ptr_.first();
271259
}
272260
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_.first(); }

libcxx/test/std/utilities/memory/unique.ptr/iterator_concept_conformance.compile.pass.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ static_assert(std::indirectly_movable_storable<std::unique_ptr<int>, std::unique
2222
static_assert(std::indirectly_copyable<std::unique_ptr<int>, std::unique_ptr<int>>);
2323
static_assert(std::indirectly_copyable_storable<std::unique_ptr<int>, std::unique_ptr<int>>);
2424
static_assert(std::indirectly_swappable<std::unique_ptr<int>, std::unique_ptr<int> >);
25-
26-
static_assert(!std::indirectly_readable<std::unique_ptr<void> >);
27-
static_assert(!std::indirectly_writable<std::unique_ptr<void>, void>);
28-
static_assert(!std::weakly_incrementable<std::unique_ptr<void> >);
29-
static_assert(!std::indirectly_movable<std::unique_ptr<void>, std::unique_ptr<void>>);
30-
static_assert(!std::indirectly_movable_storable<std::unique_ptr<void>, std::unique_ptr<void>>);
31-
static_assert(!std::indirectly_copyable<std::unique_ptr<void>, std::unique_ptr<void>>);
32-
static_assert(!std::indirectly_copyable_storable<std::unique_ptr<void>, std::unique_ptr<void>>);

libcxx/test/std/utilities/memory/unique.ptr/noexcept_operator_star.compile.pass.cpp

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

libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ struct Deleter {
3131
#endif
3232

3333
TEST_CONSTEXPR_CXX23 bool test() {
34-
ASSERT_NOEXCEPT(*(std::unique_ptr<void>{}));
35-
#if TEST_STD_VER >= 11
36-
static_assert(noexcept(*std::declval<std::unique_ptr<void>>()), "");
37-
#endif
3834
{
3935
std::unique_ptr<int> p(new int(3));
4036
assert(*p == 3);

0 commit comments

Comments
 (0)