Skip to content

to_chars can puts leading zeros on numbers #41511

@mclow

Description

@mclow
Bugzilla Link 42166
Resolution FIXED
Resolved on Jun 10, 2019 14:14
Version unspecified
OS All
CC @ivafanas,@lichray,@mclow,@jwakely

Extended Description

Given the following code:

#include
#include
#include

template
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();
test();
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillalibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions