[libcxx-commits] [libcxx] [libc++][format] Decay character arrays in formatting (PR #116571)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 26 14:09:56 PST 2024


================
@@ -188,15 +182,8 @@ _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __valu
   else if constexpr (__arg == __arg_t::__unsigned_long_long)
     return basic_format_arg<_Context>{__arg, static_cast<unsigned long long>(__value)};
   else if constexpr (__arg == __arg_t::__string_view)
-    // Using std::size on a character array will add the NUL-terminator to the size.
-    if constexpr (is_array_v<_Dp>)
-      return basic_format_arg<_Context>{
-          __arg, basic_string_view<typename _Context::char_type>{__value, extent_v<_Dp> - 1}};
----------------
ldionne wrote:

If I understand correctly, this patch as-is will cause character arrays to decay to pointers, and then their size to be computed as-if `strlen` instead, right? Since we do have the information available statically, it might be interesting to carry it around to avoid recomputing this. However, I can also imagine this would require significant changes to the implementation.

Assuming I correctly understood what this tradeoff is about, one thing that might be worth checking is whether the `strlen` call is actually getting constant folded in most use cases. This may be a non-issue.

https://github.com/llvm/llvm-project/pull/116571


More information about the libcxx-commits mailing list