diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv --- a/libcxx/docs/Status/Cxx2bIssues.csv +++ b/libcxx/docs/Status/Cxx2bIssues.csv @@ -183,7 +183,7 @@ "`3713 `__","Sorted with respect to comparator (only)","July 2022","","" "`3715 `__","``view_interface::empty`` is overconstrained","July 2022","","" "`3719 `__","Directory iterators should be usable with default sentinel","July 2022","","" -"`3721 `__","Allow an ``arg-id`` with a value of zero for ``width`` in ``std-format-spec``","July 2022","","","|format|" +"`3721 `__","Allow an ``arg-id`` with a value of zero for ``width`` in ``std-format-spec``","July 2022","|Complete|","16.0","|format|" "`3724 `__","``decay-copy`` should be constrained","July 2022","|Complete|","14.0" "","","","","" "`3645 `__","``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 --- a/libcxx/include/__format/parser_std_format_spec.h +++ b/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 diff --git a/libcxx/test/std/utilities/format/format.functions/format_tests.h b/libcxx/test/std/utilities/format/format.functions/format_tests.h --- 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 @@ 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 @@ 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));