Skip to content

Commit e6b5699

Browse files
committed
Avoid reserved names, transitive include, and shadowing
1 parent b9d5626 commit e6b5699

File tree

4 files changed

+84
-68
lines changed

4 files changed

+84
-68
lines changed

libcxx/include/__memory/indirect.h

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@
2222
#include <__memory/allocator_traits.h>
2323
#include <__memory/swap_allocator.h>
2424
#include <__type_traits/is_array.h>
25+
#include <__type_traits/is_assignable.h>
26+
#include <__type_traits/is_constructible.h>
2527
#include <__type_traits/is_object.h>
2628
#include <__type_traits/is_same.h>
2729
#include <__type_traits/remove_cv.h>
30+
#include <__type_traits/remove_cvref.h>
2831
#include <__utility/exchange.h>
2932
#include <__utility/forward.h>
3033
#include <__utility/in_place.h>
3134
#include <__utility/move.h>
3235
#include <__utility/swap.h>
3336
#include <initializer_list>
34-
#include <type_traits>
3537

3638
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3739
# pragma GCC system_header
3840
#endif
3941

42+
_LIBCPP_PUSH_MACROS
43+
#include <__undef_macros>
44+
4045
#if _LIBCPP_STD_VER >= 26
4146

4247
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -92,17 +97,17 @@ class _LIBCPP_NO_SPECIALIZATIONS indirect {
9297
}
9398
}
9499

95-
template <class _U = _Tp>
96-
requires(!is_same_v<remove_cvref_t<_U>, indirect> && !is_same_v<remove_cvref_t<_U>, in_place_t> &&
97-
is_constructible_v<_Tp, _U> && is_default_constructible_v<_Allocator>)
98-
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(_U&& __u)
99-
: __p_(__allocate_owned_object(__alloc_, std::forward<_U>(__u))) {}
100+
template <class _Up = _Tp>
101+
requires(!is_same_v<remove_cvref_t<_Up>, indirect> && !is_same_v<remove_cvref_t<_Up>, in_place_t> &&
102+
is_constructible_v<_Tp, _Up> && is_default_constructible_v<_Allocator>)
103+
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(_Up&& __u)
104+
: __p_(__allocate_owned_object(__alloc_, std::forward<_Up>(__u))) {}
100105

101-
template <class _U = _Tp>
102-
requires(!is_same_v<remove_cvref_t<_U>, indirect> && !is_same_v<remove_cvref_t<_U>, in_place_t> &&
103-
is_constructible_v<_Tp, _U>)
104-
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(allocator_arg_t, const _Allocator& __a, _U&& __u)
105-
: __alloc_(__a), __p_(__allocate_owned_object(__alloc_, std::forward<_U>(__u))) {}
106+
template <class _Up = _Tp>
107+
requires(!is_same_v<remove_cvref_t<_Up>, indirect> && !is_same_v<remove_cvref_t<_Up>, in_place_t> &&
108+
is_constructible_v<_Tp, _Up>)
109+
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(allocator_arg_t, const _Allocator& __a, _Up&& __u)
110+
: __alloc_(__a), __p_(__allocate_owned_object(__alloc_, std::forward<_Up>(__u))) {}
106111

107112
template <class... _Us>
108113
requires(is_constructible_v<_Tp, _Us...> && is_default_constructible_v<_Allocator>)
@@ -114,15 +119,15 @@ class _LIBCPP_NO_SPECIALIZATIONS indirect {
114119
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(allocator_arg_t, const _Allocator& __a, in_place_t, _Us&&... __us)
115120
: __alloc_(__a), __p_(__allocate_owned_object(__alloc_, std::forward<_Us>(__us)...)) {}
116121

117-
template <class _I, class... _Us>
118-
requires(is_constructible_v<_Tp, initializer_list<_I>&, _Us...> && is_default_constructible_v<_Allocator>)
119-
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(in_place_t, initializer_list<_I> __ilist, _Us&&... __us)
122+
template <class _In, class... _Us>
123+
requires(is_constructible_v<_Tp, initializer_list<_In>&, _Us...> && is_default_constructible_v<_Allocator>)
124+
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(in_place_t, initializer_list<_In> __ilist, _Us&&... __us)
120125
: __p_(__allocate_owned_object(__alloc_, __ilist, std::forward<_Us>(__us)...)) {}
121126

122-
template <class _I, class... _Us>
123-
requires is_constructible_v<_Tp, initializer_list<_I>&, _Us...>
127+
template <class _In, class... _Us>
128+
requires is_constructible_v<_Tp, initializer_list<_In>&, _Us...>
124129
_LIBCPP_HIDE_FROM_ABI constexpr explicit indirect(
125-
allocator_arg_t, const _Allocator& __a, in_place_t, initializer_list<_I> __ilist, _Us&&... __us)
130+
allocator_arg_t, const _Allocator& __a, in_place_t, initializer_list<_In> __ilist, _Us&&... __us)
126131
: __alloc_(__a), __p_(__allocate_owned_object(__alloc_, __ilist, std::forward<_Us>(__us)...)) {}
127132

