[libcxx-commits] [libcxx] 6a18bd7 - [libc++][format] Propagate `m` when formatting range elements (#94562)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 9 01:24:10 PDT 2026


Author: A. Jiang
Date: 2026-06-09T16:24:05+08:00
New Revision: 6a18bd7be02b5f2f663018a5ab30ac12b2d3a00e

URL: https://github.com/llvm/llvm-project/commit/6a18bd7be02b5f2f663018a5ab30ac12b2d3a00e
DIFF: https://github.com/llvm/llvm-project/commit/6a18bd7be02b5f2f663018a5ab30ac12b2d3a00e.diff

LOG: [libc++][format] Propagate `m` when formatting range elements (#94562)

As per
[[tab:formatter.range.type]](https://eel.is/c++draft/tab:formatter.range.type),
the effects of the `m` option need to be propagated to the formatter of
range elements.

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>

Added: 
    

Modified: 
    libcxx/include/__format/range_formatter.h
    libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
    libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__format/range_formatter.h b/libcxx/include/__format/range_formatter.h
index 06d2b4cb4b9f4..4cf556b9ac82d 100644
--- a/libcxx/include/__format/range_formatter.h
+++ b/libcxx/include/__format/range_formatter.h
@@ -215,6 +215,8 @@ struct range_formatter {
     switch (*__begin) {
     case _CharT('m'):
       if constexpr (__fmt_pair_like<_Tp>) {
+        __underlying_.set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ": "));
+        __underlying_.set_brackets({}, {});
         set_brackets(_LIBCPP_STATICALLY_WIDEN(_CharT, "{"), _LIBCPP_STATICALLY_WIDEN(_CharT, "}"));
         set_separator(_LIBCPP_STATICALLY_WIDEN(_CharT, ", "));
         ++__begin;

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
index 0920208499006..30306bf79a68b 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
@@ -1176,10 +1176,10 @@ void test_pair_tuple(TestFunction check, ExceptionTest check_exception, auto&& i
 
   // *** n
   check(SV("__(1, 'a'), (42, '*')___"), SV("{:_^24n}"), input);
-  check(SV("__(1, 'a'), (42, '*')___"), SV("{:_^24nm}"), input); // m should have no effect
+  check(SV("____1: 'a', 42: '*'_____"), SV("{:_^24nm}"), input);
 
   // *** type ***
-  check(SV("__{(1, 'a'), (42, '*')}___"), SV("{:_^26m}"), input);
+  check(SV("____{1: 'a', 42: '*'}_____"), SV("{:_^26m}"), input);
   check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
   check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
 
@@ -1240,7 +1240,7 @@ void test_pair_tuple(TestFunction check, ExceptionTest check_exception, auto&& i
   check(SV("1: 'a', 42: '*'"), SV("{:n:m}"), input);
   check(SV("1, 'a', 42, '*'"), SV("{:n:n}"), input);
   check(SV("{1: 'a', 42: '*'}"), SV("{:m:m}"), input);
-  check(SV("{1, 'a', 42, '*'}"), SV("{:m:n}"), input);
+  check(SV("{1: 'a', 42: '*'}"), SV("{:m:n}"), input);
 }
 
 template <class CharT, class TestFunction, class ExceptionTest>

diff  --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
index b9e2151646245..f88078c2dc5b5 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
+++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
@@ -1000,10 +1000,10 @@ void test_pair_tuple(TestFunction check, ExceptionTest check_exception, auto&& i
 
   // *** n
   check(SV("__(1, 'a'), (42, '*')___"), SV("{:_^24n}"), input);
-  check(SV("__(1, 'a'), (42, '*')___"), SV("{:_^24nm}"), input); // m should have no effect
+  check(SV("____1: 'a', 42: '*'_____"), SV("{:_^24nm}"), input);
 
   // *** type ***
-  check(SV("__{(1, 'a'), (42, '*')}___"), SV("{:_^26m}"), input);
+  check(SV("____{1: 'a', 42: '*'}_____"), SV("{:_^26m}"), input);
   check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
   check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
   for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
@@ -1060,7 +1060,7 @@ void test_pair_tuple(TestFunction check, ExceptionTest check_exception, auto&& i
   check(SV("1: 'a', 42: '*'"), SV("{:n:m}"), input);
   check(SV("1, 'a', 42, '*'"), SV("{:n:n}"), input);
   check(SV("{1: 'a', 42: '*'}"), SV("{:m:m}"), input);
-  check(SV("{1, 'a', 42, '*'}"), SV("{:m:n}"), input);
+  check(SV("{1: 'a', 42: '*'}"), SV("{:m:n}"), input);
 }
 
 template <class CharT, class TestFunction, class ExceptionTest>


        


More information about the libcxx-commits mailing list