This is an archive of the discontinued LLVM Phabricator instance.

[libc++][format] Fix precision parser conformance.
ClosedPublic

Authored by Mordante on Dec 29 2021, 10:57 AM.

Details

Reviewers
ldionne
vitaut
Group Reviewers
Restricted Project
Commits
rGf2b40ba40004: [libc++][format] Fix precision parser conformance.
Summary

@CaseyCarter reported that the tests for the std-format-spec rejects leading
zeroes for precision, which the Standard does not require. The Standard allows
them. Only for precision, not for the width or an arg-id.

Fixes the precision parser and adds some test for the arg-id since they
were missing.

Diff Detail

Event Timeline

Mordante requested review of this revision.Dec 29 2021, 10:57 AM
Mordante created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2021, 10:57 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

LGTM FWIW

libcxx/test/std/utilities/format/format.functions/format_tests.h
180

It would be friendlier to make this message "A format-spec arg-id shouldn't have leading zeros".
Also (definitely unrelated to this PR) I think it's superfluous to keep repeating the word format-spec in all these messages. The exception type is already format_error and it's thrown during format-string parsing, right? I think "An arg-id shouldn't... would be perfectly unambiguous to the catcher.

199

I'd like to see another test case for {:.010} to conclusively prove it's parsed as decimal 10, not octal 8.

@CaseyCarter reported the std-format-spec parser prohibits leading zeros

Technically, I reported that the _test_ expects the std-format-spec parser to reject leading zeroes for precision, which the Working Draft does not require. I wouldn't write this silly format-spec even if it is allowed, but I did notice that MSVC STL fails this test.

libcxx/test/std/utilities/format/format.functions/format_tests.h
180

+1 for "... shouldn't have leading zeroes". A user who mistakenly believes that 01 is a valid _arg-id_ will read this message, see all the }s in the format string, and spend an hour investigating the wrong thing / filing a bug report when we could have pointed them directly at the problem.

Thanks for the reviews!

@CaseyCarter reported the std-format-spec parser prohibits leading zeros

Technically, I reported that the _test_ expects the std-format-spec parser to reject leading zeroes for precision, which the Working Draft does not require. I wouldn't write this silly format-spec even if it is allowed, but I did notice that MSVC STL fails this test.

True, I can reword the message. But without your report this bug wouldn't be fixed ;-) And I agree these tests are probably the only time I'll write the leading zeros for precision; unless I want to do a C++ Pub quiz.

libcxx/test/std/utilities/format/format.functions/format_tests.h
180

@vitaut suggested here https://reviews.llvm.org/D115988#inline-1110797 to simplify all messages. So for now I keep this message as is. If we keep multiple errors it should indeed be a better message, but if we're going to simplify them I rather keep this one as is.

Mordante marked 2 inline comments as done.Jan 2 2022, 8:08 AM
Mordante added inline comments.
libcxx/test/std/utilities/format/format.functions/format_tests.h
180

Changing the message requires updating some tests, so I prefer to do it in a separate PR D116495.

ldionne accepted this revision.Jan 4 2022, 10:09 AM
This revision is now accepted and ready to land.Jan 4 2022, 10:09 AM
Mordante updated this revision to Diff 397461.Jan 4 2022, 11:03 PM

Rebased to check CI, addresses the last review comment.

Mordante edited the summary of this revision. (Show Details)Jan 5 2022, 8:40 AM
This revision was automatically updated to reflect the committed changes.