Skip to content

Commit

Permalink
Suppress checked iterator warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 27, 2021
1 parent 77258f6 commit ab7c33e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ class buffer_appender : public std::back_insert_iterator<buffer<T>> {
public:
using std::back_insert_iterator<buffer<T>>::back_insert_iterator;
buffer_appender(base it) : base(it) {}
using _Unchecked_type = buffer_appender; // Mark iterator as checked.

buffer_appender& operator++() {
base::operator++();
Expand Down
12 changes: 8 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ FMT_CONSTEXPR20 OutChar* copy_str(InputIt begin, InputIt end, OutChar* out) {
if (is_constant_evaluated()) {
return copy_str<OutChar, InputIt, OutChar*>(begin, end, out);
}
return std::uninitialized_copy(begin, end, out);
auto size = to_unsigned(end - begin);
std::uninitialized_copy(begin, end, make_checked(out, size));
return out + size;
}

template <typename OutChar, typename InputIt, typename OutputIt,
Expand Down Expand Up @@ -1791,10 +1793,12 @@ inline Char* write_significand(Char* out, UInt significand,
if (!decimal_point)
return format_decimal(out, significand, significand_size).end;
auto end = format_decimal(out + 1, significand, significand_size).end;
if (integral_size == 1)
if (integral_size == 1) {
out[0] = out[1];
else
std::uninitialized_copy_n(out + 1, integral_size, out);
} else {
std::uninitialized_copy_n(out + 1, integral_size,
make_checked(out, to_unsigned(integral_size)));
}
out[integral_size] = decimal_point;
return end;
}
Expand Down

0 comments on commit ab7c33e

Please sign in to comment.