Skip to content

Check make_format_args's preconditions - #3080

Merged
Stephan T. Lavavej (StephanTLavavej) merged 2 commits into
microsoft:mainfrom
cpplearner:has-formatter
Oct 12, 2022
Merged

Check make_format_args's preconditions#3080
Stephan T. Lavavej (StephanTLavavej) merged 2 commits into
microsoft:mainfrom
cpplearner:has-formatter

Conversation

@cpplearner

Copy link
Copy Markdown
Contributor

[format.arg.store]

Preconditions: The type typename Context​::​template formatter_­type<Ti> meets the BasicFormatter requirements ([formatter.requirements]) for each Ti in Args.

Currently, this precondition isn't checked. If an user passes an unformattable type, the error message will likely start with "'std::_Format_arg_traits<_Context>::_Phony_basic_format_arg_constructor': none of the 5 overloads could convert all the argument types", which isn't quite helpful.

Before LWG-3701, It was impractical to check this precondition, because even std::format("Hello {}!\n", "world") was a precondition violation. This is no longer a concern after LWG-3701 lands.

The error message was copied from fmtlib (https://github.com/fmtlib/fmt/blob/1feb430faaac6bd8094e996861d6025f9903d34e/include/fmt/core.h#L1771-L1772).

@cpplearner
S. B. Tam (cpplearner) requested a review from a team as a code owner September 6, 2022 19:42
Comment thread stl/inc/format Outdated
@barcharcraz

Copy link
Copy Markdown
Contributor

I'm scared that this is going to blow up because we got the nuances of the type mapping machinery confused again, somehow. I'm worried about types where formatability depends on cvref qualifiers

@barcharcraz

Copy link
Copy Markdown
Contributor

I couldn't come up with any cases where this error does not agree with the later concept failure, and this actually is an error improvement.

@barcharcraz Charlie Barto (barcharcraz) removed their assignment Sep 22, 2022
Co-authored-by: Sam Huang <samestimable2016@gmail.com>
@StephanTLavavej

Copy link
Copy Markdown
Member

I've added Standardese citations as recommended by @sam20908 (thanks!). Note that the same paragraph is cited for narrow and wide because of Effects Equivalent To wording.

✅ No modules impact.

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit fe9f858 into microsoft:main Oct 12, 2022
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for this diagnostic improvement! 🎉 💡 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved format C++20/23 format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants