Title
std::format should escape null as \0
Status
lewg
Section
[format.string.escaped]
Submitter
Tomasz Kamiński

Created on 2026-06-10.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-06-10.09:49:08

Proposed resolution:

This wording is relative to N5046.

  1. Modify [tab:format.escape.sequences], Table 114 — Mapping of characters to escape sequences:

    CharacterEscape sequence
    U+0000 NULL \0
Date: 2026-06-10.11:37:38

[ Brno 2026-06-10; Status changed: New → LEWG. ]

LWG initially approved this as Ready, but Davis pointed out that this would produce strings that resemble an octal literal, e.g. `"abc\0123"`. LEWG should see it.

Date: 2026-06-10.09:49:08

As currently specified the debug output of std::format for a string containing a null terminator should escape it as \u{0} instead of the more conventional \0.

std::string_view sv("a\0b", 3);
std::print("{:?}", sv); // "a\u{0}b" not "a\0b"
History
Date User Action Args
2026-06-10 11:37:38adminsetstatus: ready -> lewg
2026-06-10 09:49:08adminsetmessages: + msg16402
2026-06-10 09:49:08adminsetstatus: new -> ready
2026-06-10 09:13:00adminsetmessages: + msg16401
2026-06-10 00:00:00admincreate