This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of LEWG status.

4589. std::format should escape null as \0

Section: 28.5.6.5 [format.string.escaped] Status: LEWG Submitter: Tomasz Kamiński Opened: 2026-06-10 Last modified: 2026-06-10

Priority: Not Prioritized

View all other issues in [format.string.escaped].

View all issues with LEWG status.

Discussion:

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"

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

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