[libcxx-commits] [PATCH] D145309: [libc++][format] Fixes invalid usage of m type.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 4 11:03:23 PST 2023


Mordante created this revision.
Mordante added reviewers: ldionne, vitaut.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

The m type in a range formatter may only be used when a pair or a tuple
with two elements is used. This was not correctly validated as reported
in llvm.org/PR60995.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145309

Files:
  libcxx/include/__format/concepts.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


Index: libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
===================================================================
--- libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
+++ libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h
@@ -1084,7 +1084,7 @@
   check(SV("__(42), (99)___"), SV("{:_^15n}"), input);
 
   // *** type ***
-  check(SV("__{(42), (99)}___"), SV("{:_^17m}"), input);
+  check_exception("The range-format-spec type m requires two elements for a pair or tuple", SV("{:m}"), input);
   check_exception("The range-format-spec type s requires formatting a character type", SV("{:s}"), input);
   check_exception("The range-format-spec type ?s requires formatting a character type", SV("{:?s}"), input);
   for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
@@ -1185,7 +1185,7 @@
   check(SV("__(42, 99, 0), (1, 10, 100)___"), SV("{:_^30n}"), input);
 
   // *** type ***
-  check(SV("__{(42, 99, 0), (1, 10, 100)}___"), SV("{:_^32m}"), input);
+  check_exception("The range-format-spec type m requires two elements for a pair or tuple", SV("{:m}"), input);
   check_exception("The range-format-spec type s requires formatting a character type", SV("{:s}"), input);
   check_exception("The range-format-spec type ?s requires formatting a character type", SV("{:?s}"), input);
   for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
Index: libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
===================================================================
--- libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
+++ libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h
@@ -1260,7 +1260,7 @@
   check(SV("__(42), (99)___"), SV("{:_^15n}"), input);
 
   // *** type ***
-  check(SV("__{(42), (99)}___"), SV("{:_^17m}"), input);
+  check_exception("The range-format-spec type m requires two elements for a pair or tuple", SV("{:m}"), input);
   check_exception("The range-format-spec type s requires formatting a character type", SV("{:s}"), input);
   check_exception("The range-format-spec type ?s requires formatting a character type", SV("{:?s}"), input);
 
@@ -1366,7 +1366,7 @@
   check(SV("__(1, 10, 100), (42, 99, 0)___"), SV("{:_^30n}"), input);
 
   // *** type ***
-  check(SV("__{(1, 10, 100), (42, 99, 0)}___"), SV("{:_^32m}"), input);
+  check_exception("The range-format-spec type m requires two elements for a pair or tuple", SV("{:m}"), input);
   check_exception("The range-format-spec type s requires formatting a character type", SV("{:s}"), input);
   check_exception("The range-format-spec type ?s requires formatting a character type", SV("{:?s}"), input);
 
Index: libcxx/include/__format/concepts.h
===================================================================
--- libcxx/include/__format/concepts.h
+++ libcxx/include/__format/concepts.h
@@ -65,9 +65,8 @@
 // TODO FMT Add a test to validate we fail when using that concept after P2165
 // has been implemented.
 template <class _Tp>
-concept __fmt_pair_like = __is_specialization_v<_Tp, pair> ||
-                          // Use a requires since tuple_size_v may fail to instantiate,
-                          (__is_specialization_v<_Tp, tuple> && requires { tuple_size_v<_Tp> == 2; });
+concept __fmt_pair_like =
+    __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);
 
 #  endif //_LIBCPP_STD_VER >= 23
 #endif //_LIBCPP_STD_VER >= 20


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145309.502383.patch
Type: text/x-patch
Size: 3676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230304/7901e450/attachment.bin>


More information about the libcxx-commits mailing list