[libcxx-commits] [PATCH] D100722: [libc++] Fixes std::to_chars for bases != 10.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 18 05:30:59 PDT 2021
Mordante created this revision.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
While working on D70631 <https://reviews.llvm.org/D70631>, Microsoft's unit tests discovered an issue.
Our `std::to_chars` implementation for bases != 10 uses the range
`[first,last)` as temporary buffer. This violates the contract for
to_chars:
[charconv.to.chars]/1 http://eel.is/c++draft/charconv#to.chars-1
`to_chars_result to_chars(char* first, char* last, see below value, int base = 10);`
"If the member ec of the return value is such that the value is equal to
the value of a value-initialized errc, the conversion was successful and
the member ptr is the one-past-the-end pointer of the characters
written."
Our implementation modifies the range `[member ptr, last)`, which causes
Microsoft's test to fail. Their test verifies the buffer
`[member ptr, last)` is unchanged. (The test is only done when the
conversion is successful.)
While looking at the code I noticed the performance for bases != 10 also
is suboptimal. This is tracked in D97705 <https://reviews.llvm.org/D97705>.
This patch fixes the issue and adds a benchmark. This benchmark will be
used as baseline for D97705 <https://reviews.llvm.org/D97705>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100722
Files:
libcxx/benchmarks/to_chars.bench.cpp
libcxx/include/charconv
libcxx/test/support/charconv_test_helpers.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100722.338370.patch
Type: text/x-patch
Size: 5798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210418/21ec6365/attachment.bin>
More information about the libcxx-commits
mailing list