[all-commits] [llvm/llvm-project] 939306: [libc++] Fixes std::to_chars for bases != 10.
mordante via All-commits
all-commits at lists.llvm.org
Thu Apr 29 10:56:53 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 9393060f908b95f30267f2122b3a2aadb698aadb
https://github.com/llvm/llvm-project/commit/9393060f908b95f30267f2122b3a2aadb698aadb
Author: Mark de Wever <koraq at xs4all.nl>
Date: 2021-04-29 (Thu, 29 Apr 2021)
Changed paths:
A libcxx/benchmarks/to_chars.bench.cpp
M libcxx/include/charconv
M libcxx/test/support/charconv_test_helpers.h
Log Message:
-----------
[libc++] Fixes std::to_chars for bases != 10.
While working on 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.
This patch fixes the issue and adds a benchmark. This benchmark will be
used as baseline for D97705.
Reviewed By: #libc, Quuxplusone, zoecarver
Differential Revision: https://reviews.llvm.org/D100722
More information about the All-commits
mailing list