[all-commits] [llvm/llvm-project] ab6091: [libc++][format] Discard contents since null-termi...

A. Jiang via All-commits all-commits at lists.llvm.org
Mon May 12 13:49:47 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ab60910e01eaa8bcf993cdb59a95f882b3859fd1
      https://github.com/llvm/llvm-project/commit/ab60910e01eaa8bcf993cdb59a95f882b3859fd1
  Author: A. Jiang <de34 at live.cn>
  Date:   2025-05-12 (Mon, 12 May 2025)

  Changed paths:
    M libcxx/include/__format/format_arg_store.h
    M libcxx/include/__format/formatter_string.h
    A libcxx/test/libcxx/utilities/format/format.arguments/format.arg/assert.array.pass.cpp
    M libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.char_array.pass.cpp
    M libcxx/test/std/utilities/format/format.functions/format_tests.h

  Log Message:
  -----------
  [libc++][format] Discard contents since null-terminator in character arrays in formatting (#116571)

Currently, built-in `char`/`wchar_t` arrays are assumed to be
null-terminated sequence with the terminator being the last element in
formatting. This doesn't conform to [format.arg]/6.9.

> otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`,
> initializes value with `static_cast<const char_type*>(v)`;

The standard wording specifies that character arrays are decayed to
pointers. When the null terminator is not the last element or there's no
null terminator (the latter case is UB), libc++ currently produces
different results.

Also fixes and hardens `formatter<CharT[N], CharT>::format` in
`<__format/formatter_string.h>`. These specializations are rarely used.

Fixes #115935. Also checks the preconditions in this case, which fixes
#116570.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list