Skip to content

Commit 63cdc34

Browse files
committed
fix(launder-iterator): fixing ub
1 parent b6141b6 commit 63cdc34

30 files changed

+382
-364
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PenaltyBreakFirstLessLess: 0
5656
PenaltyBreakOpenParenthesis: 10
5757
PenaltyBreakScopeResolution: 30
5858
PenaltyBreakString: 100
59-
PenaltyBreakTemplateDeclaration: 100
59+
PenaltyBreakTemplateDeclaration: 0
6060
PenaltyExcessCharacter: 1000
6161
PenaltyIndentedWhitespace: 0
6262
PenaltyReturnTypeOnItsOwnLine: 50

include/stdsharp/algorithm/algorithm.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ namespace stdsharp
4747
template<
4848
typename T,
4949
typename Proj = std::identity,
50-
std::indirect_strict_weak_order<std::projected<const T*, Proj>> Compare =
51-
std::ranges::less>
50+
std::indirect_strict_weak_order<std::projected<const T*, Proj>> Compare = std::ranges::
51+
less>
5252
[[nodiscard]] constexpr auto operator()(
5353
const T& t,
5454
decltype(t) min,
@@ -154,11 +154,8 @@ namespace stdsharp
154154
constexpr move_n_result<In, Out>
155155
operator()(In in, const std::iter_difference_t<In> n, Out out) const
156156
{
157-
auto&& r = std::ranges::move(
158-
std::counted_iterator{cpp_move(in), n},
159-
std::default_sentinel,
160-
cpp_move(out)
161-
);
157+
auto&& r = std::ranges::
158+
move(std::counted_iterator{cpp_move(in), n}, std::default_sentinel, cpp_move(out));
162159

163160
return {cpp_move(r).in.base(), cpp_move(r).out};
164161
}

include/stdsharp/compare/compare.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ namespace stdsharp
2424
concept ordering_predicate = ordering_like<Cat> && regular_invocable_r<Fn, Cat, T, U>;
2525

2626
template<typename Fn, typename T, typename U, typename Cat = std::partial_ordering>
27-
concept nothrow_ordering_predicate =
28-
ordering_predicate<Fn, T, U, Cat> && nothrow_invocable_r<Fn, Cat, T, U>;
27+
concept nothrow_ordering_predicate = ordering_predicate<Fn, T, U, Cat> &&
28+
nothrow_invocable_r<Fn, Cat, T, U>;
2929
}

include/stdsharp/concepts/object.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ namespace stdsharp
7070
concept inter_convertible = std::convertible_to<T, U> && convertible_from<T, U>;
7171

7272
template<typename T, typename U>
73-
concept nothrow_inter_convertible =
74-
nothrow_convertible_to<T, U> && nothrow_convertible_from<T, U>;
73+
concept nothrow_inter_convertible = nothrow_convertible_to<T, U> &&
74+
nothrow_convertible_from<T, U>;
7575

7676
template<typename T, typename U>
77-
concept explicitly_inter_convertible =
78-
explicitly_convertible<T, U> && explicitly_convertible_from<T, U>;
77+
concept explicitly_inter_convertible = explicitly_convertible<T, U> &&
78+
explicitly_convertible_from<T, U>;
7979

8080
template<typename T, typename U>
81-
concept nothrow_explicitly_inter_convertible =
82-
nothrow_explicitly_convertible<T, U> && nothrow_explicitly_convertible_from<T, U>;
81+
concept nothrow_explicitly_inter_convertible = nothrow_explicitly_convertible<T, U> &&
82+
nothrow_explicitly_convertible_from<T, U>;
8383

