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

Daniel McIntosh via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 22 09:31:12 PDT 2021


DanielMcIntosh-IBM updated this revision to Diff 381582.
DanielMcIntosh-IBM added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112017

Files:
  libcxx/include/__format/formatter_string.h


Index: libcxx/include/__format/formatter_string.h
===================================================================
--- libcxx/include/__format/formatter_string.h
+++ libcxx/include/__format/formatter_string.h
@@ -133,17 +133,25 @@
   _LIBCPP_HIDE_FROM_ABI auto
   format(const basic_string<_CharT, _Traits, _Allocator>& __str, auto& __ctx)
       -> decltype(__ctx.out()) {
-    return _Base::format(_VSTD::basic_string_view<_CharT>(__str), __ctx);
+    // drop _Traits and _Allocator
+    return _Base::format(_VSTD::basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
   }
 };
 
 // Formatter std::string_view.
 template <class _CharT, class _Traits>
-struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT
-    formatter<basic_string_view<_CharT, _Traits>, _CharT>
-    : public __format_spec::__formatter_string<_CharT> {};
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<basic_string_view<_CharT, _Traits>, _CharT>
+    : public __format_spec::__formatter_string<_CharT> {
+  using _Base = __format_spec::__formatter_string<_CharT>;
+
+  _LIBCPP_HIDE_FROM_ABI auto format(const basic_string_view<_CharT, _Traits>& __str, auto& __ctx)
+      -> decltype(__ctx.out()) {
+    // drop _Traits
+    return _Base::format(_VSTD::basic_string_view<_CharT>(__str.data(), __str.size()), __ctx);
+  }
+};
 
-#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+#  endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 #endif //_LIBCPP_STD_VER > 17
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112017.381582.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211022/1e4b924d/attachment-0001.bin>


More information about the libcxx-commits mailing list