Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<format>: Always enable compile-time format string checking for wchar_t #4459

Merged

Conversation

frederick-vs-ja
Copy link
Contributor

We've been enabling compiler-time format string checking for self-synchronizing execution character sets (see #2221 and #2493).

However, when the character type is wchar_t, the checking may also be skipped for certain execution character sets (Godbolt link), although, IIUC, the supported execution wide character set should always be Unicode and MSVC STL only supports wchar_t of the UTF-16 encoding.

This PR unconditionally enables compiler-time format string checking when the character type is wchar_t (or is not char, if formatting for charN_t is supported in the future).

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner March 9, 2024 05:42
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Mar 9, 2024
@StephanTLavavej StephanTLavavej self-assigned this Mar 9, 2024
@StephanTLavavej StephanTLavavej added the format C++20/23 format label Mar 13, 2024
@StephanTLavavej StephanTLavavej removed their assignment Mar 13, 2024
@@ -3682,7 +3682,7 @@ public:
template <class _Ty>
requires convertible_to<const _Ty&, basic_string_view<_CharT>>
consteval basic_format_string(const _Ty& _Str_val) : _Str(_Str_val) {
if (_Is_execution_charset_self_synchronizing()) {
if constexpr (!is_same_v<_CharT, char> || _Is_execution_charset_self_synchronizing()) {
Copy link
Member

Choose a reason for hiding this comment

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

why not is_same_v<_CharT, wchar_t>? That seems more direct to me.

Copy link
Contributor Author

@frederick-vs-ja frederick-vs-ja Mar 15, 2024

Choose a reason for hiding this comment

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

My opinion was that !is_same_v<_CharT, char> would "automatically" support charN_t if formatting for them gets supported in the future.

(or is not char, if formatting for charN_t is supported in the future)

But this reason may be not strong enough.

@StephanTLavavej StephanTLavavej self-assigned this Mar 15, 2024
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej StephanTLavavej merged commit 3ec144e into microsoft:main Mar 16, 2024
37 checks passed
@frederick-vs-ja frederick-vs-ja deleted the wchar_t-compiler-time-checking branch March 16, 2024 05:33
@StephanTLavavej
Copy link
Member

format(L"Thanks!!! {}", L"😻✅")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working format C++20/23 format
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants