[libcxx-commits] [libcxx] 36e0e2c - [libc++][format] Allows width arg-id with value 0.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 31 10:19:24 PDT 2022
Author: Mark de Wever
Date: 2022-08-31T19:19:13+02:00
New Revision: 36e0e2c485447ac984a375aa0829f8c75d565fbb
URL: https://github.com/llvm/llvm-project/commit/36e0e2c485447ac984a375aa0829f8c75d565fbb
DIFF: https://github.com/llvm/llvm-project/commit/36e0e2c485447ac984a375aa0829f8c75d565fbb.diff
LOG: [libc++][format] Allows width arg-id with value 0.
Implements:
- LWG3721 Allow an arg-id with a value of zero for width in std-format-spec
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D130649
Added:
Modified:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__format/parser_std_format_spec.h
libcxx/test/std/utilities/format/format.functions/format_tests.h
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 0541ef241ddf0..85a93cc52ee64 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/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",""
diff --git a/libcxx/include/__format/parser_std_format_spec.h b/libcxx/include/__format/parser_std_format_spec.h
index 1425a953ebaa2..5dfcb5fb7e5f9 100644
--- a/libcxx/include/__format/parser_std_format_spec.h
+++ b/libcxx/include/__format/parser_std_format_spec.h
@@ -534,10 +534,7 @@ class _LIBCPP_TEMPLATE_VIS __parser {
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
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 551e1dd066a99..5b5db6403886f 100644
--- a/libcxx/test/std/utilities/format/format.functions/format_tests.h
+++ b/libcxx/test/std/utilities/format/format.functions/format_tests.h
@@ -241,6 +241,9 @@ void format_test_string(const W& world, const U& universe, TestFunction check, E
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.");
@@ -249,7 +252,6 @@ void format_test_string(const W& world, const U& universe, TestFunction check, E
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));
More information about the libcxx-commits
mailing list