This is an archive of the discontinued LLVM Phabricator instance.

[libc++][format] Adds formatter pointer.
ClosedPublic

Authored by Mordante on Dec 18 2021, 2:49 AM.

Details

Reviewers
ldionne
vitaut
Group Reviewers
Restricted Project
Commits
rG787ccd345cbb: [libc++][format] Adds formatter pointer.
Summary

This implements the last required formatter specialization.

Completes:

  • LWG 3251 Are std::format alignment specifiers applied to string arguments?
  • LWG 3340 Formatting functions should throw on argument/format string mismatch in §[format.functions]
  • LWG 3540 §[format.arg] There should be no const in basic_format_arg(const T* p)

Implements parts of:

  • P0645 Text Formatting

Depends on D114001

Diff Detail

Event Timeline

Mordante created this revision.Dec 18 2021, 2:49 AM
Mordante requested review of this revision.Dec 18 2021, 2:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 18 2021, 2:49 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante updated this revision to Diff 395278.Dec 18 2021, 3:29 AM

Adds a missing generated test.

Mordante added inline comments.Dec 18 2021, 4:19 AM
libcxx/include/__format/format_arg.h
246

There are no tests that non-void pointers are rejected. These are added in D115989.

Mordante updated this revision to Diff 395286.Dec 18 2021, 5:19 AM

Qualify std::nullptr_t to fix a CI error.

vitaut requested changes to this revision.Dec 22 2021, 3:54 PM

Overall looks good but I think there is a potential buffer overflow in format (see inline comment).

libcxx/include/__format/formatter_pointer.h
42

What is this namespace for? __formatter_<foo> is already very specific.

53

"is looks" -> "looks"

57

I think the buffer size should be 2 + 2 * sizeof(uintptr_t). Note extra factor of two because each byte may results in two hex characters.

61

_VSTD::addressof(__buffer[2]) can be simplified to __buffer + 2. addressof doesn't seem to be adding anything useful here.

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

nit: I think the error message is a bit too technical. Something simpler along the lines of "Invalid format specifier" might be more user-friendly.

2510–2512

Do you test anywhere that non-void pointers are disallowed?

This revision now requires changes to proceed.Dec 22 2021, 3:54 PM
Mordante marked 5 inline comments as done.Dec 23 2021, 8:58 AM

Thanks for the review.

libcxx/include/__format/formatter_pointer.h
42

This is consistent with the other formatters so I prefer to keep it that way.
But maybe I'll change it, but than for all code in these namespaces.

57

Good catch, seems there's a test missing ;-)

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

This message is consistent with the message of the other parsers/formatters.
Do you suggest to change all messages to only contain "Invalid format specifier" ?

I will keep it as is in this patch. I wouldn't mind to change it, but in a separate patch and addressing all messages to keep them consistent.

2510–2512

At the moment they are allowed, this is addressed in D115989.
(See also https://reviews.llvm.org/D115988#inline-1108939)

vitaut added inline comments.Dec 23 2021, 9:12 AM
libcxx/include/__format/formatter_pointer.h
42

Yeah, I'd recommend dropping this namespace in a separate diff to keep symbol names manageable and since the names already have __format... in them.

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

Do you suggest to change all messages to only contain "Invalid format specifier" ?

Yes

Mordante updated this revision to Diff 396042.Dec 23 2021, 9:47 AM
Mordante marked 3 inline comments as done.

Addresses review comments.

vitaut accepted this revision.Dec 23 2021, 10:50 AM

LGTM

ldionne accepted this revision.Jan 4 2022, 1:49 PM
This revision is now accepted and ready to land.Jan 4 2022, 1:49 PM
Mordante updated this revision to Diff 399739.Jan 13 2022, 11:26 AM

Rebased to trigger CI and fix some tests broken after rebasing.

Mordante updated this revision to Diff 399742.Jan 13 2022, 11:43 AM

Fixes CI build.

This revision was automatically updated to reflect the committed changes.