Skip to content

num_get::do_get incorrect digit grouping check #29078

@llvmbot

Description

@llvmbot
Bugzilla Link 28704
Resolution FIXED
Resolved on Jun 17, 2019 06:42
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @Quuxplusone,@mclow

Extended Description

For a locale which specifies digit grouping, num_get::do_get will enforce
that the number read in contains the grouping character at the correct
locations. It does this even if the number read in didn't have any grouping
characters present.

This is shown best with a code example:

#include
#include

int main()
{
std::locale::global(std::locale("en_US.UTF-8"));
std::istringstream iss("1024");
int a = 0;
iss >> a;
std::cout << a << ", " << iss.fail() << std::endl;
}

With libc++ this prints:

1024, 1

With libstdc++ this prints:

1024, 0

http://coliru.stacked-crooked.com/a/9283df64c2bd5142

The standard says:

Digit grouping is checked. That is, the positions of discarded separators is
examined for consistency with
use_facet<numpunct >(loc).grouping(). If they are not consistent then
ios_base::failbit is assigned to err.

http://eel.is/c++draft/facet.num.get.virtuals#4

Whilst the standard could be clearer, it seems one can take it to mean that as
there are no discarded characters, there is nothing to examine for consistency.

This is the approach that libstdc++ takes, as well as boost's lexical_cast:

https://svn.boost.org/trac/boost/ticket/5585

I think it's reasonable that libc++ changes its implementation to match.

Metadata

Metadata

Assignees

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