[llvm-branch-commits] [libcxx] 59d896f - [libc++][format] Fixes invalid usage of m type.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Mar 8 05:38:52 PST 2023


Author: Mark de Wever
Date: 2023-03-08T05:38:23-08:00
New Revision: 59d896fd7f9340ed29d8e46964a792df6f836340

URL: https://github.com/llvm/llvm-project/commit/59d896fd7f9340ed29d8e46964a792df6f836340
DIFF: https://github.com/llvm/llvm-project/commit/59d896fd7f9340ed29d8e46964a792df6f836340.diff

LOG: [libc++][format] Fixes invalid usage of m type.

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.

Reviewed By: ldionne, #libc

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

(cherry picked from commit 347a65a16493f00ee3eaeaeaf11d3611c62343eb)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__format/concepts.h b/libcxx/include/__format/concepts.h
index fe4a7b9625ce3..ba8d8e316226d 100644
--- a/libcxx/include/__format/concepts.h
+++ b/libcxx/include/__format/concepts.h
@@ -66,9 +66,8 @@ concept formattable = __formattable<_Tp, _CharT>;
 // 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 > 20
 #endif //_LIBCPP_STD_VER > 17

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 a884ba7ec8585..cd0bc5ad1d81e 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
@@ -1260,7 +1260,7 @@ void test_tuple_int(TestFunction check, ExceptionTest check_exception) {
   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 @@ void test_tuple_int_int_int(TestFunction check, ExceptionTest check_exception) {
   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);
 

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 a465916afa10e..cdd39e6945221 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
@@ -1083,7 +1083,7 @@ void test_tuple_int(TestFunction check, ExceptionTest check_exception) {
   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"))
@@ -1184,7 +1184,7 @@ void test_tuple_int_int_int(TestFunction check, ExceptionTest check_exception) {
   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"))


        


More information about the llvm-branch-commits mailing list