This is an archive of the discontinued LLVM Phabricator instance.

[libc++] money_get::do_get() set failbit and eofbit if iterator begin equals end
ClosedPublic

Authored by jasonliu on Apr 14 2021, 2:09 PM.

Details

Summary

Currently, if we pass in the same iterator for begin and end, the long double version of do_get would throw a runtime error.
However, according to standard (https://eel.is/c++draft/locale.money.get#virtuals-1):

If a valid sequence is recognized, does not change err; otherwise, sets err to (err|str.failbit), or
(err|str.failbit|str.eofbit) if no more characters are available, and does not change units or
digits.

So we should set the failbit and eofbit when no more characters are available.

Diff Detail

Event Timeline

jasonliu requested review of this revision.Apr 14 2021, 2:09 PM
jasonliu created this revision.
curdeius edited the summary of this revision. (Show Details)Apr 15 2021, 1:49 AM
curdeius accepted this revision as: curdeius.Apr 15 2021, 2:36 AM
curdeius added a subscriber: curdeius.

LGTM % suggestion. But please wait for libc++'s group approval.

libcxx/include/locale
3116–3120

Instead of putting this check here and in the other do_get overload, you can just put everything into __do_get (at the beginning):

if (__b == __e) {
    __err |= ios_base::failbit;
    return false;
}

No need to set eofbit there, as it's set in do_get anyway.

This revision is now accepted and ready to land.Apr 15 2021, 2:36 AM
curdeius added inline comments.Apr 15 2021, 2:39 AM
libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp
729

Oh, and please change the value from 0 to some other (magic) value to verify it's not changed.

jasonliu updated this revision to Diff 337766.Apr 15 2021, 7:43 AM

Address comments.

jasonliu marked 2 inline comments as done.Apr 15 2021, 7:43 AM
jasonliu added inline comments.
libcxx/include/locale
3116–3120

Thanks. Make sense.

jasonliu updated this revision to Diff 337824.Apr 15 2021, 10:34 AM
jasonliu marked an inline comment as done.

Speculative fix for clang-format error in CI.

jasonliu updated this revision to Diff 337841.Apr 15 2021, 11:19 AM
jasonliu updated this revision to Diff 337843.Apr 15 2021, 11:21 AM
jasonliu updated this revision to Diff 337884.Apr 15 2021, 1:27 PM

Run clang-format and hopefully it fix the pre-commit CI.

The format failure isn't your fault. There was a misconfig that's already fixed in main. Just rebase.

Gentle ping for libc++ group's review.

jasonliu added 1 blocking reviewer(s): Restricted Project.Jun 30 2021, 12:47 PM
This revision now requires review to proceed.Jun 30 2021, 12:47 PM

Ping.
@ldionne Any comments?

ldionne accepted this revision.Jul 28 2021, 1:53 PM
This revision is now accepted and ready to land.Jul 28 2021, 1:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2021, 7:23 PM