@@ -41,13 +41,10 @@ struct Tester {
4141 constexpr Tester (const char (&r)[N]) { __builtin_memcpy (text, r, N); }
4242 char text[N];
4343
44- // The size of the array shouldn't include the NUL character.
45- static const std::size_t size = N - 1 ;
46-
4744 template <class CharT >
4845 void
4946 test (const std::basic_string<CharT>& expected, const std::basic_string_view<CharT>& fmt, std::size_t offset) const {
50- using Str = CharT[size ];
47+ using Str = CharT[N ];
5148 std::basic_format_parse_context<CharT> parse_ctx{fmt};
5249 std::formatter<Str, CharT> formatter;
5350 static_assert (std::semiregular<decltype (formatter)>);
@@ -60,13 +57,9 @@ struct Tester {
6057 auto out = std::back_inserter (result);
6158 using FormatCtxT = std::basic_format_context<decltype (out), CharT>;
6259
63- std::basic_string<CharT> buffer{text, text + N};
64- // Note not too found of this hack
65- Str* data = reinterpret_cast <Str*>(const_cast <CharT*>(buffer.c_str ()));
66-
6760 FormatCtxT format_ctx =
68- test_format_context_create<decltype (out), CharT>(out, std::make_format_args<FormatCtxT>(*data ));
69- formatter.format (*data , format_ctx);
61+ test_format_context_create<decltype (out), CharT>(out, std::make_format_args<FormatCtxT>(text ));
62+ formatter.format (text , format_ctx);
7063 assert (result == expected);
7164 }
7265
@@ -118,8 +111,8 @@ template <class CharT>
118111void test_array () {
119112 test_helper_wrapper<" azAZ09,./<>?" >(STR (" azAZ09,./<>?" ), STR (" }" ));
120113
121- std::basic_string<CharT> s ( CSTR ( " abc \0 abc " ), 7 );
122- test_helper_wrapper<" abc\0 abc" >(s , STR (" }" ));
114+ // Contents after embedded null terminator are not formatted.
115+ test_helper_wrapper<" abc\0 abc" >(STR ( " abc " ) , STR (" }" ));
123116
124117 test_helper_wrapper<" world" >(STR (" world" ), STR (" }" ));
125118 test_helper_wrapper<" world" >(STR (" world" ), STR (" _>}" ));
0 commit comments