8484
template<typename B>
8585
concept boolean_testable = std::convertible_to<B, bool> && requires(B&& b) {
@@ -143,8 +143,8 @@ namespace stdsharp
143143
requires { std::declval<void(const T&)>()({std::declval<Args>()...}); };
144144

145145
template<typename T>
146-
concept implicitly_move_constructible =
147-
std::move_constructible<T> && implicitly_constructible_from<T, T>;
146+
concept implicitly_move_constructible = std::move_constructible<T> &&
147+
implicitly_constructible_from<T, T>;
148148

149149
template<typename T>
150150
concept implicitly_copy_constructible = std::copy_constructible<T> && //
@@ -157,8 +157,8 @@ namespace stdsharp
157157
concept nothrow_constructible_from = std::is_nothrow_constructible_v<T, Args...>;
158158

159159
template<typename T>
160-
concept nothrow_default_initializable =
161-
std::default_initializable<T> && std::is_nothrow_default_constructible_v<T>;
160+
concept nothrow_default_initializable = std::default_initializable<T> &&
161+
std::is_nothrow_default_constructible_v<T>;
162162

163163
template<typename T>
164164
concept nothrow_move_constructible = std::is_nothrow_move_constructible_v<T>;
@@ -205,12 +205,12 @@ namespace stdsharp
205205
concept nothrow_invocable = std::is_nothrow_invocable_v<Func, Args...>;
206206

207207
template<typename Func, typename ReturnT, typename... Args>
208-
concept regular_invocable_r =
209-
std::regular_invocable<Func, Args...> && invocable_r<Func, ReturnT, Args...>;
208+
concept regular_invocable_r = std::regular_invocable<Func, Args...> &&
209+
invocable_r<Func, ReturnT, Args...>;
210210

211211
template<typename Func, typename ReturnT, typename... Args>
212-
concept nothrow_regular_invocable_r =
213-
regular_invocable_r<Func, ReturnT, Args...> && nothrow_invocable_r<Func, ReturnT, Args...>;
212+
concept nothrow_regular_invocable_r = regular_invocable_r<Func, ReturnT, Args...> &&
213+
nothrow_invocable_r<Func, ReturnT, Args...>;
214214

215215
template<typename Func, typename... Args>
216216
concept nothrow_predicate = nothrow_invocable_r<Func, bool, Args...>;
@@ -262,4 +262,10 @@ namespace stdsharp
262262
{ t1 <<= t2 } -> std::same_as<T&>;
263263
{ t1 >>= t2 } -> std::same_as<T&>;
264264
};
265+
266+
template<typename T, typename U>
267+
concept decay_derived = std::is_base_of_v<std::remove_reference_t<U>, std::remove_reference_t<T>>;
268+
269+
template<typename T, typename U>
270+
concept not_decay_derived = !decay_derived<T, U>;
265271
}

