Skip to content

Commit

Permalink
[libc++][format] LWG-3648 format should not print bool with 'c'
Browse files Browse the repository at this point in the history
Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D119350
  • Loading branch information
mordante committed Feb 11, 2022
1 parent b6d6b8c commit efe5cba
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 125 deletions.
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx2bIssues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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|"
Expand Down
4 changes: 0 additions & 4 deletions libcxx/include/__format/formatter_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -401,7 +331,6 @@ constexpr void test() {
test({}, 0, CSTR("}"));

test_as_string<CharT>();
test_as_char<CharT>();
test_as_integer<CharT>();

// *** Type ***
Expand All @@ -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}"));
Expand Down
50 changes: 1 addition & 49 deletions libcxx/test/std/utilities/format/format.functions/format_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 ***
Expand Down

0 comments on commit efe5cba

Please sign in to comment.