[libcxx-commits] [PATCH] D130649: [libc++][format] Allows width arg-id with value 0.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 27 10:19:11 PDT 2022
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++.
Implements:
- LWG3721 Allow an arg-id with a value of zero for width in std-format-spec
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130649
Files:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__format/parser_std_format_spec.h
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
@@ -238,6 +238,9 @@
check_exception("A format-spec width field shouldn't have a leading zero", SV("hello {:0}"), world);
// *** width ***
+ // Width 0 allowed, but not useful for string arguments.
+ check.template operator()<"hello {:{}}">(SV("hello world"), world, 0);
+
#ifdef _LIBCPP_VERSION
// This limit isn't specified in the Standard.
static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test.");
@@ -246,7 +249,6 @@
check_exception("The numeric value of the format-spec is too large", SV("{:10000000000}"), world);
#endif
- check_exception("A format-spec width field replacement should have a positive value", SV("hello {:{}}"), world, 0);
check_exception("A format-spec arg-id replacement shouldn't have a negative value", SV("hello {:{}}"), world, -1);
check_exception("A format-spec arg-id replacement exceeds the maximum supported value", SV("hello {:{}}"), world,
unsigned(-1));
Index: libcxx/include/__format/parser_std_format_spec.h
===================================================================
--- libcxx/include/__format/parser_std_format_spec.h
+++ libcxx/include/__format/parser_std_format_spec.h
@@ -534,10 +534,7 @@
if (!__width_as_arg_)
return __width_;
- int32_t __result = __format_spec::__substitute_arg_id(__ctx.arg(__width_));
- if (__result == 0)
- __throw_format_error("A format-spec width field replacement should have a positive value");
- return __result;
+ return __format_spec::__substitute_arg_id(__ctx.arg(__width_));
}
_LIBCPP_HIDE_FROM_ABI
Index: libcxx/docs/Status/Cxx2bIssues.csv
===================================================================
--- libcxx/docs/Status/Cxx2bIssues.csv
+++ libcxx/docs/Status/Cxx2bIssues.csv
@@ -183,7 +183,7 @@
"`3713 <https://wg21.link/LWG3713>`__","Sorted with respect to comparator (only)","July 2022","",""
"`3715 <https://wg21.link/LWG3715>`__","``view_interface::empty`` is overconstrained","July 2022","",""
"`3719 <https://wg21.link/LWG3719>`__","Directory iterators should be usable with default sentinel","July 2022","",""
-"`3721 <https://wg21.link/LWG3721>`__","Allow an ``arg-id`` with a value of zero for ``width`` in ``std-format-spec``","July 2022","","","|format|"
+"`3721 <https://wg21.link/LWG3721>`__","Allow an ``arg-id`` with a value of zero for ``width`` in ``std-format-spec``","July 2022","|Complete|","16.0","|format|"
"`3724 <https://wg21.link/LWG3724>`__","``decay-copy`` should be constrained","July 2022","|Complete|","14.0"
"","","","",""
"`3645 <https://wg21.link/LWG3645>`__","``resize_and_overwrite`` is overspecified to call its callback with lvalues","Not voted in","|Complete|","14.0",""
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130649.448090.patch
Type: text/x-patch
Size: 3012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220727/b801dd81/attachment.bin>
More information about the libcxx-commits
mailing list