add static assertion to prevent lossy type conversion

This commit is contained in:
Yancey 2026-03-04 07:08:39 +08:00 committed by GitHub
parent 18ae3f4080
commit 1ff672025a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1808,6 +1808,7 @@ template <typename T> class buffer {
/// Appends data to the end of the buffer.
template <typename U>
FMT_CONSTEXPR20 void append(const U* begin, const U* end) {
static_assert(std::is_same<T, U>::value || std::is_same<U, char>::value);
while (begin != end) {
auto size = size_;
auto free_cap = capacity_ - size;