Skip to content

Commit b622e0c

Browse files
cjdbdanakj
authored andcommitted
responds to feedback
1 parent d452e0c commit b622e0c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

sus/ptr/copy.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ void copy(::sus::marker::UnsafeFnMarker, const T* src, T* dst,
140140
sus_debug_check(reinterpret_cast<uintptr_t>(dst) % alignof(T) == 0);
141141
if constexpr (::sus::mem::size_of<T>() > 1) {
142142
auto bytes = count.checked_mul(::sus::mem::size_of<T>()).expect("overflow");
143-
memmove(dst, src, bytes);
143+
// Clang isn't able to detect that `T` is trivially relocatable, and errors
144+
// out when it's not trivially copyable. We cast to `void*` since we
145+
// require the caller to ensure the type is `TrivialCopy` or
146+
// `TriviallyRelocatable`.
147+
memmove(static_cast<void*>(dst), src, bytes);
144148
} else {
145-
memmove(dst, src, count);
149+
memmove(static_cast<void*>(dst), src, count);
146150
}
147151
}
148152

sus/ptr/nonnull.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,11 @@ struct fmt::formatter<::sus::ptr::NonNull<T>, Char> {
197197
template <class FormatContext>
198198
constexpr auto format(const ::sus::ptr::NonNull<T>& t,
199199
FormatContext& ctx) const {
200-
// t.as_ptr() returns `const T*`, so we need to cast its constness away in
201-
// order to format it.
202-
return underlying_.format(const_cast<T*>(t.as_ptr()), ctx);
200+
return underlying_.format(t.as_ptr(), ctx);
203201
}
204202

205203
private:
206-
formatter<void*, Char> underlying_;
204+
formatter<const void*, Char> underlying_;
207205
};
208206

209207
// Stream support.

0 commit comments

Comments
 (0)