Author: Mark de Wever Date: 2022-02-11T17:45:14+01:00 New Revision: efe5cbaf42da80f7bbe9010d1663fb44af057954
URL: https://github.com/llvm/llvm-project/commit/efe5cbaf42da80f7bbe9010d1663fb44af057954 DIFF: https://github.com/llvm/llvm-project/commit/efe5cbaf42da80f7bbe9010d1663fb44af057954.diff LOG: [libc++][format] LWG-3648 format should not print bool with 'c' Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D119350 Added: Modified: libcxx/docs/Status/Cxx2bIssues.csv libcxx/include/__format/formatter_bool.h libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp 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 f335a3b2fa1d8..b806f8be79a74 100644 --- a/libcxx/docs/Status/Cxx2bIssues.csv +++ b/libcxx/docs/Status/Cxx2bIssues.csv @@ -151,7 +151,7 @@ "`3621 <https://wg21.link/LWG3621>`__","Remove feature-test macro ``__cpp_lib_monadic_optional`` ","February 2022","","" "`3632 <https://wg21.link/LWG3632>`__","``unique_ptr`` ""Mandates: This constructor is not selected by class tmeplate argument deduction""","February 2022","|Nothing to do|","" "`3643 <https://wg21.link/LWG3643>`__","Missing ``constexpr`` in ``std::counted_iterator`` ","February 2022","","" -"`3648 <https://wg21.link/LWG3648>`__","``format`` should not print ``bool`` with ``'c'`` ","February 2022","","","|format|" +"`3648 <https://wg21.link/LWG3648>`__","``format`` should not print ``bool`` with ``'c'`` ","February 2022","|Complete|","15.0","|format|" "`3649 <https://wg21.link/LWG3649>`__","[fund.ts.v2] Reinstate and bump ``__cpp_lib_experimental_memory_resource`` feature test macro","February 2022","","" "`3650 <https://wg21.link/LWG3650>`__","Are ``std::basic_string`` 's ``iterator`` and ``const_iterator`` constexpr iterators?","February 2022","|Nothing to do|","" "`3654 <https://wg21.link/LWG3654>`__","``basic_format_context::arg(size_t)`` should be ``noexcept`` ","February 2022","|Complete|","15.0","|format|" diff --git a/libcxx/include/__format/formatter_bool.h b/libcxx/include/__format/formatter_bool.h index 52d5224a15a11..f42868365771a 100644 --- a/libcxx/include/__format/formatter_bool.h +++ b/libcxx/include/__format/formatter_bool.h @@ -54,10 +54,6 @@ class _LIBCPP_TEMPLATE_VIS __parser_bool : public __parser_integral<_CharT> { this->__handle_bool(); break; - case _Flags::_Type::__char: - this->__handle_char(); - break; - case _Flags::_Type::__binary_lower_case: case _Flags::_Type::__binary_upper_case: case _Flags::_Type::__octal: diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp index 6d233f80ac537..772cffbc33d48 100644 --- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp +++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp @@ -196,76 +196,6 @@ constexpr void test_as_string() { test({.locale_specific_form = true}, 2, CSTR("Ls}")); } -template <class CharT> -constexpr void test_as_char() { - - test({.type = _Flags::_Type::__char}, 1, CSTR("c}")); - - // *** Align-fill *** - test({.alignment = _Flags::_Alignment::__left, .type = _Flags::_Type::__char}, - 2, CSTR("<c}")); - test({.alignment = _Flags::_Alignment::__center, - .type = _Flags::_Type::__char}, - 2, "^c}"); - test( - {.alignment = _Flags::_Alignment::__right, .type = _Flags::_Type::__char}, - 2, ">c}"); - - test({.fill = CharT('L'), - .alignment = _Flags::_Alignment::__left, - .type = _Flags::_Type::__char}, - 3, CSTR("L<c}")); - test({.fill = CharT('#'), - .alignment = _Flags::_Alignment::__center, - .type = _Flags::_Type::__char}, - 3, CSTR("#^c}")); - test({.fill = CharT('0'), - .alignment = _Flags::_Alignment::__right, - .type = _Flags::_Type::__char}, - 3, CSTR("0>c}")); - - // *** Sign *** - test_exception<Parser<CharT>>( - "A sign field isn't allowed in this format-spec", CSTR("-c}")); - - // *** Alternate form *** - test_exception<Parser<CharT>>( - "An alternate form field isn't allowed in this format-spec", CSTR("#c}")); - - // *** Zero padding *** - test_exception<Parser<CharT>>( - "A zero-padding field isn't allowed in this format-spec", CSTR("0c}")); - - // *** Width *** - test({.width = 0, .width_as_arg = false, .type = _Flags::_Type::__char}, 1, - CSTR("c}")); - test({.width = 1, .width_as_arg = false, .type = _Flags::_Type::__char}, 2, - CSTR("1c}")); - test({.width = 10, .width_as_arg = false, .type = _Flags::_Type::__char}, 3, - CSTR("10c}")); - test({.width = 1000, .width_as_arg = false, .type = _Flags::_Type::__char}, 5, - CSTR("1000c}")); - test({.width = 1000000, .width_as_arg = false, .type = _Flags::_Type::__char}, - 8, CSTR("1000000c}")); - - test({.width = 0, .width_as_arg = true, .type = _Flags::_Type::__char}, 3, - CSTR("{}c}")); - test({.width = 0, .width_as_arg = true, .type = _Flags::_Type::__char}, 4, - CSTR("{0}c}")); - test({.width = 1, .width_as_arg = true, .type = _Flags::_Type::__char}, 4, - CSTR("{1}c}")); - - // *** Precision *** - test_exception<Parser<CharT>>( - "The format-spec should consume the input or end with a '}'", CSTR(".")); - test_exception<Parser<CharT>>( - "The format-spec should consume the input or end with a '}'", CSTR(".1")); - - // *** Locale-specific form *** - test({.locale_specific_form = true, .type = _Flags::_Type::__char}, 2, - CSTR("Lc}")); -} - template <class CharT> constexpr void test_as_integer() { @@ -401,7 +331,6 @@ constexpr void test() { test({}, 0, CSTR("}")); test_as_string<CharT>(); - test_as_char<CharT>(); test_as_integer<CharT>(); // *** Type *** @@ -413,6 +342,7 @@ constexpr void test() { test_exception<Parser<CharT>>(expected, CSTR("F}")); test_exception<Parser<CharT>>(expected, CSTR("G}")); test_exception<Parser<CharT>>(expected, CSTR("a}")); + test_exception<Parser<CharT>>(expected, CSTR("c}")); test_exception<Parser<CharT>>(expected, CSTR("e}")); test_exception<Parser<CharT>>(expected, CSTR("f}")); test_exception<Parser<CharT>>(expected, CSTR("g}")); 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 4319f5fd1d4b1..df9f4f6b454c4 100644 --- a/libcxx/test/std/utilities/format/format.functions/format_tests.h +++ b/libcxx/test/std/utilities/format/format.functions/format_tests.h @@ -393,54 +393,7 @@ void format_test_bool(TestFunction check, ExceptionTest check_exception) { // See locale-specific_form.pass.cpp // *** type *** - for (const auto& fmt : invalid_types<CharT>("bBcdosxX")) - check_exception("The format-spec type has a type not supported for a bool argument", fmt, true); -} - -template <class CharT, class TestFunction, class ExceptionTest> -void format_test_bool_as_char(TestFunction check, ExceptionTest check_exception) { - // *** align-fill & width *** - check(SV("answer is '\1 '"), SV("answer is '{:6c}'"), true); - check(SV("answer is ' \1'"), SV("answer is '{:>6c}'"), true); - check(SV("answer is '\1 '"), SV("answer is '{:<6c}'"), true); - check(SV("answer is ' \1 '"), SV("answer is '{:^6c}'"), true); - - check(SV("answer is '-----\1'"), SV("answer is '{:->6c}'"), true); - check(SV("answer is '\1-----'"), SV("answer is '{:-<6c}'"), true); - check(SV("answer is '--\1---'"), SV("answer is '{:-^6c}'"), true); - - check(std::basic_string_view<CharT>(CSTR("answer is '\0 '"), 18), SV("answer is '{:6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is '\0 '"), 18), SV("answer is '{:6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is ' \0'"), 18), SV("answer is '{:>6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is '\0 '"), 18), SV("answer is '{:<6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is ' \0 '"), 18), SV("answer is '{:^6c}'"), false); - - check(std::basic_string_view<CharT>(CSTR("answer is '-----\0'"), 18), SV("answer is '{:->6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is '\0-----'"), 18), SV("answer is '{:-<6c}'"), false); - check(std::basic_string_view<CharT>(CSTR("answer is '--\0---'"), 18), SV("answer is '{:-^6c}'"), false); - - // *** Sign *** - check_exception("A sign field isn't allowed in this format-spec", SV("{:-c}"), true); - check_exception("A sign field isn't allowed in this format-spec", SV("{:+c}"), true); - check_exception("A sign field isn't allowed in this format-spec", SV("{: c}"), true); - - // *** alternate form *** - check_exception("An alternate form field isn't allowed in this format-spec", SV("{:#c}"), true); - - // *** zero-padding *** - check_exception("A zero-padding field isn't allowed in this format-spec", SV("{:0c}"), true); - - // *** precision *** - check_exception("The format-spec should consume the input or end with a '}'", SV("{:.c}"), true); - check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0c}"), true); - check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42c}"), true); - - // *** locale-specific form *** - // Note it has no effect but it's allowed. - check(SV("answer is '*'"), SV("answer is '{:Lc}'"), '*'); - - // *** type *** - for (const auto& fmt : invalid_types<CharT>("bBcdosxX")) + for (const auto& fmt : invalid_types<CharT>("bBdosxX")) check_exception("The format-spec type has a type not supported for a bool argument", fmt, true); } @@ -2550,7 +2503,6 @@ void format_tests(TestFunction check, ExceptionTest check_exception) { check(SV("hello false true"), SV("hello {} {}"), false, true); format_test_bool<CharT>(check, check_exception); - format_test_bool_as_char<CharT>(check, check_exception); format_test_bool_as_integer<CharT>(check, check_exception); // *** Test signed integral format argument *** _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits