[libcxx-commits] [libcxx] 84cdfbc - [libc++][format] Fixes default string alignment.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 1 12:21:55 PDT 2022


Author: Mark de Wever
Date: 2022-11-01T20:21:50+01:00
New Revision: 84cdfbcd5558ebbdec091c7ff68de286bb6ef760

URL: https://github.com/llvm/llvm-project/commit/84cdfbcd5558ebbdec091c7ff68de286bb6ef760
DIFF: https://github.com/llvm/llvm-project/commit/84cdfbcd5558ebbdec091c7ff68de286bb6ef760.diff

LOG: [libc++][format] Fixes default string alignment.

Fixes https://llvm.org/PR58315

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D137017

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__format/formatter_string.h b/libcxx/include/__format/formatter_string.h
index 8af2962cd201a..d1d1379146b70 100644
--- a/libcxx/include/__format/formatter_string.h
+++ b/libcxx/include/__format/formatter_string.h
@@ -52,7 +52,7 @@ struct _LIBCPP_TEMPLATE_VIS __formatter_string {
   _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*.

diff  --git a/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp b/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
index 50cc546879547..4145385678874 100644
--- a/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.functions/escaped_output.ascii.pass.cpp
@@ -321,7 +321,7 @@ void test_format_functions(TestFunction check) {
   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"));

diff  --git a/libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp b/libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
index cb14ff85a2922..351491940cc0e 100644
--- a/libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.functions/escaped_output.unicode.pass.cpp
@@ -391,9 +391,9 @@ void test_format_functions(TestFunction check) {
   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ö"));

diff  --git a/libcxx/test/std/utilities/format/format.functions/format_tests.h b/libcxx/test/std/utilities/format/format.functions/format_tests.h
index 77bd45d61afff..b0e57b71591c9 100644
--- a/libcxx/test/std/utilities/format/format.functions/format_tests.h
+++ b/libcxx/test/std/utilities/format/format.functions/format_tests.h
@@ -201,6 +201,7 @@ void format_test_string(const W& world, const U& universe, TestFunction check, E
   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 @@ void format_test_char(TestFunction check, ExceptionTest check_exception) {
   // ***** 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('*'));


        


More information about the libcxx-commits mailing list