Given the following code: ------ #include <charconv> #include <iostream> #include <cassert> template <typename T> void test() { char buf[100]; auto res = std::to_chars(buf, buf + 100, (T)0xffffffff); assert(res.ec == std::errc()); *res.ptr = '\0'; std::cout << (const char *) buf << std::endl; } int main () { test<int>(); test<long>(); test<int64_t>(); test<unsigned int>(); test<unsigned long>(); test<uint64_t>(); } ----- I expect this to print: -1 4294967295 4294967295 4294967295 4294967295 4294967295 but instead it prints: -1 0004294967295 0004294967295 4294967295 0004294967295 0004294967295
Created attachment 22076 [details] Runtime tests for std::to_chars<integral type> These are my tests for to_chars for integral types. These were written for libstdc++ and contributed to GCC, but as the sole author I'm free to relicense them for distribution in libc++ as well. Which I'm doing now. There are currently several failures when using libc++. The first few seem to be the issue described here. There are also some failures in base 2 output, but I didn't analyze them.
(In reply to Jonathan Wakely from comment #1) > > These are my tests for to_chars for integral types. These were written for > libstdc++ and contributed to GCC, but as the sole author I'm free to > relicense them for distribution in libc++ as well. Which I'm doing now. > Thanks for your tests. > There are currently several failures when using libc++. The first few seem > to be the issue described here. Yes, I walked through the original code (branchlut3) contributed by RapidJSON author in debugger and saw the same issue. The issue doesn't present in branchlut2. I'm going to contacting him to look at it. > There are also some failures in base 2 > output, but I didn't analyze them. I looked into them, and I think your test cases are asking for something not required by the standard. The standard does not guarantee that we don't modify the space after r.ptr in the buffer. My code may write to anywhere in the buffer provided https://github.com/llvm-mirror/libcxx/blob/master/include/charconv#L377 then move the content to the front if needed.
Vlad has proposed a fix here: https://reviews.llvm.org/D59178 I am looking into it as well.
Good catch, I should mark those checks as GNU-specific in our copy, and you won't want to keep that part in the libc++ tests.
Bugfix proposal: https://reviews.llvm.org/D63047 I will be very grateful for a help with review.
Fixed in revision 362967.