include/stdsharp/containers/actions.h

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ namespace stdsharp::actions::cpo::inline cpo_impl::details
4343
template<container_erasable Container>
4444
constexpr auto operator()(
4545
Container& container,
46-
const std::equality_comparable_with<typename std::decay_t<Container>::value_type> auto&
47-
value
46+
const std::
47+
equality_comparable_with<typename std::decay_t<Container>::value_type> auto& value
4848
) const
4949
requires requires {
5050
requires sequence_container<Container>;
@@ -58,8 +58,8 @@ namespace stdsharp::actions::cpo::inline cpo_impl::details
5858
requires associative_like_container<Container>
5959
constexpr auto operator()(
6060
Container& container,
61-
const std::equality_comparable_with<typename std::decay_t<Container>::key_type> auto&
62-
key
61+
const std::
62+
equality_comparable_with<typename std::decay_t<Container>::key_type> auto& key
6363
) const
6464
{
6565
return container.erase(key);
@@ -93,50 +93,48 @@ namespace stdsharp::actions::cpo::inline cpo_impl
9393
inline constexpr erase_fn erase{};
9494
}
9595

96-
namespace stdsharp::actions
97-
{
98-
#define STDSHARP_EMPLACE_WHERE_ACTION(where, iter) \
99-
namespace details \
100-
{ \
101-
struct emplace_##where##_default_fn \
102-
{ \
103-
template<typename Container, typename... Args> \
104-
requires std::invocable< \
105-
emplace_fn, \
106-
Container&, \
107-
details::container_citer<Container>, \
108-
Args...> \
109-
constexpr decltype(auto) operator()(Container& container, Args&&... args) const \
110-
{ \
111-
return *actions::emplace(container, container.c##iter(), cpp_forward(args)...); \
112-
} \
113-
}; \
114-
\
115-
struct emplace_##where##_mem_fn \
116-
{ \
117-
template<typename... Args, container_emplace_constructible<Args...> Container> \
118-
constexpr typename std::decay_t<Container>::reference \
119-
operator()(Container& container, Args&&... args) const \
120-
requires requires { \
121-
requires stdsharp::container<Container>; \
122-
container.emplace_##where(std::declval<Args>()...); \
123-
} \
124-
{ \
125-
return container.emplace_##where(cpp_forward(args)...); \
126-
} \
127-
}; \
128-
} \
129-
using emplace_##where##_fn = sequenced_invocables< \
130-
details::emplace_##where##_mem_fn, \
131-
details::emplace_##where##_default_fn>; \
132-
\
133-
inline constexpr emplace_##where##_fn emplace_##where{};
96+
#define STDSHARP_EMPLACE_WHERE_ACTION(where, iter) \
97+
namespace stdsharp::actions::details \
98+
{ \
99+
struct emplace_##where##_default_fn \
100+
{ \
101+
template<typename Container, typename... Args> \
102+
requires std:: \
103+
invocable<emplace_fn, Container&, details::container_citer<Container>, Args...> \
104+
constexpr decltype(auto) operator()(Container& container, Args&&... args) const \
105+
{ \
106+
return *actions::emplace(container, container.c##iter(), cpp_forward(args)...); \
107+
} \
108+
}; \
109+
\
110+
struct emplace_##where##_mem_fn \
111+
{ \
112+
template<typename... Args, container_emplace_constructible<Args...> Container> \
113+
constexpr typename std::decay_t<Container>::reference \
114+
operator()(Container& container, Args&&... args) const \
115+
requires requires { \
116+
requires stdsharp::container<Container>; \
117+
container.emplace_##where(std::declval<Args>()...); \
118+
} \
119+
{ \
120+
return container.emplace_##where(cpp_forward(args)...); \
121+
} \
122+
}; \
123+
} \
124+
\
125+
namespace stdsharp::actions \
126+
{ \
127+
using emplace_##where##_fn = sequenced_invocables< \
128+
details::emplace_##where##_mem_fn, \
129+
details::emplace_##where##_default_fn>; \
130+
\
131+
inline constexpr emplace_##where##_fn emplace_##where{}; \
132+
}
134133

135-
STDSHARP_EMPLACE_WHERE_ACTION(back, end)
136-
STDSHARP_EMPLACE_WHERE_ACTION(front, begin)
134+
STDSHARP_EMPLACE_WHERE_ACTION(back, end)
135+
STDSHARP_EMPLACE_WHERE_ACTION(front, begin)
137136

138137
#undef STDSHARP_EMPLACE_WHERE_ACTION
139-
}
140138

141139
namespace stdsharp::actions::cpo::inline cpo_impl::details
142140
{

include/stdsharp/containers/concepts.h

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace stdsharp
2323
};
2424

2525
template<typename Rng, typename ValueType>
26-
concept compatible_range =
27-
ranges::input_range<Rng> && std::convertible_to<ranges::range_reference_t<Rng>, ValueType>;
26+
concept compatible_range = ranges::input_range<Rng> &&
27+
std::convertible_to<ranges::range_reference_t<Rng>, ValueType>;
2828

2929
template<typename ValueType, typename Allocator>
3030
concept erasable = requires(Allocator allocator_instance, ValueType* ptr) {
@@ -72,9 +72,8 @@ namespace stdsharp
7272
requires(Allocator allocator_instance, ValueType* ptr, ValueType&& rv) {
7373
requires move_insertable<ValueType, Allocator>;
7474
requires nothrow_move_constructible<ValueType>;
75-
requires noexcept(
76-
allocator_traits<Allocator>::construct(allocator_instance, ptr, cpp_move(rv))
77-
);
75+
requires noexcept(allocator_traits<Allocator>::
76+
construct(allocator_instance, ptr, cpp_move(rv)));
7877
};
7978

8079
template<typename Container>
@@ -133,11 +132,10 @@ namespace stdsharp
133132
concept nothrow_emplace_constructible =
134133
requires(Allocator allocator_instance, ValueType* ptr, Args&&... args) {
135134
requires nothrow_constructible_from<ValueType, Args...>;
136-
requires noexcept(allocator_traits<Allocator>::construct(
137-
allocator_instance,
138-
ptr,
139-
cpp_forward(args)...
140-
));
135+
requires noexcept( //
136+
allocator_traits<Allocator>::
137+
construct(allocator_instance, ptr, cpp_forward(args)...)
138+
);
141139
};
142140

143141
template<typename Container, typename... Args>
@@ -160,20 +158,21 @@ namespace stdsharp
160158
namespace stdsharp::details
161159
{
162160
template<typename T, typename U>
163-
concept iterator_identical =
164-
requires(std::iterator_traits<T> t_traits, std::iterator_traits<U> u_traits) {
165-
requires std::same_as<
166-
typename decltype(t_traits)::value_type,
167-
typename decltype(u_traits)::value_type>;
168-
requires std::same_as<
169-
typename decltype(t_traits)::difference_type,
170-
typename decltype(u_traits)::difference_type>;
171-
requires std::
172-
same_as<typename decltype(t_traits)::pointer, typename decltype(u_traits)::pointer>;
173-
requires std::same_as<
174-
typename decltype(t_traits)::reference,
175-
typename decltype(u_traits)::reference>;
176-
};
161+
concept iterator_identical = requires(
162+
std::iterator_traits<T> t_traits,
163+
std::iterator_traits<U> u_traits
164+
) {
165+
requires std::same_as<
166+
typename decltype(t_traits)::value_type,
167+
typename decltype(u_traits)::value_type>;
168+
requires std::same_as<
169+
typename decltype(t_traits)::difference_type,
170+
typename decltype(u_traits)::difference_type>;
171+
requires std::
172+
same_as<typename decltype(t_traits)::pointer, typename decltype(u_traits)::pointer>;
173+
requires std::
174+
same_as<typename decltype(t_traits)::reference, typename decltype(u_traits)::reference>;
175+
};
177176

178177
template<typename>
179178
struct insert_return_type_of;
@@ -411,8 +410,8 @@ namespace stdsharp
411410
};
412411

413412
template<typename Container>
414-
concept contiguous_container =
415-
container<Container> && std::ranges::contiguous_range<std::decay_t<Container>>;
413+
concept contiguous_container = container<Container> &&
414+
std::ranges::contiguous_range<std::decay_t<Container>>;
416415
}
417416

418417
namespace stdsharp::details
@@ -542,9 +541,9 @@ namespace stdsharp
542541
decltype(instance),
543542
decltype(const_iter),
544543
decltype(const_iter)>::template value<decltype(key_cmp), decltype(alloc)> &&
545-
details::container_optional_constructible<
546-
decltype(instance),
547-
decltype(v_list)>::template value<decltype(key_cmp), decltype(alloc)>;
544+
details::
545+
container_optional_constructible<decltype(instance), decltype(v_list)>::
546+
template value<decltype(key_cmp), decltype(alloc)>;
548547

549548
requires !compatible_range<decltype(v_list), decltype(value)> ||
550549
details::container_optional_constructible<
@@ -563,12 +562,12 @@ namespace stdsharp
563562
};
564563

565564
template<typename Container, typename... Members>
566-
concept unique_associative_container =
567-
associative_container<Container, Members...> && details::unique_associative<Container>;
565+
concept unique_associative_container = associative_container<Container, Members...> &&
566+
details::unique_associative<Container>;
568567

569568
template<typename Container, typename... Members>
570-
concept multikey_associative_container =
571-
associative_container<Container, Members...> && details::multikey_associative<Container>;
569+
concept multikey_associative_container = associative_container<Container, Members...> &&
570+
details::multikey_associative<Container>;
572571

573572
template<typename Container, typename... Members>
574573
concept unordered_associative_container = requires {

include/stdsharp/cstdint/cstdint.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace stdsharp
1919
using u32 = std::uint32_t; // 32-bit unsigned integer type.
2020
using i64 = std::int64_t; // 64-bit signed integer type.
2121
using u64 = std::uint64_t; // 64-bit unsigned integer type.
22-
using ssize_t =
23-
std::make_signed_t<std::size_t>; // Signed integer type corresponding to `size_t`.
22+
using ssize_t = std::make_signed_t<std::size_t>; // signed size_t.
2423

2524
inline constexpr struct
2625
{

0 commit comments

Comments
 (0)