[libcxx-commits] [PATCH] D112017: [libcxx][format] Fix how we handle char traits in formatter<string> and formatter<string_view>

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 19 10:21:04 PDT 2021


Mordante added a comment.

Nice catch!



================
Comment at: libcxx/include/__format/formatter_string.h:134
       -> decltype(__ctx.out()) {
-    return _Base::format(_VSTD::basic_string_view<_CharT>(__str), __ctx);
+    return _Base::format(_VSTD::basic_string_view<_CharT, _Traits>(__str), __ctx);
   }
----------------
I think we can here directly convert to a `VSTD::basic_string_view<_CharT>` and drop the `_Traits`.


================
Comment at: libcxx/include/__format/formatter_string.h:141
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string_view<_CharT, _Traits>, _CharT>
+    : public __format_spec::__formatter_string<_CharT, _Traits> {};
 
----------------
I even wonder whether we want to drop the `_Traits` here and have no `_Traits` for `__formatter_string`.
When a string(_view) is stored as `format_arg` the traits and allocator are stripped http://eel.is/c++draft/format#arg-9


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112017/new/

https://reviews.llvm.org/D112017



More information about the libcxx-commits mailing list