<format>: compile time checks#2221
Conversation
This comment has been minimized.
This comment has been minimized.
miscco
left a comment
There was a problem hiding this comment.
Some minor nints about naming, but looks great overall
CaseyCarter
left a comment
There was a problem hiding this comment.
Partial review.
We fail to reject even the motivating example from the paper (std::format("{:d}", "I am not a number")), because we perform most specs validation in the writer functions (which aren't called at compile time) for builtin types. Am I missing something here?
test failure was due to added compile time checking in basic_format_parse_context
Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
correct usage of wrong format output iterator in compile time parsing.
This comment has been minimized.
This comment has been minimized.
tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp
Outdated
Show resolved
Hide resolved
|
I pushed changes and resolved the simple comments I had, leaving only the ones that need |
… consteval instead of via is_constant_evaluated().
| test_pointer_specs<charT>(); | ||
| test_string_specs<charT>(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Style nitpick: The newline between these functions should be retained. (The general convention is to have a newline between all functions, except for short highly repetitive functions.) However, this isn't worth resetting testing.
stl/inc/yvals_core.h
Outdated
|
|
||
| #if _HAS_CXX23 && defined(__cpp_lib_concepts) // TRANSITION, GH-395 and GH-1814 | ||
| #define __cpp_lib_format 201907L | ||
| #define __cpp_lib_format 202106L // P2216R3 std::format improvements |
There was a problem hiding this comment.
We only have a comment like this for macros that are defined to different values in different cases - __cpp_lib_format is all-or-nothing. (Not worth resetting testing if we touch nothing else.)
tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp
Outdated
Show resolved
Hide resolved
| // Precision | ||
| throw_helper(STR("{:.5}"), charT{'X'}); | ||
|
|
||
|
|
There was a problem hiding this comment.
Here's the extra line that was removed from right before 994. =)
| test_size_helper_impl<wchar_t, Args...>(expected_size, fmt, forward<Args>(args)...); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Ditto "extraneous newline to remove if we need to touch something else."
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
|
I've pushed a workaround for an ICE in the internal "chk" compiler build. Introducing a named variable |
|
Thanks for implementing this major C++20 DR! 😸 🎉 ✅ |
This is the second half of P2216R3 (the first half is already implemented), and continues @vitaut's work from #1882
There's no new tests accompanying this PR because we don't really have "tests that should not compile". I did mess remove the throw_helper call from around several of the tests in P0645R10_text_formatting_formatting to verify those invalid strings failed to compile.
The compile time format string checking is disabled if we can't figure out that you're using a utf-8 execution character set at compile time. The compiler does have a new feature that lets us find out about other character sets, but in addition to that we'd need constexpr decoding for GB18030/GBK and CP932 (or any other legacy codepages that don't self-synchronize, or move format control characters around). This PR does enforce that the format string must be a compile-time constant, even for those unsupported codepages.
Fixes #1981.