Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@barcharcraz
Copy link
Contributor

@barcharcraz barcharcraz commented Sep 27, 2021

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.

@barcharcraz barcharcraz requested a review from a team as a code owner September 27, 2021 22:54
@StephanTLavavej StephanTLavavej added cxx20 C++20 feature defect report Applied retroactively format C++20/23 format labels Sep 27, 2021
@StephanTLavavej

This comment has been minimized.

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nints about naming, but looks great overall

Copy link
Contributor

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@StephanTLavavej

This comment has been minimized.

@StephanTLavavej StephanTLavavej self-assigned this Nov 19, 2021
@StephanTLavavej
Copy link
Member

I pushed changes and resolved the simple comments I had, leaving only the ones that need <format> expertise.

test_pointer_specs<charT>();
test_string_specs<charT>();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


#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
Copy link
Contributor

@CaseyCarter CaseyCarter Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

// Precision
throw_helper(STR("{:.5}"), charT{'X'});


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)...);
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto "extraneous newline to remove if we need to touch something else."

@CaseyCarter CaseyCarter removed their assignment Dec 15, 2021
@StephanTLavavej StephanTLavavej self-assigned this Dec 16, 2021
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej
Copy link
Member

I've pushed a workaround for an ICE in the internal "chk" compiler build. Introducing a named variable _Iter avoids the ICE.

@StephanTLavavej StephanTLavavej merged commit 9265c51 into microsoft:main Dec 17, 2021
@StephanTLavavej
Copy link
Member

Thanks for implementing this major C++20 DR! 😸 🎉 ✅

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

Labels

cxx20 C++20 feature defect report Applied retroactively format C++20/23 format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2216R3 std::format Improvements

5 participants