Title
What should `std::format_to` etc. behave when the output is overlong?
Status
new
Section
[format]
Submitter
Jiang An

Created on 2025-05-14.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-05-14.00:00:00

It seems permitted to write overly long contents via an (C++20) output iterator with `std::format_to(_n)`, where the length isn't representable in `size_t` or `ptrdiff_t`, especially when the implementation provides integer-class types. However, currently some implementation can't properly handle content whose length is greater than `PTRDIFF_MAX`. Presumably we don't want UB in such cases. Should we explicitly allow throwing exception and/or silent truncation?

Additionally, given that the return type of `std::formatted_size` is `std::size_t`, even if the implementation supports formatted contents whose lengths are greater than `SIZE_MAX`, the length can't be correctly returned. Perhaps we need to either precisely specify the return value as modulo arithmetic seems undesired, or specify that an exception is thrown.

History
Date User Action Args
2025-05-14 00:00:00admincreate