Skip to content

Commit 5dd9220

Browse files
committed
Implement more of P0600: '[[nodiscard]] in the library' for C++2a
llvm-svn: 319710
1 parent d1c9b61 commit 5dd9220

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

libcxx/include/new

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ new_handler get_new_handler() noexcept;
5050
template <class T> constexpr T* launder(T* p) noexcept; // C++17
5151
} // std
5252
53-
void* operator new(std::size_t size); // replaceable
54-
void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17
55-
void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable
53+
void* operator new(std::size_t size); // replaceable, nodiscard in C++2a
54+
void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a
55+
void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a
5656
void* operator new(std::size_t size, std::align_val_t alignment,
57-
const std::nothrow_t&) noexcept; // replaceable, C++17
57+
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a
5858
void operator delete(void* ptr) noexcept; // replaceable
5959
void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
6060
void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17
@@ -64,12 +64,12 @@ void operator delete(void* ptr, const std::nothrow_t&) noexcept; // repla
6464
void operator delete(void* ptr, std:align_val_t alignment,
6565
const std::nothrow_t&) noexcept; // replaceable, C++17
6666
67-
void* operator new[](std::size_t size); // replaceable
67+
void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a
6868
void* operator new[](std::size_t size,
69-
std::align_val_t alignment) noexcept; // replaceable, C++17
70-
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
69+
std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a
70+
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a
7171
void* operator new[](std::size_t size, std::align_val_t alignment,
72-
const std::nothrow_t&) noexcept; // replaceable, C++17
72+
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a
7373
void operator delete[](void* ptr) noexcept; // replaceable
7474
void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
7575
void operator delete[](void* ptr,
@@ -80,8 +80,8 @@ void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // repla
8080
void operator delete[](void* ptr, std::align_val_t alignment,
8181
const std::nothrow_t&) noexcept; // replaceable, C++17
8282
83-
void* operator new (std::size_t size, void* ptr) noexcept;
84-
void* operator new[](std::size_t size, void* ptr) noexcept;
83+
void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a
84+
void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a
8585
void operator delete (void* ptr, void*) noexcept;
8686
void operator delete[](void* ptr, void*) noexcept;
8787
@@ -178,42 +178,42 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 };
178178

179179
#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME)
180180

181-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
182-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
181+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
182+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
183183
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
184184
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
185185
#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
186186
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
187187
#endif
188188

189-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
190-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
189+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
190+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
191191
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
192192
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
193193
#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
194194
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
195195
#endif
196196

197197
#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
198-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
199-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
198+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
199+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
200200
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
201201
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
202202
#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
203203
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
204204
#endif
205205

206-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
207-
_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
206+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
207+
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
208208
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
209209
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
210210
#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
211211
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
212212
#endif
213213
#endif
214214

215-
inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
216-
inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
215+
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
216+
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
217217
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
218218
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
219219

libcxx/www/cxx2a_status.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ <h3>Paper Status</h3>
7878

7979
<p><i>[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]</i></p>
8080

81+
<p><i>The missing bits in P0600 are in [mem.res.class], [mem.poly.allocator.class], and [container.node.overview]</i></p>
82+
8183
<h3>Library Working group Issues Status</h3>
8284
<!-- <I>Note: "NAD" means that the issue was deemed "Not a defect"</I> -->
8385
<table id="issues" border="1">

0 commit comments

Comments
 (0)