[libcxx-commits] [PATCH] D137017: [libc++][format] Fixes default string alignment.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 1 12:22:05 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG84cdfbcd5558: [libc++][format] Fixes default string alignment. (authored by Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137017

Files:
  libcxx/include/__format/formatter_string.h
  libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
  libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
  libcxx/test/std/utilities/format/format.functions/format_tests.h


Index: libcxx/test/std/utilities/format/format.functions/format_tests.h
===================================================================
--- libcxx/test/std/utilities/format/format.functions/format_tests.h
+++ libcxx/test/std/utilities/format/format.functions/format_tests.h
@@ -201,6 +201,7 @@
   check(SV("hello universe and world"), SV("hello {1} and {0}"), world, universe);
 
   check(SV("hello world"), SV("hello {:_>}"), world);
+  check(SV("hello world   "), SV("hello {:8}"), world);
   check(SV("hello    world"), SV("hello {:>8}"), world);
   check(SV("hello ___world"), SV("hello {:_>8}"), world);
   check(SV("hello _world__"), SV("hello {:_^8}"), world);
@@ -883,7 +884,6 @@
   // ***** Char type *****
   // *** align-fill & width ***
   check(SV("answer is '*     '"), SV("answer is '{:6}'"), CharT('*'));
-
   check(SV("answer is '     *'"), SV("answer is '{:>6}'"), CharT('*'));
   check(SV("answer is '*     '"), SV("answer is '{:<6}'"), CharT('*'));
   check(SV("answer is '  *   '"), SV("answer is '{:^6}'"), CharT('*'));
Index: libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
===================================================================
--- libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
+++ libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
@@ -391,9 +391,9 @@
   check(SV(R"("hello 🤷🏻\u{200d}♂\u{fe0f}"***)"), SV("{:*<30?}"), SV("hello 🤷🏻‍♂️"));
 
   // *** width ***
-  check(SV(R"(   "hellö")"), SV("{:10?}"), SV("hellö"));
-  check(SV(R"(   "hello\u{308}")"), SV("{:17?}"), SV("hello\u0308"));
-  check(SV(R"(   "hello 🤷🏻\u{200d}♂\u{fe0f}")"), SV("{:30?}"), SV("hello 🤷🏻‍♂️"));
+  check(SV(R"("hellö"   )"), SV("{:10?}"), SV("hellö"));
+  check(SV(R"("hello\u{308}"   )"), SV("{:17?}"), SV("hello\u0308"));
+  check(SV(R"("hello 🤷🏻\u{200d}♂\u{fe0f}"   )"), SV("{:30?}"), SV("hello 🤷🏻‍♂️"));
 
   // *** precision ***
   check(SV(R"("hell)"), SV("{:.5?}"), SV("hellö"));
Index: libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
===================================================================
--- libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
+++ libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
@@ -321,7 +321,7 @@
   check(SV("\"hello\u0308\"***"), SV("{:*<{}?}"), SV("hello\u0308"), sizeof(CharT) == 1 ? 12 : 11);
 
   // *** width ***
-  check(SV(R"(   "hello")"), SV("{:10?}"), SV("hello"));
+  check(SV(R"("hello"   )"), SV("{:10?}"), SV("hello"));
 
   // *** precision ***
   check(SV(R"("hell)"), SV("{:.5?}"), SV("hello"));
Index: libcxx/include/__format/formatter_string.h
===================================================================
--- libcxx/include/__format/formatter_string.h
+++ libcxx/include/__format/formatter_string.h
@@ -52,7 +52,7 @@
   _LIBCPP_HIDE_FROM_ABI constexpr void set_debug_format() { __parser_.__type_ = __format_spec::__type::__debug; }
 #  endif
 
-  __format_spec::__parser<_CharT> __parser_;
+  __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__left};
 };
 
 // Formatter const char*.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137017.472373.patch
Type: text/x-patch
Size: 3268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221101/5d4e1c3b/attachment-0001.bin>


More information about the libcxx-commits mailing list