128133
// [indirect.dtor], destructor
@@ -189,13 +194,13 @@ class _LIBCPP_NO_SPECIALIZATIONS indirect {
189194
return *this;
190195
}
191196

192-
template <class _U = _Tp>
193-
requires(!is_same_v<remove_cvref_t<_U>, indirect> && is_constructible_v<_Tp, _U> && is_assignable_v<_Tp&, _U>)
194-
_LIBCPP_HIDE_FROM_ABI constexpr indirect& operator=(_U&& __u) {
197+
template <class _Up = _Tp>
198+
requires(!is_same_v<remove_cvref_t<_Up>, indirect> && is_constructible_v<_Tp, _Up> && is_assignable_v<_Tp&, _Up>)
199+
_LIBCPP_HIDE_FROM_ABI constexpr indirect& operator=(_Up&& __u) {
195200
if (valueless_after_move())
196-
__p_ = __allocate_owned_object(__alloc_, std::forward<_U>(__u));
201+
__p_ = __allocate_owned_object(__alloc_, std::forward<_Up>(__u));
197202
else
198-
*__p_ = std::forward<_U>(__u);
203+
*__p_ = std::forward<_Up>(__u);
199204
return *this;
200205
}
201206

@@ -257,31 +262,31 @@ class _LIBCPP_NO_SPECIALIZATIONS indirect {
257262
}
258263

259264
// [indirect.relops], relational operators
260-
template <class _U, class _AA>
265+
template <class _Up, class _AA>
261266
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool
262-
operator==(const indirect& __lhs, const indirect<_U, _AA>& __rhs) noexcept(noexcept(*__lhs == *__rhs)) {
267+
operator==(const indirect& __lhs, const indirect<_Up, _AA>& __rhs) noexcept(noexcept(*__lhs == *__rhs)) {
263268
return (__lhs.valueless_after_move() == __rhs.valueless_after_move()) &&
264269
(__lhs.valueless_after_move() || *__lhs == *__rhs);
265270
}
266271

267-
template <class _U, class _AA>
268-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __synth_three_way_result<_Tp, _U>
269-
operator<=>(const indirect& __lhs, const indirect<_U, _AA>& __rhs) {
272+
template <class _Up, class _AA>
273+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __synth_three_way_result<_Tp, _Up>
274+
operator<=>(const indirect& __lhs, const indirect<_Up, _AA>& __rhs) {
270275
if (__lhs.valueless_after_move() || __rhs.valueless_after_move())
271276
return !__lhs.valueless_after_move() <=> !__rhs.valueless_after_move();
272277
return std::__synth_three_way(*__lhs, *__rhs);
273278
}
274279

275280
// [indirect.comp.with.t], comparison with T
276-
template <class _U>
281+
template <class _Up>
277282
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool
278-
operator==(const indirect& __lhs, const _U& __rhs) noexcept(noexcept(*__lhs == __rhs)) {
283+
operator==(const indirect& __lhs, const _Up& __rhs) noexcept(noexcept(*__lhs == __rhs)) {
279284
return !__lhs.valueless_after_move() && *__lhs == __rhs;
280285
}
281286

282-
template <class _U>
283-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __synth_three_way_result<_Tp, _U>
284-
operator<=>(const indirect& __lhs, const _U& __rhs) {
287+
template <class _Up>
288+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __synth_three_way_result<_Tp, _Up>
289+
operator<=>(const indirect& __lhs, const _Up& __rhs) {
285290
return __lhs.valueless_after_move() ? strong_ordering::less : std::__synth_three_way(*__lhs, __rhs);
286291
}
287292

@@ -310,11 +315,11 @@ indirect(_Value) -> indirect<_Value>;
310315
template <class _Allocator, class _Value>
311316
indirect(allocator_arg_t, _Allocator, _Value) -> indirect<_Value, __rebind_alloc<allocator_traits<_Allocator>, _Value>>;
312317

313-
template <class _T, class _Allocator>
314-
requires is_default_constructible_v<hash<_T>>
315-
struct hash<indirect<_T, _Allocator>> {
316-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t operator()(const indirect<_T, _Allocator>& __i) const {
317-
return __i.valueless_after_move() ? 0 : hash<_T>()(*__i);
318+
template <class _Tp, class _Allocator>
319+
requires is_default_constructible_v<hash<_Tp>>
320+
struct hash<indirect<_Tp, _Allocator>> {
321+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t operator()(const indirect<_Tp, _Allocator>& __i) const {
322+
return __i.valueless_after_move() ? 0 : hash<_Tp>()(*__i);
318323
}
319324
};
320325

@@ -329,4 +334,6 @@ _LIBCPP_END_NAMESPACE_STD
329334

330335
#endif // _LIBCPP_STD_VER >= 26
331336

337+
_LIBCPP_POP_MACROS
338+
332339
#endif // _LIBCPP___MEMORY_INDIRECT_H

libcxx/test/std/utilities/memory/indirect/indirect.obs/deref.pass.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,28 @@
2424
#include <utility>
2525

2626
constexpr bool test() {
27-
std::indirect<int> i;
28-
29-
std::same_as<int&> decltype(auto) _ = *i;
30-
std::same_as<int&&> decltype(auto) _ = *std::move(i);
31-
std::same_as<const int&> decltype(auto) _ = *std::as_const(i);
32-
std::same_as<const int&&> decltype(auto) _ = *std::move(std::as_const(i));
33-
34-
static_assert(noexcept(*i));
35-
static_assert(noexcept(*std::move(i)));
36-
static_assert(noexcept(*std::as_const(i)));
37-
static_assert(noexcept(*std::move(std::as_const(i))));
38-
39-
struct Incomplete;
40-
(void)([](std::indirect<Incomplete>& i) {
41-
(void)(*i);
42-
(void)(*std::move(i));
43-
(void)(*std::as_const(i));
44-
(void)(*std::move(std::as_const(i)));
45-
});
27+
{
28+
std::indirect<int> i;
29+
30+
std::same_as<int&> decltype(auto) _ = *i;
31+
std::same_as<int&&> decltype(auto) _ = *std::move(i);
32+
std::same_as<const int&> decltype(auto) _ = *std::as_const(i);
33+
std::same_as<const int&&> decltype(auto) _ = *std::move(std::as_const(i));
34+
35+
static_assert(noexcept(*i));
36+
static_assert(noexcept(*std::move(i)));
37+
static_assert(noexcept(*std::as_const(i)));
38+
static_assert(noexcept(*std::move(std::as_const(i))));
39+
}
40+
{
41+
struct Incomplete;
42+
(void)([](std::indirect<Incomplete>& i) {
43+
(void)(*i);
44+
(void)(*std::move(i));
45+
(void)(*std::as_const(i));
46+
(void)(*std::move(std::as_const(i)));
47+
});
48+
}
4649

4750
return true;
4851
}

libcxx/test/std/utilities/memory/indirect/indirect.obs/get_allocator.pass.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
#include <memory>
2020

2121
constexpr bool test() {
22-
const std::indirect<int> i;
22+
{
23+
const std::indirect<int> i;
2324

24-
std::same_as<std::allocator<int>> decltype(auto) _ = i.get_allocator();
25+
std::same_as<std::allocator<int>> decltype(auto) _ = i.get_allocator();
2526

26-
static_assert(noexcept(i.get_allocator()));
27-
28-
struct Incomplete;
29-
(void)([](std::indirect<Incomplete>& i) { return i.get_allocator(); });
27+
static_assert(noexcept(i.get_allocator()));
28+
}
29+
{
30+
struct Incomplete;
31+
(void)([](std::indirect<Incomplete>& i) { return i.get_allocator(); });
32+
}
3033

3134
return true;
3235
}

libcxx/test/std/utilities/memory/indirect/indirect.obs/valueless_after_move.pass.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
#include <memory>
2020

2121
constexpr bool test() {
22-
const std::indirect<int> i;
22+
{
23+
const std::indirect<int> i;
2324

24-
std::same_as<bool> decltype(auto) _ = i.valueless_after_move();
25+
std::same_as<bool> decltype(auto) _ = i.valueless_after_move();
2526

26-
static_assert(noexcept(i.valueless_after_move()));
27-
28-
struct Incomplete;
29-
(void)([](std::indirect<Incomplete>& i) { return i.valueless_after_move(); });
27+
static_assert(noexcept(i.valueless_after_move()));
28+
}
29+
{
30+
struct Incomplete;
31+
(void)([](std::indirect<Incomplete>& i) { return i.valueless_after_move(); });
32+
}
3033

3134
return true;
3235
}

0 commit comments

Comments
 (0)