1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
8 #ifndef TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H
9 #define TEST_STD_UTILITIES_FORMAT_FORMAT_FUNCTIONS_FORMAT_TESTS_H
10 
11 #include <format>
12 
13 #include <algorithm>
14 #include <cassert>
15 #include <charconv>
16 #include <cmath>
17 #include <cstdint>
18 #include <iterator>
19 
20 #include "make_string.h"
21 #include "string_literal.h"
22 #include "test_macros.h"
23 
24 // In this file the following template types are used:
25 // TestFunction must be callable as check(expected-result, string-to-format, args-to-format...)
26 // ExceptionTest must be callable as check_exception(expected-exception, string-to-format, args-to-format...)
27 
28 #define STR(S) MAKE_STRING(CharT, S)
29 #define SV(S) MAKE_STRING_VIEW(CharT, S)
30 #define CSTR(S) MAKE_CSTRING(CharT, S)
31 
32 template <class T>
33 struct context {};
34 
35 template <>
36 struct context<char> {
37   using type = std::format_context;
38 };
39 
40 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
41 template <>
42 struct context<wchar_t> {
43   using type = std::wformat_context;
44 };
45 #endif
46 
47 template <class T>
48 using context_t = typename context<T>::type;
49 
50 // A user-defined type used to test the handle formatter.
51 enum class status : uint16_t { foo = 0xAAAA, bar = 0x5555, foobar = 0xAA55 };
52 
53 // The formatter for a user-defined type used to test the handle formatter.
54 template <class CharT>
55 struct std::formatter<status, CharT> {
56   int type = 0;
57 
58   constexpr auto parse(basic_format_parse_context<CharT>& parse_ctx) -> decltype(parse_ctx.begin()) {
59     auto begin = parse_ctx.begin();
60     auto end = parse_ctx.end();
61     if (begin == end)
62       return begin;
63 
64     switch (*begin) {
65     case CharT('x'):
66       break;
67     case CharT('X'):
68       type = 1;
69       break;
70     case CharT('s'):
71       type = 2;
72       break;
73     case CharT('}'):
74       return begin;
75     default:
76       throw_format_error("The format-spec type has a type not supported for a status argument");
77     }
78 
79     ++begin;
80     if (begin != end && *begin != CharT('}'))
81       throw_format_error("The format-spec should consume the input or end with a '}'");
82 
83     return begin;
84   }
85 
86   template <class Out>
87   auto format(status s, basic_format_context<Out, CharT>& ctx) -> decltype(ctx.out()) {
88     const char* names[] = {"foo", "bar", "foobar"};
89     char buffer[6];
90     const char* begin;
91     const char* end;
92     switch (type) {
93     case 0:
94       begin = buffer;
95       buffer[0] = '0';
96       buffer[1] = 'x';
97       end = std::to_chars(&buffer[2], std::end(buffer), static_cast<uint16_t>(s), 16).ptr;
98       break;
99 
100     case 1:
101       begin = buffer;
102       buffer[0] = '0';
103       buffer[1] = 'X';
104       end = std::to_chars(&buffer[2], std::end(buffer), static_cast<uint16_t>(s), 16).ptr;
105       std::transform(static_cast<const char*>(&buffer[2]), end, &buffer[2], [](char c) { return std::toupper(c); });
106       break;
107 
108     case 2:
109       switch (s) {
110       case status::foo:
111         begin = names[0];
112         break;
113       case status::bar:
114         begin = names[1];
115         break;
116       case status::foobar:
117         begin = names[2];
118         break;
119       }
120       end = begin + strlen(begin);
121       break;
122     }
123 
124     return std::copy(begin, end, ctx.out());
125   }
126 
127 private:
128   void throw_format_error(const char* s) {
129 #ifndef TEST_HAS_NO_EXCEPTIONS
130     throw std::format_error(s);
131 #else
132     (void)s;
133     std::abort();
134 #endif
135   }
136 };
137 
138 template <class CharT>
139 std::vector<std::basic_string_view<CharT>> invalid_types(std::string valid) {
140   std::vector<std::basic_string_view<CharT>> result;
141 
142 #define CASE(T)                                                                                                        \
143 case #T[0]:                                                                                                            \
144   result.push_back(SV("Invalid formatter type {:" #T "}"));                                                            \
145   break;
146 
147   for (auto type : "aAbBcdeEfFgGopsxX") {
148     if (valid.find(type) != std::string::npos)
149       continue;
150 
151     switch (type) {
152       CASE(a)
153       CASE(A)
154       CASE(b)
155       CASE(B)
156       CASE(c)
157       CASE(d)
158       CASE(e)
159       CASE(E)
160       CASE(f)
161       CASE(F)
162       CASE(g)
163       CASE(G)
164       CASE(o)
165       CASE(p)
166       CASE(s)
167       CASE(x)
168       CASE(X)
169     case 0:
170       break;
171     default:
172       assert(false && "Add the type to the list of cases.");
173     }
174   }
175 #undef CASE
176 
177   return result;
178 }
179 
180 // Using a const ref for world and universe so a string literal will be a character array.
181 // When passed as character array W and U have different types.
182 template <class CharT, class W, class U, class TestFunction, class ExceptionTest>
183 void format_test_string(const W& world, const U& universe, TestFunction check, ExceptionTest check_exception) {
184 
185   // *** Valid input tests ***
186   // Unsed argument is ignored. TODO FMT what does the Standard mandate?
187   check.template operator()<"hello {}">(SV("hello world"), world, universe);
188   check.template operator()<"hello {} and {}">(SV("hello world and universe"), world, universe);
189   check.template operator()<"hello {0}">(SV("hello world"), world, universe);
190   check.template operator()<"hello {1}">(SV("hello universe"), world, universe);
191   check.template operator()<"hello {1} and {0}">(SV("hello universe and world"), world, universe);
192 
193   check.template operator()<"hello {:_>}">(SV("hello world"), world);
194   check.template operator()<"hello {:>8}">(SV("hello    world"), world);
195   check.template operator()<"hello {:_>8}">(SV("hello ___world"), world);
196   check.template operator()<"hello {:_^8}">(SV("hello _world__"), world);
197   check.template operator()<"hello {:_<8}">(SV("hello world___"), world);
198 
199   check.template operator()<"hello {:>>8}">(SV("hello >>>world"), world);
200   check.template operator()<"hello {:<>8}">(SV("hello <<<world"), world);
201   check.template operator()<"hello {:^>8}">(SV("hello ^^^world"), world);
202 
203   check.template operator()<"hello {:$>{}}">(SV("hello $world"), world, 6);
204   check.template operator()<"hello {0:$>{1}}">(SV("hello $world"), world, 6);
205   check.template operator()<"hello {1:$>{0}}">(SV("hello $world"), 6, world);
206 
207   check.template operator()<"hello {:.5}">(SV("hello world"), world);
208   check.template operator()<"hello {:.5}">(SV("hello unive"), universe);
209 
210   check.template operator()<"hello {:.{}}">(SV("hello univer"), universe, 6);
211   check.template operator()<"hello {0:.{1}}">(SV("hello univer"), universe, 6);
212   check.template operator()<"hello {1:.{0}}">(SV("hello univer"), 6, universe);
213 
214   check.template operator()<"hello {:%^7.7}">(SV("hello %world%"), world);
215   check.template operator()<"hello {:%^7.7}">(SV("hello univers"), universe);
216   check.template operator()<"hello {:%^{}.{}}">(SV("hello %world%"), world, 7, 7);
217   check.template operator()<"hello {0:%^{1}.{2}}">(SV("hello %world%"), world, 7, 7);
218   check.template operator()<"hello {0:%^{2}.{1}}">(SV("hello %world%"), world, 7, 7);
219   check.template operator()<"hello {1:%^{0}.{2}}">(SV("hello %world%"), 7, world, 7);
220 
221   check.template operator()<"hello {:_>s}">(SV("hello world"), world);
222   check.template operator()<"hello {:$>{}s}">(SV("hello $world"), world, 6);
223   check.template operator()<"hello {:.5s}">(SV("hello world"), world);
224   check.template operator()<"hello {:.{}s}">(SV("hello univer"), universe, 6);
225   check.template operator()<"hello {:%^7.7s}">(SV("hello %world%"), world);
226 
227   check.template operator()<"hello {:#>8.3s}">(SV("hello #####uni"), universe);
228   check.template operator()<"hello {:#^8.3s}">(SV("hello ##uni###"), universe);
229   check.template operator()<"hello {:#<8.3s}">(SV("hello uni#####"), universe);
230 
231   // *** sign ***
232   check_exception("The format-spec should consume the input or end with a '}'", SV("hello {:-}"), world);
233 
234   // *** alternate form ***
235   check_exception("The format-spec should consume the input or end with a '}'", SV("hello {:#}"), world);
236 
237   // *** zero-padding ***
238   check_exception("A format-spec width field shouldn't have a leading zero", SV("hello {:0}"), world);
239 
240   // *** width ***
241 #ifdef _LIBCPP_VERSION
242   // This limit isn't specified in the Standard.
243   static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test.");
244   check_exception("The numeric value of the format-spec is too large", SV("{:2147483648}"), world);
245   check_exception("The numeric value of the format-spec is too large", SV("{:5000000000}"), world);
246   check_exception("The numeric value of the format-spec is too large", SV("{:10000000000}"), world);
247 #endif
248 
249   check_exception("A format-spec width field replacement should have a positive value", SV("hello {:{}}"), world, 0);
250   check_exception("A format-spec arg-id replacement shouldn't have a negative value", SV("hello {:{}}"), world, -1);
251   check_exception("A format-spec arg-id replacement exceeds the maximum supported value", SV("hello {:{}}"), world,
252                   unsigned(-1));
253   check_exception("Argument index out of bounds", SV("hello {:{}}"), world);
254   check_exception("A format-spec arg-id replacement argument isn't an integral type", SV("hello {:{}}"), world,
255                   universe);
256   check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:{0}}"), world, 1);
257   check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:{}}"), world, 1);
258   // Arg-id may not have leading zeros.
259   check_exception("Invalid arg-id", SV("hello {0:{01}}"), world, 1);
260 
261   // *** precision ***
262 #ifdef _LIBCPP_VERSION
263   // This limit isn't specified in the Standard.
264   static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test.");
265   check_exception("The numeric value of the format-spec is too large", SV("{:.2147483648}"), world);
266   check_exception("The numeric value of the format-spec is too large", SV("{:.5000000000}"), world);
267   check_exception("The numeric value of the format-spec is too large", SV("{:.10000000000}"), world);
268 #endif
269 
270   // Precision 0 allowed, but not useful for string arguments.
271   check.template operator()<"hello {:.{}}">(SV("hello "), world, 0);
272   // Precision may have leading zeros. Secondly tests the value is still base 10.
273   check.template operator()<"hello {:.000010}">(SV("hello 0123456789"), STR("0123456789abcdef"));
274   check_exception("A format-spec arg-id replacement shouldn't have a negative value", SV("hello {:.{}}"), world, -1);
275   check_exception("A format-spec arg-id replacement exceeds the maximum supported value", SV("hello {:.{}}"), world,
276                   ~0u);
277   check_exception("Argument index out of bounds", SV("hello {:.{}}"), world);
278   check_exception("A format-spec arg-id replacement argument isn't an integral type", SV("hello {:.{}}"), world,
279                   universe);
280   check_exception("Using manual argument numbering in automatic argument numbering mode", SV("hello {:.{0}}"), world,
281                   1);
282   check_exception("Using automatic argument numbering in manual argument numbering mode", SV("hello {0:.{}}"), world,
283                   1);
284   // Arg-id may not have leading zeros.
285   check_exception("Invalid arg-id", SV("hello {0:.{01}}"), world, 1);
286 
287   // *** locale-specific form ***
288   check_exception("The format-spec should consume the input or end with a '}'", SV("hello {:L}"), world);
289 
290   // *** type ***
291   for (const auto& fmt : invalid_types<CharT>("s"))
292     check_exception("The format-spec type has a type not supported for a string argument", fmt, world);
293 }
294 
295 template <class CharT, class TestFunction>
296 void format_test_string_unicode([[maybe_unused]] TestFunction check) {
297   // unicode.pass.cpp and ascii.pass.cpp have additional tests.
298 #ifndef TEST_HAS_NO_UNICODE
299   // Make sure all possible types are tested. For clarity don't use macros.
300   if constexpr (std::same_as<CharT, char>) {
301     const char* c_string = "aßc";
302     check.template operator()<"{:*^5}">(SV("*aßc*"), c_string);
303     check.template operator()<"{:*^4.2}">(SV("*aß*"), c_string);
304 
305     check.template operator()<"{:*^5}">(SV("*aßc*"), const_cast<char*>(c_string));
306     check.template operator()<"{:*^4.2}">(SV("*aß*"), const_cast<char*>(c_string));
307 
308     check.template operator()<"{:*^5}">(SV("*aßc*"), "aßc");
309     check.template operator()<"{:*^4.2}">(SV("*aß*"), "aßc");
310 
311     check.template operator()<"{:*^5}">(SV("*aßc*"), std::string("aßc"));
312     check.template operator()<"{:*^4.2}">(SV("*aß*"), std::string("aßc"));
313 
314     check.template operator()<"{:*^5}">(SV("*aßc*"), std::string_view("aßc"));
315     check.template operator()<"{:*^4.2}">(SV("*aß*"), std::string_view("aßc"));
316   }
317 #  ifndef TEST_HAS_NO_WIDE_CHARACTERS
318   else {
319     const wchar_t* c_string = L"aßc";
320     check.template operator()<"{:*^5}">(SV("*aßc*"), c_string);
321     check.template operator()<"{:*^4.2}">(SV("*aß*"), c_string);
322 
323     check.template operator()<"{:*^5}">(SV("*aßc*"), const_cast<wchar_t*>(c_string));
324     check.template operator()<"{:*^4.2}">(SV("*aß*"), const_cast<wchar_t*>(c_string));
325 
326     check.template operator()<"{:*^5}">(SV("*aßc*"), L"aßc");
327     check.template operator()<"{:*^4.2}">(SV("*aß*"), L"aßc");
328 
329     check.template operator()<"{:*^5}">(SV("*aßc*"), std::wstring(L"aßc"));
330     check.template operator()<"{:*^4.2}">(SV("*aß*"), std::wstring(L"aßc"));
331 
332     check.template operator()<"{:*^5}">(SV("*aßc*"), std::wstring_view(L"aßc"));
333     check.template operator()<"{:*^4.2}">(SV("*aß*"), std::wstring_view(L"aßc"));
334   }
335 #  endif // TEST_HAS_NO_WIDE_CHARACTERS
336 
337   // ß requires one column
338   check.template operator()<"{}">(SV("aßc"), STR("aßc"));
339 
340   check.template operator()<"{:.3}">(SV("aßc"), STR("aßc"));
341   check.template operator()<"{:.2}">(SV("aß"), STR("aßc"));
342   check.template operator()<"{:.1}">(SV("a"), STR("aßc"));
343 
344   check.template operator()<"{:3.3}">(SV("aßc"), STR("aßc"));
345   check.template operator()<"{:2.2}">(SV("aß"), STR("aßc"));
346   check.template operator()<"{:1.1}">(SV("a"), STR("aßc"));
347 
348   check.template operator()<"{:-<6}">(SV("aßc---"), STR("aßc"));
349   check.template operator()<"{:-^6}">(SV("-aßc--"), STR("aßc"));
350   check.template operator()<"{:->6}">(SV("---aßc"), STR("aßc"));
351 
352   // \u1000 requires two columns
353   check.template operator()<"{}">(SV("a\u1110c"), STR("a\u1110c"));
354 
355   check.template operator()<"{:.4}">(SV("a\u1100c"), STR("a\u1100c"));
356   check.template operator()<"{:.3}">(SV("a\u1100"), STR("a\u1100c"));
357   check.template operator()<"{:.2}">(SV("a"), STR("a\u1100c"));
358   check.template operator()<"{:.1}">(SV("a"), STR("a\u1100c"));
359 
360   check.template operator()<"{:-<4.4}">(SV("a\u1100c"), STR("a\u1100c"));
361   check.template operator()<"{:-<3.3}">(SV("a\u1100"), STR("a\u1100c"));
362   check.template operator()<"{:-<2.2}">(SV("a-"), STR("a\u1100c"));
363   check.template operator()<"{:-<1.1}">(SV("a"), STR("a\u1100c"));
364 
365   check.template operator()<"{:-<7}">(SV("a\u1110c---"), STR("a\u1110c"));
366   check.template operator()<"{:-^7}">(SV("-a\u1110c--"), STR("a\u1110c"));
367   check.template operator()<"{:->7}">(SV("---a\u1110c"), STR("a\u1110c"));
368 
369   // Examples used in P1868R2
370   check.template operator()<"{:*^3}">(SV("*\u0041*"), STR("\u0041")); // { LATIN CAPITAL LETTER A }
371   check.template operator()<"{:*^3}">(SV("*\u00c1*"), STR("\u00c1")); // { LATIN CAPITAL LETTER A WITH ACUTE }
372   check.template operator()<"{:*^3}">(
373       SV("*\u0041\u0301*"),
374       STR("\u0041\u0301")); // { LATIN CAPITAL LETTER A } { COMBINING ACUTE ACCENT }
375   check.template operator()<"{:*^3}">(SV("*\u0132*"), STR("\u0132")); // { LATIN CAPITAL LIGATURE IJ }
376   check.template operator()<"{:*^3}">(SV("*\u0394*"), STR("\u0394")); // { GREEK CAPITAL LETTER DELTA }
377 
378   check.template operator()<"{:*^3}">(SV("*\u0429*"), STR("\u0429"));         // { CYRILLIC CAPITAL LETTER SHCHA }
379   check.template operator()<"{:*^3}">(SV("*\u05d0*"), STR("\u05d0"));         // { HEBREW LETTER ALEF }
380   check.template operator()<"{:*^3}">(SV("*\u0634*"), STR("\u0634"));         // { ARABIC LETTER SHEEN }
381   check.template operator()<"{:*^4}">(SV("*\u3009*"), STR("\u3009"));         // { RIGHT-POINTING ANGLE BRACKET }
382   check.template operator()<"{:*^4}">(SV("*\u754c*"), STR("\u754c"));         // { CJK Unified Ideograph-754C }
383   check.template operator()<"{:*^4}">(SV("*\U0001f921*"), STR("\U0001f921")); // { UNICORN FACE }
384   check.template operator()<"{:*^4}">(
385       SV("*\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466*"),
386       STR("\U0001f468\u200d\U0001F469\u200d\U0001F467\u200d\U0001F466")); // { Family: Man, Woman, Girl, Boy }
387 #endif // TEST_HAS_NO_UNICODE
388 }
389 
390 template <class CharT, class TestFunction, class ExceptionTest>
391 void format_string_tests(TestFunction check, ExceptionTest check_exception) {
392   std::basic_string<CharT> world = STR("world");
393   std::basic_string<CharT> universe = STR("universe");
394 
395   // Test a string literal in a way it won't decay to a pointer.
396   if constexpr (std::same_as<CharT, char>)
397     format_test_string<CharT>("world", "universe", check, check_exception);
398 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
399   else
400     format_test_string<CharT>(L"world", L"universe", check, check_exception);
401 #endif
402 
403   format_test_string<CharT>(world.c_str(), universe.c_str(), check, check_exception);
404   format_test_string<CharT>(const_cast<CharT*>(world.c_str()), const_cast<CharT*>(universe.c_str()), check,
405                             check_exception);
406   format_test_string<CharT>(std::basic_string_view<CharT>(world), std::basic_string_view<CharT>(universe), check,
407                             check_exception);
408   format_test_string<CharT>(world, universe, check, check_exception);
409   format_test_string_unicode<CharT>(check);
410 }
411 
412 template <class CharT, class TestFunction, class ExceptionTest>
413 void format_test_bool(TestFunction check, ExceptionTest check_exception) {
414 
415   // *** align-fill & width ***
416   check.template operator()<"answer is '{:7}'">(SV("answer is 'true   '"), true);
417   check.template operator()<"answer is '{:>7}'">(SV("answer is '   true'"), true);
418   check.template operator()<"answer is '{:<7}'">(SV("answer is 'true   '"), true);
419   check.template operator()<"answer is '{:^7}'">(SV("answer is ' true  '"), true);
420 
421   check.template operator()<"answer is '{:8s}'">(SV("answer is 'false   '"), false);
422   check.template operator()<"answer is '{:>8s}'">(SV("answer is '   false'"), false);
423   check.template operator()<"answer is '{:<8s}'">(SV("answer is 'false   '"), false);
424   check.template operator()<"answer is '{:^8s}'">(SV("answer is ' false  '"), false);
425 
426   check.template operator()<"answer is '{:->7}'">(SV("answer is '---true'"), true);
427   check.template operator()<"answer is '{:-<7}'">(SV("answer is 'true---'"), true);
428   check.template operator()<"answer is '{:-^7}'">(SV("answer is '-true--'"), true);
429 
430   check.template operator()<"answer is '{:->8s}'">(SV("answer is '---false'"), false);
431   check.template operator()<"answer is '{:-<8s}'">(SV("answer is 'false---'"), false);
432   check.template operator()<"answer is '{:-^8s}'">(SV("answer is '-false--'"), false);
433 
434   // *** Sign ***
435   check_exception("A sign field isn't allowed in this format-spec", SV("{:-}"), true);
436   check_exception("A sign field isn't allowed in this format-spec", SV("{:+}"), true);
437   check_exception("A sign field isn't allowed in this format-spec", SV("{: }"), true);
438 
439   check_exception("A sign field isn't allowed in this format-spec", SV("{:-s}"), true);
440   check_exception("A sign field isn't allowed in this format-spec", SV("{:+s}"), true);
441   check_exception("A sign field isn't allowed in this format-spec", SV("{: s}"), true);
442 
443   // *** alternate form ***
444   check_exception("An alternate form field isn't allowed in this format-spec", SV("{:#}"), true);
445   check_exception("An alternate form field isn't allowed in this format-spec", SV("{:#s}"), true);
446 
447   // *** zero-padding ***
448   check_exception("A zero-padding field isn't allowed in this format-spec", SV("{:0}"), true);
449   check_exception("A zero-padding field isn't allowed in this format-spec", SV("{:0s}"), true);
450 
451   // *** precision ***
452   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.}"), true);
453   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0}"), true);
454   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42}"), true);
455 
456   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.s}"), true);
457   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0s}"), true);
458   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42s}"), true);
459 
460   // *** locale-specific form ***
461   // See locale-specific_form.pass.cpp
462 
463   // *** type ***
464   for (const auto& fmt : invalid_types<CharT>("bBdosxX"))
465     check_exception("The format-spec type has a type not supported for a bool argument", fmt, true);
466 }
467 
468 template <class CharT, class TestFunction, class ExceptionTest>
469 void format_test_bool_as_integer(TestFunction check, ExceptionTest check_exception) {
470   // *** align-fill & width ***
471   check.template operator()<"answer is '{:<1d}'">(SV("answer is '1'"), true);
472   check.template operator()<"answer is '{:<2d}'">(SV("answer is '1 '"), true);
473   check.template operator()<"answer is '{:<2d}'">(SV("answer is '0 '"), false);
474 
475   check.template operator()<"answer is '{:6d}'">(SV("answer is '     1'"), true);
476   check.template operator()<"answer is '{:>6d}'">(SV("answer is '     1'"), true);
477   check.template operator()<"answer is '{:<6d}'">(SV("answer is '1     '"), true);
478   check.template operator()<"answer is '{:^6d}'">(SV("answer is '  1   '"), true);
479 
480   check.template operator()<"answer is '{:*>6d}'">(SV("answer is '*****0'"), false);
481   check.template operator()<"answer is '{:*<6d}'">(SV("answer is '0*****'"), false);
482   check.template operator()<"answer is '{:*^6d}'">(SV("answer is '**0***'"), false);
483 
484   // Test whether zero padding is ignored
485   check.template operator()<"answer is '{:>06d}'">(SV("answer is '     1'"), true);
486   check.template operator()<"answer is '{:<06d}'">(SV("answer is '1     '"), true);
487   check.template operator()<"answer is '{:^06d}'">(SV("answer is '  1   '"), true);
488 
489   // *** Sign ***
490   check.template operator()<"answer is {:d}">(SV("answer is 1"), true);
491   check.template operator()<"answer is {:-d}">(SV("answer is 0"), false);
492   check.template operator()<"answer is {:+d}">(SV("answer is +1"), true);
493   check.template operator()<"answer is {: d}">(SV("answer is  0"), false);
494 
495   // *** alternate form ***
496   check.template operator()<"answer is {:+#d}">(SV("answer is +1"), true);
497   check.template operator()<"answer is {:+b}">(SV("answer is +1"), true);
498   check.template operator()<"answer is {:+#b}">(SV("answer is +0b1"), true);
499   check.template operator()<"answer is {:+#B}">(SV("answer is +0B1"), true);
500   check.template operator()<"answer is {:+o}">(SV("answer is +1"), true);
501   check.template operator()<"answer is {:+#o}">(SV("answer is +01"), true);
502   check.template operator()<"answer is {:+x}">(SV("answer is +1"), true);
503   check.template operator()<"answer is {:+#x}">(SV("answer is +0x1"), true);
504   check.template operator()<"answer is {:+X}">(SV("answer is +1"), true);
505   check.template operator()<"answer is {:+#X}">(SV("answer is +0X1"), true);
506 
507   check.template operator()<"answer is {:#d}">(SV("answer is 0"), false);
508   check.template operator()<"answer is {:b}">(SV("answer is 0"), false);
509   check.template operator()<"answer is {:#b}">(SV("answer is 0b0"), false);
510   check.template operator()<"answer is {:#B}">(SV("answer is 0B0"), false);
511   check.template operator()<"answer is {:o}">(SV("answer is 0"), false);
512   check.template operator()<"answer is {:#o}">(SV("answer is 0"), false);
513   check.template operator()<"answer is {:x}">(SV("answer is 0"), false);
514   check.template operator()<"answer is {:#x}">(SV("answer is 0x0"), false);
515   check.template operator()<"answer is {:X}">(SV("answer is 0"), false);
516   check.template operator()<"answer is {:#X}">(SV("answer is 0X0"), false);
517 
518   // *** zero-padding & width ***
519   check.template operator()<"answer is {:+#012d}">(SV("answer is +00000000001"), true);
520   check.template operator()<"answer is {:+012b}">(SV("answer is +00000000001"), true);
521   check.template operator()<"answer is {:+#012b}">(SV("answer is +0b000000001"), true);
522   check.template operator()<"answer is {:+#012B}">(SV("answer is +0B000000001"), true);
523   check.template operator()<"answer is {:+012o}">(SV("answer is +00000000001"), true);
524   check.template operator()<"answer is {:+#012o}">(SV("answer is +00000000001"), true);
525   check.template operator()<"answer is {:+012x}">(SV("answer is +00000000001"), true);
526   check.template operator()<"answer is {:+#012x}">(SV("answer is +0x000000001"), true);
527   check.template operator()<"answer is {:+012X}">(SV("answer is +00000000001"), true);
528   check.template operator()<"answer is {:+#012X}">(SV("answer is +0X000000001"), true);
529 
530   check.template operator()<"answer is {:#012d}">(SV("answer is 000000000000"), false);
531   check.template operator()<"answer is {:012b}">(SV("answer is 000000000000"), false);
532   check.template operator()<"answer is {:#012b}">(SV("answer is 0b0000000000"), false);
533   check.template operator()<"answer is {:#012B}">(SV("answer is 0B0000000000"), false);
534   check.template operator()<"answer is {:012o}">(SV("answer is 000000000000"), false);
535   check.template operator()<"answer is {:#012o}">(SV("answer is 000000000000"), false);
536   check.template operator()<"answer is {:012x}">(SV("answer is 000000000000"), false);
537   check.template operator()<"answer is {:#012x}">(SV("answer is 0x0000000000"), false);
538   check.template operator()<"answer is {:012X}">(SV("answer is 000000000000"), false);
539   check.template operator()<"answer is {:#012X}">(SV("answer is 0X0000000000"), false);
540 
541   // *** precision ***
542   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.}"), true);
543   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0}"), true);
544   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42}"), true);
545 
546   // *** locale-specific form ***
547   // See locale-specific_form.pass.cpp
548 
549   // *** type ***
550   for (const auto& fmt : invalid_types<CharT>("bBcdosxX"))
551     check_exception("The format-spec type has a type not supported for a bool argument", fmt, true);
552 }
553 
554 template <class I, class CharT, class TestFunction, class ExceptionTest>
555 void format_test_integer_as_integer(TestFunction check, ExceptionTest check_exception) {
556   // *** align-fill & width ***
557   check.template operator()<"answer is '{:<1}'">(SV("answer is '42'"), I(42));
558   check.template operator()<"answer is '{:<2}'">(SV("answer is '42'"), I(42));
559   check.template operator()<"answer is '{:<3}'">(SV("answer is '42 '"), I(42));
560 
561   check.template operator()<"answer is '{:7}'">(SV("answer is '     42'"), I(42));
562   check.template operator()<"answer is '{:>7}'">(SV("answer is '     42'"), I(42));
563   check.template operator()<"answer is '{:<7}'">(SV("answer is '42     '"), I(42));
564   check.template operator()<"answer is '{:^7}'">(SV("answer is '  42   '"), I(42));
565 
566   check.template operator()<"answer is '{:*>7}'">(SV("answer is '*****42'"), I(42));
567   check.template operator()<"answer is '{:*<7}'">(SV("answer is '42*****'"), I(42));
568   check.template operator()<"answer is '{:*^7}'">(SV("answer is '**42***'"), I(42));
569 
570   // Test whether zero padding is ignored
571   check.template operator()<"answer is '{:>07}'">(SV("answer is '     42'"), I(42));
572   check.template operator()<"answer is '{:<07}'">(SV("answer is '42     '"), I(42));
573   check.template operator()<"answer is '{:^07}'">(SV("answer is '  42   '"), I(42));
574 
575   // *** Sign ***
576   if constexpr (std::signed_integral<I>)
577     check.template operator()<"answer is {}">(SV("answer is -42"), I(-42));
578   check.template operator()<"answer is {}">(SV("answer is 0"), I(0));
579   check.template operator()<"answer is {}">(SV("answer is 42"), I(42));
580 
581   if constexpr (std::signed_integral<I>)
582     check.template operator()<"answer is {:-}">(SV("answer is -42"), I(-42));
583   check.template operator()<"answer is {:-}">(SV("answer is 0"), I(0));
584   check.template operator()<"answer is {:-}">(SV("answer is 42"), I(42));
585 
586   if constexpr (std::signed_integral<I>)
587     check.template operator()<"answer is {:+}">(SV("answer is -42"), I(-42));
588   check.template operator()<"answer is {:+}">(SV("answer is +0"), I(0));
589   check.template operator()<"answer is {:+}">(SV("answer is +42"), I(42));
590 
591   if constexpr (std::signed_integral<I>)
592     check.template operator()<"answer is {: }">(SV("answer is -42"), I(-42));
593   check.template operator()<"answer is {: }">(SV("answer is  0"), I(0));
594   check.template operator()<"answer is {: }">(SV("answer is  42"), I(42));
595 
596   // *** alternate form ***
597   if constexpr (std::signed_integral<I>) {
598     check.template operator()<"answer is {:#}">(SV("answer is -42"), I(-42));
599     check.template operator()<"answer is {:#d}">(SV("answer is -42"), I(-42));
600     check.template operator()<"answer is {:b}">(SV("answer is -101010"), I(-42));
601     check.template operator()<"answer is {:#b}">(SV("answer is -0b101010"), I(-42));
602     check.template operator()<"answer is {:#B}">(SV("answer is -0B101010"), I(-42));
603     check.template operator()<"answer is {:o}">(SV("answer is -52"), I(-42));
604     check.template operator()<"answer is {:#o}">(SV("answer is -052"), I(-42));
605     check.template operator()<"answer is {:x}">(SV("answer is -2a"), I(-42));
606     check.template operator()<"answer is {:#x}">(SV("answer is -0x2a"), I(-42));
607     check.template operator()<"answer is {:X}">(SV("answer is -2A"), I(-42));
608     check.template operator()<"answer is {:#X}">(SV("answer is -0X2A"), I(-42));
609   }
610   check.template operator()<"answer is {:#}">(SV("answer is 0"), I(0));
611   check.template operator()<"answer is {:#d}">(SV("answer is 0"), I(0));
612   check.template operator()<"answer is {:b}">(SV("answer is 0"), I(0));
613   check.template operator()<"answer is {:#b}">(SV("answer is 0b0"), I(0));
614   check.template operator()<"answer is {:#B}">(SV("answer is 0B0"), I(0));
615   check.template operator()<"answer is {:o}">(SV("answer is 0"), I(0));
616   check.template operator()<"answer is {:#o}">(SV("answer is 0"), I(0));
617   check.template operator()<"answer is {:x}">(SV("answer is 0"), I(0));
618   check.template operator()<"answer is {:#x}">(SV("answer is 0x0"), I(0));
619   check.template operator()<"answer is {:X}">(SV("answer is 0"), I(0));
620   check.template operator()<"answer is {:#X}">(SV("answer is 0X0"), I(0));
621 
622   check.template operator()<"answer is {:+#}">(SV("answer is +42"), I(42));
623   check.template operator()<"answer is {:+#d}">(SV("answer is +42"), I(42));
624   check.template operator()<"answer is {:+b}">(SV("answer is +101010"), I(42));
625   check.template operator()<"answer is {:+#b}">(SV("answer is +0b101010"), I(42));
626   check.template operator()<"answer is {:+#B}">(SV("answer is +0B101010"), I(42));
627   check.template operator()<"answer is {:+o}">(SV("answer is +52"), I(42));
628   check.template operator()<"answer is {:+#o}">(SV("answer is +052"), I(42));
629   check.template operator()<"answer is {:+x}">(SV("answer is +2a"), I(42));
630   check.template operator()<"answer is {:+#x}">(SV("answer is +0x2a"), I(42));
631   check.template operator()<"answer is {:+X}">(SV("answer is +2A"), I(42));
632   check.template operator()<"answer is {:+#X}">(SV("answer is +0X2A"), I(42));
633 
634   // *** zero-padding & width ***
635   if constexpr (std::signed_integral<I>) {
636     check.template operator()<"answer is {:#012}">(SV("answer is -00000000042"), I(-42));
637     check.template operator()<"answer is {:#012d}">(SV("answer is -00000000042"), I(-42));
638     check.template operator()<"answer is {:012b}">(SV("answer is -00000101010"), I(-42));
639     check.template operator()<"answer is {:#012b}">(SV("answer is -0b000101010"), I(-42));
640     check.template operator()<"answer is {:#012B}">(SV("answer is -0B000101010"), I(-42));
641     check.template operator()<"answer is {:012o}">(SV("answer is -00000000052"), I(-42));
642     check.template operator()<"answer is {:#012o}">(SV("answer is -00000000052"), I(-42));
643     check.template operator()<"answer is {:012x}">(SV("answer is -0000000002a"), I(-42));
644     check.template operator()<"answer is {:#012x}">(SV("answer is -0x00000002a"), I(-42));
645     check.template operator()<"answer is {:012X}">(SV("answer is -0000000002A"), I(-42));
646     check.template operator()<"answer is {:#012X}">(SV("answer is -0X00000002A"), I(-42));
647   }
648 
649   check.template operator()<"answer is {:#012}">(SV("answer is 000000000000"), I(0));
650   check.template operator()<"answer is {:#012d}">(SV("answer is 000000000000"), I(0));
651   check.template operator()<"answer is {:012b}">(SV("answer is 000000000000"), I(0));
652   check.template operator()<"answer is {:#012b}">(SV("answer is 0b0000000000"), I(0));
653   check.template operator()<"answer is {:#012B}">(SV("answer is 0B0000000000"), I(0));
654   check.template operator()<"answer is {:012o}">(SV("answer is 000000000000"), I(0));
655   check.template operator()<"answer is {:#012o}">(SV("answer is 000000000000"), I(0));
656   check.template operator()<"answer is {:012x}">(SV("answer is 000000000000"), I(0));
657   check.template operator()<"answer is {:#012x}">(SV("answer is 0x0000000000"), I(0));
658   check.template operator()<"answer is {:012X}">(SV("answer is 000000000000"), I(0));
659   check.template operator()<"answer is {:#012X}">(SV("answer is 0X0000000000"), I(0));
660 
661   check.template operator()<"answer is {:+#012}">(SV("answer is +00000000042"), I(42));
662   check.template operator()<"answer is {:+#012d}">(SV("answer is +00000000042"), I(42));
663   check.template operator()<"answer is {:+012b}">(SV("answer is +00000101010"), I(42));
664   check.template operator()<"answer is {:+#012b}">(SV("answer is +0b000101010"), I(42));
665   check.template operator()<"answer is {:+#012B}">(SV("answer is +0B000101010"), I(42));
666   check.template operator()<"answer is {:+012o}">(SV("answer is +00000000052"), I(42));
667   check.template operator()<"answer is {:+#012o}">(SV("answer is +00000000052"), I(42));
668   check.template operator()<"answer is {:+012x}">(SV("answer is +0000000002a"), I(42));
669   check.template operator()<"answer is {:+#012x}">(SV("answer is +0x00000002a"), I(42));
670   check.template operator()<"answer is {:+012X}">(SV("answer is +0000000002A"), I(42));
671   check.template operator()<"answer is {:+#012X}">(SV("answer is +0X00000002A"), I(42));
672 
673   // *** precision ***
674   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.}"), I(0));
675   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0}"), I(0));
676   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42}"), I(0));
677 
678   // *** locale-specific form ***
679   // See locale-specific_form.pass.cpp
680 
681   // *** type ***
682   for (const auto& fmt : invalid_types<CharT>("bBcdoxX"))
683     check_exception("The format-spec type has a type not supported for an integer argument", fmt, 42);
684 }
685 
686 template <class I, class CharT, class TestFunction, class ExceptionTest>
687 void format_test_integer_as_char(TestFunction check, ExceptionTest check_exception) {
688   // *** align-fill & width ***
689   check.template operator()<"answer is '{:6c}'">(SV("answer is '*     '"), I(42));
690   check.template operator()<"answer is '{:>6c}'">(SV("answer is '     *'"), I(42));
691   check.template operator()<"answer is '{:<6c}'">(SV("answer is '*     '"), I(42));
692   check.template operator()<"answer is '{:^6c}'">(SV("answer is '  *   '"), I(42));
693 
694   check.template operator()<"answer is '{:->6c}'">(SV("answer is '-----*'"), I(42));
695   check.template operator()<"answer is '{:-<6c}'">(SV("answer is '*-----'"), I(42));
696   check.template operator()<"answer is '{:-^6c}'">(SV("answer is '--*---'"), I(42));
697 
698   // *** Sign ***
699   check.template operator()<"answer is {:c}">(SV("answer is *"), I(42));
700   check_exception("A sign field isn't allowed in this format-spec", SV("answer is {:-c}"), I(42));
701   check_exception("A sign field isn't allowed in this format-spec", SV("answer is {:+c}"), I(42));
702   check_exception("A sign field isn't allowed in this format-spec", SV("answer is {: c}"), I(42));
703 
704   // *** alternate form ***
705   check_exception("An alternate form field isn't allowed in this format-spec", SV("answer is {:#c}"), I(42));
706 
707   // *** zero-padding & width ***
708   check_exception("A zero-padding field isn't allowed in this format-spec", SV("answer is {:01c}"), I(42));
709 
710   // *** precision ***
711   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.c}"), I(0));
712   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0c}"), I(0));
713   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42c}"), I(0));
714 
715   // *** locale-specific form ***
716   // Note it has no effect but it's allowed.
717   check.template operator()<"answer is '{:Lc}'">(SV("answer is '*'"), I(42));
718 
719   // *** type ***
720   for (const auto& fmt : invalid_types<CharT>("bBcdoxX"))
721     check_exception("The format-spec type has a type not supported for an integer argument", fmt, I(42));
722 
723   // *** Validate range ***
724   // The code has some duplications to keep the if statement readable.
725   if constexpr (std::signed_integral<CharT>) {
726     if constexpr (std::signed_integral<I> && sizeof(I) > sizeof(CharT)) {
727       check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::min());
728       check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max());
729     } else if constexpr (std::unsigned_integral<I> && sizeof(I) >= sizeof(CharT)) {
730       check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max());
731     }
732   } else if constexpr (sizeof(I) > sizeof(CharT)) {
733     check_exception("Integral value outside the range of the char type", SV("{:c}"), std::numeric_limits<I>::max());
734   }
735 }
736 
737 template <class I, class CharT, class TestFunction, class ExceptionTest>
738 void format_test_integer(TestFunction check, ExceptionTest check_exception) {
739   format_test_integer_as_integer<I, CharT>(check, check_exception);
740   format_test_integer_as_char<I, CharT>(check, check_exception);
741 }
742 
743 template <class CharT, class TestFunction, class ExceptionTest>
744 void format_test_signed_integer(TestFunction check, ExceptionTest check_exception) {
745   format_test_integer<signed char, CharT>(check, check_exception);
746   format_test_integer<short, CharT>(check, check_exception);
747   format_test_integer<int, CharT>(check, check_exception);
748   format_test_integer<long, CharT>(check, check_exception);
749   format_test_integer<long long, CharT>(check, check_exception);
750 #ifndef TEST_HAS_NO_INT128
751   format_test_integer<__int128_t, CharT>(check, check_exception);
752 #endif
753   // *** check the minma and maxima ***
754   check.template operator()<"{:#b}">(SV("-0b10000000"), std::numeric_limits<int8_t>::min());
755   check.template operator()<"{:#o}">(SV("-0200"), std::numeric_limits<int8_t>::min());
756   check.template operator()<"{:#}">(SV("-128"), std::numeric_limits<int8_t>::min());
757   check.template operator()<"{:#x}">(SV("-0x80"), std::numeric_limits<int8_t>::min());
758 
759   check.template operator()<"{:#b}">(SV("-0b1000000000000000"), std::numeric_limits<int16_t>::min());
760   check.template operator()<"{:#o}">(SV("-0100000"), std::numeric_limits<int16_t>::min());
761   check.template operator()<"{:#}">(SV("-32768"), std::numeric_limits<int16_t>::min());
762   check.template operator()<"{:#x}">(SV("-0x8000"), std::numeric_limits<int16_t>::min());
763 
764   check.template operator()<"{:#b}">(SV("-0b10000000000000000000000000000000"), std::numeric_limits<int32_t>::min());
765   check.template operator()<"{:#o}">(SV("-020000000000"), std::numeric_limits<int32_t>::min());
766   check.template operator()<"{:#}">(SV("-2147483648"), std::numeric_limits<int32_t>::min());
767   check.template operator()<"{:#x}">(SV("-0x80000000"), std::numeric_limits<int32_t>::min());
768 
769   check.template operator()<"{:#b}">(SV("-0b1000000000000000000000000000000000000000000000000000000000000000"),
770                                      std::numeric_limits<int64_t>::min());
771   check.template operator()<"{:#o}">(SV("-01000000000000000000000"), std::numeric_limits<int64_t>::min());
772   check.template operator()<"{:#}">(SV("-9223372036854775808"), std::numeric_limits<int64_t>::min());
773   check.template operator()<"{:#x}">(SV("-0x8000000000000000"), std::numeric_limits<int64_t>::min());
774 
775 #ifndef TEST_HAS_NO_INT128
776   check.template operator()<"{:#b}">(
777       SV("-0b1000000000000000000000000000000000000000000000000000000000000000"
778          "0000000000000000000000000000000000000000000000000000000000000000"),
779       std::numeric_limits<__int128_t>::min());
780   check.template
781   operator()<"{:#o}">(SV("-02000000000000000000000000000000000000000000"), std::numeric_limits<__int128_t>::min());
782   check.template
783   operator()<"{:#}">(SV("-170141183460469231731687303715884105728"), std::numeric_limits<__int128_t>::min());
784   check.template operator()<"{:#x}">(SV("-0x80000000000000000000000000000000"), std::numeric_limits<__int128_t>::min());
785 #endif
786 
787   check.template operator()<"{:#b}">(SV("0b1111111"), std::numeric_limits<int8_t>::max());
788   check.template operator()<"{:#o}">(SV("0177"), std::numeric_limits<int8_t>::max());
789   check.template operator()<"{:#}">(SV("127"), std::numeric_limits<int8_t>::max());
790   check.template operator()<"{:#x}">(SV("0x7f"), std::numeric_limits<int8_t>::max());
791 
792   check.template operator()<"{:#b}">(SV("0b111111111111111"), std::numeric_limits<int16_t>::max());
793   check.template operator()<"{:#o}">(SV("077777"), std::numeric_limits<int16_t>::max());
794   check.template operator()<"{:#}">(SV("32767"), std::numeric_limits<int16_t>::max());
795   check.template operator()<"{:#x}">(SV("0x7fff"), std::numeric_limits<int16_t>::max());
796 
797   check.template operator()<"{:#b}">(SV("0b1111111111111111111111111111111"), std::numeric_limits<int32_t>::max());
798   check.template operator()<"{:#o}">(SV("017777777777"), std::numeric_limits<int32_t>::max());
799   check.template operator()<"{:#}">(SV("2147483647"), std::numeric_limits<int32_t>::max());
800   check.template operator()<"{:#x}">(SV("0x7fffffff"), std::numeric_limits<int32_t>::max());
801 
802   check.template operator()<"{:#b}">(SV("0b111111111111111111111111111111111111111111111111111111111111111"),
803                                      std::numeric_limits<int64_t>::max());
804   check.template operator()<"{:#o}">(SV("0777777777777777777777"), std::numeric_limits<int64_t>::max());
805   check.template operator()<"{:#}">(SV("9223372036854775807"), std::numeric_limits<int64_t>::max());
806   check.template operator()<"{:#x}">(SV("0x7fffffffffffffff"), std::numeric_limits<int64_t>::max());
807 
808 #ifndef TEST_HAS_NO_INT128
809   check.template operator()<"{:#b}">(
810       SV("0b111111111111111111111111111111111111111111111111111111111111111"
811          "1111111111111111111111111111111111111111111111111111111111111111"),
812       std::numeric_limits<__int128_t>::max());
813   check.template
814   operator()<"{:#o}">(SV("01777777777777777777777777777777777777777777"), std::numeric_limits<__int128_t>::max());
815   check.template
816   operator()<"{:#}">(SV("170141183460469231731687303715884105727"), std::numeric_limits<__int128_t>::max());
817   check.template operator()<"{:#x}">(SV("0x7fffffffffffffffffffffffffffffff"), std::numeric_limits<__int128_t>::max());
818 #endif
819 }
820 
821 template <class CharT, class TestFunction, class ExceptionTest>
822 void format_test_unsigned_integer(TestFunction check, ExceptionTest check_exception) {
823   format_test_integer<unsigned char, CharT>(check, check_exception);
824   format_test_integer<unsigned short, CharT>(check, check_exception);
825   format_test_integer<unsigned, CharT>(check, check_exception);
826   format_test_integer<unsigned long, CharT>(check, check_exception);
827   format_test_integer<unsigned long long, CharT>(check, check_exception);
828 #ifndef TEST_HAS_NO_INT128
829   format_test_integer<__uint128_t, CharT>(check, check_exception);
830 #endif
831   // *** test the maxima ***
832   check.template operator()<"{:#b}">(SV("0b11111111"), std::numeric_limits<uint8_t>::max());
833   check.template operator()<"{:#o}">(SV("0377"), std::numeric_limits<uint8_t>::max());
834   check.template operator()<"{:#}">(SV("255"), std::numeric_limits<uint8_t>::max());
835   check.template operator()<"{:#x}">(SV("0xff"), std::numeric_limits<uint8_t>::max());
836 
837   check.template operator()<"{:#b}">(SV("0b1111111111111111"), std::numeric_limits<uint16_t>::max());
838   check.template operator()<"{:#o}">(SV("0177777"), std::numeric_limits<uint16_t>::max());
839   check.template operator()<"{:#}">(SV("65535"), std::numeric_limits<uint16_t>::max());
840   check.template operator()<"{:#x}">(SV("0xffff"), std::numeric_limits<uint16_t>::max());
841 
842   check.template operator()<"{:#b}">(SV("0b11111111111111111111111111111111"), std::numeric_limits<uint32_t>::max());
843   check.template operator()<"{:#o}">(SV("037777777777"), std::numeric_limits<uint32_t>::max());
844   check.template operator()<"{:#}">(SV("4294967295"), std::numeric_limits<uint32_t>::max());
845   check.template operator()<"{:#x}">(SV("0xffffffff"), std::numeric_limits<uint32_t>::max());
846 
847   check.template operator()<"{:#b}">(SV("0b1111111111111111111111111111111111111111111111111111111111111111"),
848                                      std::numeric_limits<uint64_t>::max());
849   check.template operator()<"{:#o}">(SV("01777777777777777777777"), std::numeric_limits<uint64_t>::max());
850   check.template operator()<"{:#}">(SV("18446744073709551615"), std::numeric_limits<uint64_t>::max());
851   check.template operator()<"{:#x}">(SV("0xffffffffffffffff"), std::numeric_limits<uint64_t>::max());
852 
853 #ifndef TEST_HAS_NO_INT128
854   check.template operator()<"{:#b}">(
855       SV("0b1111111111111111111111111111111111111111111111111111111111111111"
856          "1111111111111111111111111111111111111111111111111111111111111111"),
857       std::numeric_limits<__uint128_t>::max());
858   check.template
859   operator()<"{:#o}">(SV("03777777777777777777777777777777777777777777"), std::numeric_limits<__uint128_t>::max());
860   check.template
861   operator()<"{:#}">(SV("340282366920938463463374607431768211455"), std::numeric_limits<__uint128_t>::max());
862   check.template operator()<"{:#x}">(SV("0xffffffffffffffffffffffffffffffff"), std::numeric_limits<__uint128_t>::max());
863 #endif
864 }
865 
866 template <class CharT, class TestFunction, class ExceptionTest>
867 void format_test_char(TestFunction check, ExceptionTest check_exception) {
868 
869   // ***** Char type *****
870   // *** align-fill & width ***
871   check.template operator()<"answer is '{:6}'">(SV("answer is '*     '"), CharT('*'));
872 
873   check.template operator()<"answer is '{:>6}'">(SV("answer is '     *'"), CharT('*'));
874   check.template operator()<"answer is '{:<6}'">(SV("answer is '*     '"), CharT('*'));
875   check.template operator()<"answer is '{:^6}'">(SV("answer is '  *   '"), CharT('*'));
876 
877   check.template operator()<"answer is '{:6c}'">(SV("answer is '*     '"), CharT('*'));
878   check.template operator()<"answer is '{:>6c}'">(SV("answer is '     *'"), CharT('*'));
879   check.template operator()<"answer is '{:<6c}'">(SV("answer is '*     '"), CharT('*'));
880   check.template operator()<"answer is '{:^6c}'">(SV("answer is '  *   '"), CharT('*'));
881 
882   check.template operator()<"answer is '{:->6}'">(SV("answer is '-----*'"), CharT('*'));
883   check.template operator()<"answer is '{:-<6}'">(SV("answer is '*-----'"), CharT('*'));
884   check.template operator()<"answer is '{:-^6}'">(SV("answer is '--*---'"), CharT('*'));
885 
886   check.template operator()<"answer is '{:->6c}'">(SV("answer is '-----*'"), CharT('*'));
887   check.template operator()<"answer is '{:-<6c}'">(SV("answer is '*-----'"), CharT('*'));
888   check.template operator()<"answer is '{:-^6c}'">(SV("answer is '--*---'"), CharT('*'));
889 
890   // *** Sign ***
891   check_exception("A sign field isn't allowed in this format-spec", SV("{:-}"), CharT('*'));
892   check_exception("A sign field isn't allowed in this format-spec", SV("{:+}"), CharT('*'));
893   check_exception("A sign field isn't allowed in this format-spec", SV("{: }"), CharT('*'));
894 
895   check_exception("A sign field isn't allowed in this format-spec", SV("{:-c}"), CharT('*'));
896   check_exception("A sign field isn't allowed in this format-spec", SV("{:+c}"), CharT('*'));
897   check_exception("A sign field isn't allowed in this format-spec", SV("{: c}"), CharT('*'));
898 
899   // *** alternate form ***
900   check_exception("An alternate form field isn't allowed in this format-spec", SV("{:#}"), CharT('*'));
901   check_exception("An alternate form field isn't allowed in this format-spec", SV("{:#c}"), CharT('*'));
902 
903   // *** zero-padding ***
904   check_exception("A zero-padding field isn't allowed in this format-spec", SV("{:0}"), CharT('*'));
905   check_exception("A zero-padding field isn't allowed in this format-spec", SV("{:0c}"), CharT('*'));
906 
907   // *** precision ***
908   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.}"), CharT('*'));
909   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0}"), CharT('*'));
910   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42}"), CharT('*'));
911 
912   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.c}"), CharT('*'));
913   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0c}"), CharT('*'));
914   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42c}"), CharT('*'));
915 
916   // *** locale-specific form ***
917   // Note it has no effect but it's allowed.
918   check.template operator()<"answer is '{:L}'">(SV("answer is '*'"), '*');
919   check.template operator()<"answer is '{:Lc}'">(SV("answer is '*'"), '*');
920 
921   // *** type ***
922   for (const auto& fmt : invalid_types<CharT>("bBcdoxX"))
923     check_exception("The format-spec type has a type not supported for a char argument", fmt, CharT('*'));
924 }
925 
926 template <class CharT, class TestFunction, class ExceptionTest>
927 void format_test_char_as_integer(TestFunction check, ExceptionTest check_exception) {
928   // *** align-fill & width ***
929   check.template operator()<"answer is '{:<1d}'">(SV("answer is '42'"), CharT('*'));
930 
931   check.template operator()<"answer is '{:<2d}'">(SV("answer is '42'"), CharT('*'));
932   check.template operator()<"answer is '{:<3d}'">(SV("answer is '42 '"), CharT('*'));
933 
934   check.template operator()<"answer is '{:7d}'">(SV("answer is '     42'"), CharT('*'));
935   check.template operator()<"answer is '{:>7d}'">(SV("answer is '     42'"), CharT('*'));
936   check.template operator()<"answer is '{:<7d}'">(SV("answer is '42     '"), CharT('*'));
937   check.template operator()<"answer is '{:^7d}'">(SV("answer is '  42   '"), CharT('*'));
938 
939   check.template operator()<"answer is '{:*>7d}'">(SV("answer is '*****42'"), CharT('*'));
940   check.template operator()<"answer is '{:*<7d}'">(SV("answer is '42*****'"), CharT('*'));
941   check.template operator()<"answer is '{:*^7d}'">(SV("answer is '**42***'"), CharT('*'));
942 
943   // Test whether zero padding is ignored
944   check.template operator()<"answer is '{:>07d}'">(SV("answer is '     42'"), CharT('*'));
945   check.template operator()<"answer is '{:<07d}'">(SV("answer is '42     '"), CharT('*'));
946   check.template operator()<"answer is '{:^07d}'">(SV("answer is '  42   '"), CharT('*'));
947 
948   // *** Sign ***
949   check.template operator()<"answer is {:d}">(SV("answer is 42"), CharT('*'));
950   check.template operator()<"answer is {:-d}">(SV("answer is 42"), CharT('*'));
951   check.template operator()<"answer is {:+d}">(SV("answer is +42"), CharT('*'));
952   check.template operator()<"answer is {: d}">(SV("answer is  42"), CharT('*'));
953 
954   // *** alternate form ***
955   check.template operator()<"answer is {:+#d}">(SV("answer is +42"), CharT('*'));
956   check.template operator()<"answer is {:+b}">(SV("answer is +101010"), CharT('*'));
957   check.template operator()<"answer is {:+#b}">(SV("answer is +0b101010"), CharT('*'));
958   check.template operator()<"answer is {:+#B}">(SV("answer is +0B101010"), CharT('*'));
959   check.template operator()<"answer is {:+o}">(SV("answer is +52"), CharT('*'));
960   check.template operator()<"answer is {:+#o}">(SV("answer is +052"), CharT('*'));
961   check.template operator()<"answer is {:+x}">(SV("answer is +2a"), CharT('*'));
962   check.template operator()<"answer is {:+#x}">(SV("answer is +0x2a"), CharT('*'));
963   check.template operator()<"answer is {:+X}">(SV("answer is +2A"), CharT('*'));
964   check.template operator()<"answer is {:+#X}">(SV("answer is +0X2A"), CharT('*'));
965 
966   // *** zero-padding & width ***
967   check.template operator()<"answer is {:+#012d}">(SV("answer is +00000000042"), CharT('*'));
968   check.template operator()<"answer is {:+012b}">(SV("answer is +00000101010"), CharT('*'));
969   check.template operator()<"answer is {:+#012b}">(SV("answer is +0b000101010"), CharT('*'));
970   check.template operator()<"answer is {:+#012B}">(SV("answer is +0B000101010"), CharT('*'));
971   check.template operator()<"answer is {:+012o}">(SV("answer is +00000000052"), CharT('*'));
972   check.template operator()<"answer is {:+#012o}">(SV("answer is +00000000052"), CharT('*'));
973   check.template operator()<"answer is {:+012x}">(SV("answer is +0000000002a"), CharT('*'));
974   check.template operator()<"answer is {:+#012x}">(SV("answer is +0x00000002a"), CharT('*'));
975   check.template operator()<"answer is {:+012X}">(SV("answer is +0000000002A"), CharT('*'));
976 
977   check.template operator()<"answer is {:+#012X}">(SV("answer is +0X00000002A"), CharT('*'));
978 
979   // *** precision ***
980   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.d}"), CharT('*'));
981   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.0d}"), CharT('*'));
982   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.42d}"), CharT('*'));
983 
984   // *** locale-specific form ***
985   // See locale-specific_form.pass.cpp
986 
987   // *** type ***
988   for (const auto& fmt : invalid_types<CharT>("bBcdoxX"))
989     check_exception("The format-spec type has a type not supported for a char argument", fmt, '*');
990 }
991 
992 template <class F, class CharT, class TestFunction>
993 void format_test_floating_point_hex_lower_case(TestFunction check) {
994   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
995   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
996 
997   // Test whether the hexadecimal letters are the proper case.
998   // The precision is too large for float, so two tests are used.
999   check.template operator()<"answer is '{:a}'">(SV("answer is '1.abcp+0'"), F(0x1.abcp+0));
1000   check.template operator()<"answer is '{:a}'">(SV("answer is '1.defp+0'"), F(0x1.defp+0));
1001 
1002   // *** align-fill & width ***
1003   check.template operator()<"answer is '{:7a}'">(SV("answer is '   1p-2'"), F(0.25));
1004   check.template operator()<"answer is '{:>7a}'">(SV("answer is '   1p-2'"), F(0.25));
1005   check.template operator()<"answer is '{:<7a}'">(SV("answer is '1p-2   '"), F(0.25));
1006   check.template operator()<"answer is '{:^7a}'">(SV("answer is ' 1p-2  '"), F(0.25));
1007 
1008   check.template operator()<"answer is '{:->7a}'">(SV("answer is '---1p-3'"), F(125e-3));
1009   check.template operator()<"answer is '{:-<7a}'">(SV("answer is '1p-3---'"), F(125e-3));
1010   check.template operator()<"answer is '{:-^7a}'">(SV("answer is '-1p-3--'"), F(125e-3));
1011 
1012   check.template operator()<"answer is '{:*>6a}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
1013   check.template operator()<"answer is '{:*<6a}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
1014   check.template operator()<"answer is '{:*^6a}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
1015 
1016   check.template operator()<"answer is '{:#>7a}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
1017   check.template operator()<"answer is '{:#<7a}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
1018   check.template operator()<"answer is '{:#^7a}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
1019 
1020   check.template operator()<"answer is '{:^>6a}'">(SV("answer is '^^^nan'"), nan_pos);
1021   check.template operator()<"answer is '{:^<6a}'">(SV("answer is 'nan^^^'"), nan_pos);
1022   check.template operator()<"answer is '{:^^6a}'">(SV("answer is '^nan^^'"), nan_pos);
1023 
1024   check.template operator()<"answer is '{:0>7a}'">(SV("answer is '000-nan'"), nan_neg);
1025   check.template operator()<"answer is '{:0<7a}'">(SV("answer is '-nan000'"), nan_neg);
1026   check.template operator()<"answer is '{:0^7a}'">(SV("answer is '0-nan00'"), nan_neg);
1027 
1028   // Test whether zero padding is ignored
1029   check.template operator()<"answer is '{:>07a}'">(SV("answer is '   1p-2'"), F(0.25));
1030   check.template operator()<"answer is '{:<07a}'">(SV("answer is '1p-2   '"), F(0.25));
1031   check.template operator()<"answer is '{:^07a}'">(SV("answer is ' 1p-2  '"), F(0.25));
1032 
1033   // *** Sign ***
1034   check.template operator()<"answer is '{:a}'">(SV("answer is '0p+0'"), F(0));
1035   check.template operator()<"answer is '{:-a}'">(SV("answer is '0p+0'"), F(0));
1036   check.template operator()<"answer is '{:+a}'">(SV("answer is '+0p+0'"), F(0));
1037   check.template operator()<"answer is '{: a}'">(SV("answer is ' 0p+0'"), F(0));
1038 
1039   check.template operator()<"answer is '{:a}'">(SV("answer is '-0p+0'"), F(-0.));
1040   check.template operator()<"answer is '{:-a}'">(SV("answer is '-0p+0'"), F(-0.));
1041   check.template operator()<"answer is '{:+a}'">(SV("answer is '-0p+0'"), F(-0.));
1042   check.template operator()<"answer is '{: a}'">(SV("answer is '-0p+0'"), F(-0.));
1043 
1044   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1045   check.template operator()<"answer is '{:a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1046   check.template operator()<"answer is '{:-a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1047   check.template operator()<"answer is '{:+a}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
1048   check.template operator()<"answer is '{: a}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
1049 
1050   check.template operator()<"answer is '{:a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1051   check.template operator()<"answer is '{:-a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1052   check.template operator()<"answer is '{:+a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1053   check.template operator()<"answer is '{: a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1054 
1055   check.template operator()<"answer is '{:a}'">(SV("answer is 'nan'"), nan_pos);
1056   check.template operator()<"answer is '{:-a}'">(SV("answer is 'nan'"), nan_pos);
1057   check.template operator()<"answer is '{:+a}'">(SV("answer is '+nan'"), nan_pos);
1058   check.template operator()<"answer is '{: a}'">(SV("answer is ' nan'"), nan_pos);
1059 
1060   check.template operator()<"answer is '{:a}'">(SV("answer is '-nan'"), nan_neg);
1061   check.template operator()<"answer is '{:-a}'">(SV("answer is '-nan'"), nan_neg);
1062   check.template operator()<"answer is '{:+a}'">(SV("answer is '-nan'"), nan_neg);
1063   check.template operator()<"answer is '{: a}'">(SV("answer is '-nan'"), nan_neg);
1064 
1065   // *** alternate form ***
1066   // When precision is zero there's no decimal point except when the alternate form is specified.
1067   check.template operator()<"answer is '{:a}'">(SV("answer is '0p+0'"), F(0));
1068   check.template operator()<"answer is '{:#a}'">(SV("answer is '0.p+0'"), F(0));
1069 
1070   check.template operator()<"answer is '{:.0a}'">(SV("answer is '1p+1'"), F(2.5));
1071   check.template operator()<"answer is '{:#.0a}'">(SV("answer is '1.p+1'"), F(2.5));
1072   check.template operator()<"answer is '{:#a}'">(SV("answer is '1.4p+1'"), F(2.5));
1073 
1074   check.template operator()<"answer is '{:#a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1075   check.template operator()<"answer is '{:#a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1076 
1077   check.template operator()<"answer is '{:#a}'">(SV("answer is 'nan'"), nan_pos);
1078   check.template operator()<"answer is '{:#a}'">(SV("answer is '-nan'"), nan_neg);
1079 
1080   // *** zero-padding & width ***
1081   check.template operator()<"answer is '{:04a}'">(SV("answer is '1p-5'"), 0.03125);
1082   check.template operator()<"answer is '{:+05a}'">(SV("answer is '+1p-5'"), 0.03125);
1083   check.template operator()<"answer is '{:+06a}'">(SV("answer is '+01p-5'"), 0.03125);
1084 
1085   check.template operator()<"answer is '{:07a}'">(SV("answer is '0001p-5'"), 0.03125);
1086   check.template operator()<"answer is '{:-07a}'">(SV("answer is '0001p-5'"), 0.03125);
1087   check.template operator()<"answer is '{:+07a}'">(SV("answer is '+001p-5'"), 0.03125);
1088   check.template operator()<"answer is '{: 07a}'">(SV("answer is ' 001p-5'"), 0.03125);
1089 
1090   check.template operator()<"answer is '{:010a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1091   check.template operator()<"answer is '{:-010a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1092   check.template operator()<"answer is '{:+010a}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
1093   check.template operator()<"answer is '{: 010a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1094 
1095   check.template operator()<"answer is '{:010a}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1096   check.template operator()<"answer is '{:-010a}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1097   check.template operator()<"answer is '{:+010a}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1098   check.template operator()<"answer is '{: 010a}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1099 
1100   check.template operator()<"answer is '{:010a}'">(SV("answer is '       nan'"), nan_pos);
1101   check.template operator()<"answer is '{:-010a}'">(SV("answer is '       nan'"), nan_pos);
1102   check.template operator()<"answer is '{:+010a}'">(SV("answer is '      +nan'"), nan_pos);
1103   check.template operator()<"answer is '{: 010a}'">(SV("answer is '       nan'"), nan_pos);
1104 
1105   check.template operator()<"answer is '{:010a}'">(SV("answer is '      -nan'"), nan_neg);
1106   check.template operator()<"answer is '{:-010a}'">(SV("answer is '      -nan'"), nan_neg);
1107   check.template operator()<"answer is '{:+010a}'">(SV("answer is '      -nan'"), nan_neg);
1108   check.template operator()<"answer is '{: 010a}'">(SV("answer is '      -nan'"), nan_neg);
1109 
1110   // *** precision ***
1111   // See format_test_floating_point_hex_lower_case_precision
1112 
1113   // *** locale-specific form ***
1114   // See locale-specific_form.pass.cpp
1115 }
1116 
1117 template <class F, class CharT, class TestFunction>
1118 void format_test_floating_point_hex_upper_case(TestFunction check) {
1119   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1120   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1121 
1122   // Test whether the hexadecimal letters are the proper case.
1123   // The precision is too large for float, so two tests are used.
1124   check.template operator()<"answer is '{:A}'">(SV("answer is '1.ABCP+0'"), F(0x1.abcp+0));
1125   check.template operator()<"answer is '{:A}'">(SV("answer is '1.DEFP+0'"), F(0x1.defp+0));
1126 
1127   // *** align-fill & width ***
1128   check.template operator()<"answer is '{:7A}'">(SV("answer is '   1P-2'"), F(0.25));
1129   check.template operator()<"answer is '{:>7A}'">(SV("answer is '   1P-2'"), F(0.25));
1130   check.template operator()<"answer is '{:<7A}'">(SV("answer is '1P-2   '"), F(0.25));
1131   check.template operator()<"answer is '{:^7A}'">(SV("answer is ' 1P-2  '"), F(0.25));
1132 
1133   check.template operator()<"answer is '{:->7A}'">(SV("answer is '---1P-3'"), F(125e-3));
1134   check.template operator()<"answer is '{:-<7A}'">(SV("answer is '1P-3---'"), F(125e-3));
1135   check.template operator()<"answer is '{:-^7A}'">(SV("answer is '-1P-3--'"), F(125e-3));
1136 
1137   check.template operator()<"answer is '{:*>6A}'">(SV("answer is '***INF'"), std::numeric_limits<F>::infinity());
1138   check.template operator()<"answer is '{:*<6A}'">(SV("answer is 'INF***'"), std::numeric_limits<F>::infinity());
1139   check.template operator()<"answer is '{:*^6A}'">(SV("answer is '*INF**'"), std::numeric_limits<F>::infinity());
1140 
1141   check.template operator()<"answer is '{:#>7A}'">(SV("answer is '###-INF'"), -std::numeric_limits<F>::infinity());
1142   check.template operator()<"answer is '{:#<7A}'">(SV("answer is '-INF###'"), -std::numeric_limits<F>::infinity());
1143   check.template operator()<"answer is '{:#^7A}'">(SV("answer is '#-INF##'"), -std::numeric_limits<F>::infinity());
1144 
1145   check.template operator()<"answer is '{:^>6A}'">(SV("answer is '^^^NAN'"), nan_pos);
1146   check.template operator()<"answer is '{:^<6A}'">(SV("answer is 'NAN^^^'"), nan_pos);
1147   check.template operator()<"answer is '{:^^6A}'">(SV("answer is '^NAN^^'"), nan_pos);
1148 
1149   check.template operator()<"answer is '{:0>7A}'">(SV("answer is '000-NAN'"), nan_neg);
1150   check.template operator()<"answer is '{:0<7A}'">(SV("answer is '-NAN000'"), nan_neg);
1151   check.template operator()<"answer is '{:0^7A}'">(SV("answer is '0-NAN00'"), nan_neg);
1152 
1153   // Test whether zero padding is ignored
1154   check.template operator()<"answer is '{:>07A}'">(SV("answer is '   1P-2'"), F(0.25));
1155   check.template operator()<"answer is '{:<07A}'">(SV("answer is '1P-2   '"), F(0.25));
1156   check.template operator()<"answer is '{:^07A}'">(SV("answer is ' 1P-2  '"), F(0.25));
1157 
1158   // *** Sign ***
1159   check.template operator()<"answer is '{:A}'">(SV("answer is '0P+0'"), F(0));
1160   check.template operator()<"answer is '{:-A}'">(SV("answer is '0P+0'"), F(0));
1161   check.template operator()<"answer is '{:+A}'">(SV("answer is '+0P+0'"), F(0));
1162   check.template operator()<"answer is '{: A}'">(SV("answer is ' 0P+0'"), F(0));
1163 
1164   check.template operator()<"answer is '{:A}'">(SV("answer is '-0P+0'"), F(-0.));
1165   check.template operator()<"answer is '{:-A}'">(SV("answer is '-0P+0'"), F(-0.));
1166   check.template operator()<"answer is '{:+A}'">(SV("answer is '-0P+0'"), F(-0.));
1167   check.template operator()<"answer is '{: A}'">(SV("answer is '-0P+0'"), F(-0.));
1168 
1169   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1170   check.template operator()<"answer is '{:A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1171   check.template operator()<"answer is '{:-A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1172   check.template operator()<"answer is '{:+A}'">(SV("answer is '+INF'"), std::numeric_limits<F>::infinity());
1173   check.template operator()<"answer is '{: A}'">(SV("answer is ' INF'"), std::numeric_limits<F>::infinity());
1174 
1175   check.template operator()<"answer is '{:A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1176   check.template operator()<"answer is '{:-A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1177   check.template operator()<"answer is '{:+A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1178   check.template operator()<"answer is '{: A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1179 
1180   check.template operator()<"answer is '{:A}'">(SV("answer is 'NAN'"), nan_pos);
1181   check.template operator()<"answer is '{:-A}'">(SV("answer is 'NAN'"), nan_pos);
1182   check.template operator()<"answer is '{:+A}'">(SV("answer is '+NAN'"), nan_pos);
1183   check.template operator()<"answer is '{: A}'">(SV("answer is ' NAN'"), nan_pos);
1184 
1185   check.template operator()<"answer is '{:A}'">(SV("answer is '-NAN'"), nan_neg);
1186   check.template operator()<"answer is '{:-A}'">(SV("answer is '-NAN'"), nan_neg);
1187   check.template operator()<"answer is '{:+A}'">(SV("answer is '-NAN'"), nan_neg);
1188   check.template operator()<"answer is '{: A}'">(SV("answer is '-NAN'"), nan_neg);
1189 
1190   // *** alternate form ***
1191   // When precision is zero there's no decimal point except when the alternate form is specified.
1192   check.template operator()<"answer is '{:A}'">(SV("answer is '0P+0'"), F(0));
1193   check.template operator()<"answer is '{:#A}'">(SV("answer is '0.P+0'"), F(0));
1194 
1195   check.template operator()<"answer is '{:.0A}'">(SV("answer is '1P+1'"), F(2.5));
1196   check.template operator()<"answer is '{:#.0A}'">(SV("answer is '1.P+1'"), F(2.5));
1197   check.template operator()<"answer is '{:#A}'">(SV("answer is '1.4P+1'"), F(2.5));
1198 
1199   check.template operator()<"answer is '{:#A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1200   check.template operator()<"answer is '{:#A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1201 
1202   check.template operator()<"answer is '{:#A}'">(SV("answer is 'NAN'"), nan_pos);
1203   check.template operator()<"answer is '{:#A}'">(SV("answer is '-NAN'"), nan_neg);
1204 
1205   // *** zero-padding & width ***
1206   check.template operator()<"answer is '{:04A}'">(SV("answer is '1P-5'"), 0.03125);
1207   check.template operator()<"answer is '{:+05A}'">(SV("answer is '+1P-5'"), 0.03125);
1208   check.template operator()<"answer is '{:+06A}'">(SV("answer is '+01P-5'"), 0.03125);
1209 
1210   check.template operator()<"answer is '{:07A}'">(SV("answer is '0001P-5'"), 0.03125);
1211   check.template operator()<"answer is '{:-07A}'">(SV("answer is '0001P-5'"), 0.03125);
1212   check.template operator()<"answer is '{:+07A}'">(SV("answer is '+001P-5'"), 0.03125);
1213   check.template operator()<"answer is '{: 07A}'">(SV("answer is ' 001P-5'"), 0.03125);
1214 
1215   check.template operator()<"answer is '{:010A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1216   check.template operator()<"answer is '{:-010A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1217   check.template operator()<"answer is '{:+010A}'">(SV("answer is '      +INF'"), std::numeric_limits<F>::infinity());
1218   check.template operator()<"answer is '{: 010A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1219 
1220   check.template operator()<"answer is '{:010A}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1221   check.template operator()<"answer is '{:-010A}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1222   check.template operator()<"answer is '{:+010A}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1223   check.template operator()<"answer is '{: 010A}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1224 
1225   check.template operator()<"answer is '{:010A}'">(SV("answer is '       NAN'"), nan_pos);
1226   check.template operator()<"answer is '{:-010A}'">(SV("answer is '       NAN'"), nan_pos);
1227   check.template operator()<"answer is '{:+010A}'">(SV("answer is '      +NAN'"), nan_pos);
1228   check.template operator()<"answer is '{: 010A}'">(SV("answer is '       NAN'"), nan_pos);
1229 
1230   check.template operator()<"answer is '{:010A}'">(SV("answer is '      -NAN'"), nan_neg);
1231   check.template operator()<"answer is '{:-010A}'">(SV("answer is '      -NAN'"), nan_neg);
1232   check.template operator()<"answer is '{:+010A}'">(SV("answer is '      -NAN'"), nan_neg);
1233   check.template operator()<"answer is '{: 010A}'">(SV("answer is '      -NAN'"), nan_neg);
1234 
1235   // *** precision ***
1236   // See format_test_floating_point_hex_upper_case_precision
1237 
1238   // *** locale-specific form ***
1239   // See locale-specific_form.pass.cpp
1240 }
1241 
1242 template <class F, class CharT, class TestFunction>
1243 void format_test_floating_point_hex_lower_case_precision(TestFunction check) {
1244   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1245   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1246 
1247   // *** align-fill & width ***
1248   check.template operator()<"answer is '{:14.6a}'">(SV("answer is '   1.000000p-2'"), F(0.25));
1249   check.template operator()<"answer is '{:>14.6a}'">(SV("answer is '   1.000000p-2'"), F(0.25));
1250   check.template operator()<"answer is '{:<14.6a}'">(SV("answer is '1.000000p-2   '"), F(0.25));
1251   check.template operator()<"answer is '{:^14.6a}'">(SV("answer is ' 1.000000p-2  '"), F(0.25));
1252 
1253   check.template operator()<"answer is '{:->14.6a}'">(SV("answer is '---1.000000p-3'"), F(125e-3));
1254   check.template operator()<"answer is '{:-<14.6a}'">(SV("answer is '1.000000p-3---'"), F(125e-3));
1255   check.template operator()<"answer is '{:-^14.6a}'">(SV("answer is '-1.000000p-3--'"), F(125e-3));
1256 
1257   check.template operator()<"answer is '{:*>6.6a}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
1258   check.template operator()<"answer is '{:*<6.6a}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
1259   check.template operator()<"answer is '{:*^6.6a}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
1260 
1261   check.template operator()<"answer is '{:#>7.6a}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
1262   check.template operator()<"answer is '{:#<7.6a}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
1263   check.template operator()<"answer is '{:#^7.6a}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
1264 
1265   check.template operator()<"answer is '{:^>6.6a}'">(SV("answer is '^^^nan'"), nan_pos);
1266   check.template operator()<"answer is '{:^<6.6a}'">(SV("answer is 'nan^^^'"), nan_pos);
1267   check.template operator()<"answer is '{:^^6.6a}'">(SV("answer is '^nan^^'"), nan_pos);
1268 
1269   check.template operator()<"answer is '{:0>7.6a}'">(SV("answer is '000-nan'"), nan_neg);
1270   check.template operator()<"answer is '{:0<7.6a}'">(SV("answer is '-nan000'"), nan_neg);
1271   check.template operator()<"answer is '{:0^7.6a}'">(SV("answer is '0-nan00'"), nan_neg);
1272 
1273   // Test whether zero padding is ignored
1274   check.template operator()<"answer is '{:>014.6a}'">(SV("answer is '   1.000000p-2'"), F(0.25));
1275   check.template operator()<"answer is '{:<014.6a}'">(SV("answer is '1.000000p-2   '"), F(0.25));
1276   check.template operator()<"answer is '{:^014.6a}'">(SV("answer is ' 1.000000p-2  '"), F(0.25));
1277 
1278   // *** Sign ***
1279   check.template operator()<"answer is '{:.6a}'">(SV("answer is '0.000000p+0'"), F(0));
1280   check.template operator()<"answer is '{:-.6a}'">(SV("answer is '0.000000p+0'"), F(0));
1281   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '+0.000000p+0'"), F(0));
1282   check.template operator()<"answer is '{: .6a}'">(SV("answer is ' 0.000000p+0'"), F(0));
1283 
1284   check.template operator()<"answer is '{:.6a}'">(SV("answer is '-0.000000p+0'"), F(-0.));
1285   check.template operator()<"answer is '{:-.6a}'">(SV("answer is '-0.000000p+0'"), F(-0.));
1286   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '-0.000000p+0'"), F(-0.));
1287   check.template operator()<"answer is '{: .6a}'">(SV("answer is '-0.000000p+0'"), F(-0.));
1288 
1289   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1290   check.template operator()<"answer is '{:.6a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1291   check.template operator()<"answer is '{:-.6a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1292   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
1293   check.template operator()<"answer is '{: .6a}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
1294 
1295   check.template operator()<"answer is '{:.6a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1296   check.template operator()<"answer is '{:-.6a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1297   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1298   check.template operator()<"answer is '{: .6a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1299 
1300   check.template operator()<"answer is '{:.6a}'">(SV("answer is 'nan'"), nan_pos);
1301   check.template operator()<"answer is '{:-.6a}'">(SV("answer is 'nan'"), nan_pos);
1302   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '+nan'"), nan_pos);
1303   check.template operator()<"answer is '{: .6a}'">(SV("answer is ' nan'"), nan_pos);
1304 
1305   check.template operator()<"answer is '{:.6a}'">(SV("answer is '-nan'"), nan_neg);
1306   check.template operator()<"answer is '{:-.6a}'">(SV("answer is '-nan'"), nan_neg);
1307   check.template operator()<"answer is '{:+.6a}'">(SV("answer is '-nan'"), nan_neg);
1308   check.template operator()<"answer is '{: .6a}'">(SV("answer is '-nan'"), nan_neg);
1309 
1310   // *** alternate form ***
1311   check.template operator()<"answer is '{:#.6a}'">(SV("answer is '1.400000p+1'"), F(2.5));
1312 
1313   check.template operator()<"answer is '{:#.6a}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1314   check.template operator()<"answer is '{:#.6a}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1315 
1316   check.template operator()<"answer is '{:#.6a}'">(SV("answer is 'nan'"), nan_pos);
1317   check.template operator()<"answer is '{:#.6a}'">(SV("answer is '-nan'"), nan_neg);
1318 
1319   // *** zero-padding & width ***
1320   check.template operator()<"answer is '{:011.6a}'">(SV("answer is '1.000000p-5'"), 0.03125);
1321   check.template operator()<"answer is '{:+012.6a}'">(SV("answer is '+1.000000p-5'"), 0.03125);
1322   check.template operator()<"answer is '{:+013.6a}'">(SV("answer is '+01.000000p-5'"), 0.03125);
1323 
1324   check.template operator()<"answer is '{:014.6a}'">(SV("answer is '0001.000000p-5'"), 0.03125);
1325   check.template operator()<"answer is '{:-014.6a}'">(SV("answer is '0001.000000p-5'"), 0.03125);
1326   check.template operator()<"answer is '{:+014.6a}'">(SV("answer is '+001.000000p-5'"), 0.03125);
1327   check.template operator()<"answer is '{: 014.6a}'">(SV("answer is ' 001.000000p-5'"), 0.03125);
1328 
1329   check.template operator()<"answer is '{:010.6a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1330   check.template operator()<"answer is '{:-010.6a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1331   check.template operator()<"answer is '{:+010.6a}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
1332   check.template operator()<"answer is '{: 010.6a}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1333 
1334   check.template operator()<"answer is '{:010.6a}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1335   check.template operator()<"answer is '{:-010.6a}'">(SV("answer is '      -inf'"),
1336                                                       -std::numeric_limits<F>::infinity());
1337   check.template operator()<"answer is '{:+010.6a}'">(SV("answer is '      -inf'"),
1338                                                       -std::numeric_limits<F>::infinity());
1339   check.template operator()<"answer is '{: 010.6a}'">(SV("answer is '      -inf'"),
1340                                                       -std::numeric_limits<F>::infinity());
1341 
1342   check.template operator()<"answer is '{:010.6a}'">(SV("answer is '       nan'"), nan_pos);
1343   check.template operator()<"answer is '{:-010.6a}'">(SV("answer is '       nan'"), nan_pos);
1344   check.template operator()<"answer is '{:+010.6a}'">(SV("answer is '      +nan'"), nan_pos);
1345   check.template operator()<"answer is '{: 010.6a}'">(SV("answer is '       nan'"), nan_pos);
1346 
1347   check.template operator()<"answer is '{:010.6a}'">(SV("answer is '      -nan'"), nan_neg);
1348   check.template operator()<"answer is '{:-010.6a}'">(SV("answer is '      -nan'"), nan_neg);
1349   check.template operator()<"answer is '{:+010.6a}'">(SV("answer is '      -nan'"), nan_neg);
1350   check.template operator()<"answer is '{: 010.6a}'">(SV("answer is '      -nan'"), nan_neg);
1351 
1352   // *** locale-specific form ***
1353   // See locale-specific_form.pass.cpp
1354 }
1355 
1356 template <class F, class CharT, class TestFunction>
1357 void format_test_floating_point_hex_upper_case_precision(TestFunction check) {
1358   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1359   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1360 
1361   // *** align-fill & width ***
1362   check.template operator()<"answer is '{:14.6A}'">(SV("answer is '   1.000000P-2'"), F(0.25));
1363   check.template operator()<"answer is '{:>14.6A}'">(SV("answer is '   1.000000P-2'"), F(0.25));
1364   check.template operator()<"answer is '{:<14.6A}'">(SV("answer is '1.000000P-2   '"), F(0.25));
1365   check.template operator()<"answer is '{:^14.6A}'">(SV("answer is ' 1.000000P-2  '"), F(0.25));
1366 
1367   check.template operator()<"answer is '{:->14.6A}'">(SV("answer is '---1.000000P-3'"), F(125e-3));
1368   check.template operator()<"answer is '{:-<14.6A}'">(SV("answer is '1.000000P-3---'"), F(125e-3));
1369   check.template operator()<"answer is '{:-^14.6A}'">(SV("answer is '-1.000000P-3--'"), F(125e-3));
1370 
1371   check.template operator()<"answer is '{:*>6.6A}'">(SV("answer is '***INF'"), std::numeric_limits<F>::infinity());
1372   check.template operator()<"answer is '{:*<6.6A}'">(SV("answer is 'INF***'"), std::numeric_limits<F>::infinity());
1373   check.template operator()<"answer is '{:*^6.6A}'">(SV("answer is '*INF**'"), std::numeric_limits<F>::infinity());
1374 
1375   check.template operator()<"answer is '{:#>7.6A}'">(SV("answer is '###-INF'"), -std::numeric_limits<F>::infinity());
1376   check.template operator()<"answer is '{:#<7.6A}'">(SV("answer is '-INF###'"), -std::numeric_limits<F>::infinity());
1377   check.template operator()<"answer is '{:#^7.6A}'">(SV("answer is '#-INF##'"), -std::numeric_limits<F>::infinity());
1378 
1379   check.template operator()<"answer is '{:^>6.6A}'">(SV("answer is '^^^NAN'"), nan_pos);
1380   check.template operator()<"answer is '{:^<6.6A}'">(SV("answer is 'NAN^^^'"), nan_pos);
1381   check.template operator()<"answer is '{:^^6.6A}'">(SV("answer is '^NAN^^'"), nan_pos);
1382 
1383   check.template operator()<"answer is '{:0>7.6A}'">(SV("answer is '000-NAN'"), nan_neg);
1384   check.template operator()<"answer is '{:0<7.6A}'">(SV("answer is '-NAN000'"), nan_neg);
1385   check.template operator()<"answer is '{:0^7.6A}'">(SV("answer is '0-NAN00'"), nan_neg);
1386 
1387   // Test whether zero padding is ignored
1388   check.template operator()<"answer is '{:>014.6A}'">(SV("answer is '   1.000000P-2'"), F(0.25));
1389   check.template operator()<"answer is '{:<014.6A}'">(SV("answer is '1.000000P-2   '"), F(0.25));
1390   check.template operator()<"answer is '{:^014.6A}'">(SV("answer is ' 1.000000P-2  '"), F(0.25));
1391 
1392   // *** Sign ***
1393   check.template operator()<"answer is '{:.6A}'">(SV("answer is '0.000000P+0'"), F(0));
1394   check.template operator()<"answer is '{:-.6A}'">(SV("answer is '0.000000P+0'"), F(0));
1395   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '+0.000000P+0'"), F(0));
1396   check.template operator()<"answer is '{: .6A}'">(SV("answer is ' 0.000000P+0'"), F(0));
1397 
1398   check.template operator()<"answer is '{:.6A}'">(SV("answer is '-0.000000P+0'"), F(-0.));
1399   check.template operator()<"answer is '{:-.6A}'">(SV("answer is '-0.000000P+0'"), F(-0.));
1400   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '-0.000000P+0'"), F(-0.));
1401   check.template operator()<"answer is '{: .6A}'">(SV("answer is '-0.000000P+0'"), F(-0.));
1402 
1403   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1404   check.template operator()<"answer is '{:.6A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1405   check.template operator()<"answer is '{:-.6A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1406   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '+INF'"), std::numeric_limits<F>::infinity());
1407   check.template operator()<"answer is '{: .6A}'">(SV("answer is ' INF'"), std::numeric_limits<F>::infinity());
1408 
1409   check.template operator()<"answer is '{:.6A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1410   check.template operator()<"answer is '{:-.6A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1411   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1412   check.template operator()<"answer is '{: .6A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1413 
1414   check.template operator()<"answer is '{:.6A}'">(SV("answer is 'NAN'"), nan_pos);
1415   check.template operator()<"answer is '{:-.6A}'">(SV("answer is 'NAN'"), nan_pos);
1416   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '+NAN'"), nan_pos);
1417   check.template operator()<"answer is '{: .6A}'">(SV("answer is ' NAN'"), nan_pos);
1418 
1419   check.template operator()<"answer is '{:.6A}'">(SV("answer is '-NAN'"), nan_neg);
1420   check.template operator()<"answer is '{:-.6A}'">(SV("answer is '-NAN'"), nan_neg);
1421   check.template operator()<"answer is '{:+.6A}'">(SV("answer is '-NAN'"), nan_neg);
1422   check.template operator()<"answer is '{: .6A}'">(SV("answer is '-NAN'"), nan_neg);
1423 
1424   // *** alternate form ***
1425   check.template operator()<"answer is '{:#.6A}'">(SV("answer is '1.400000P+1'"), F(2.5));
1426 
1427   check.template operator()<"answer is '{:#.6A}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1428   check.template operator()<"answer is '{:#.6A}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1429 
1430   check.template operator()<"answer is '{:#.6A}'">(SV("answer is 'NAN'"), nan_pos);
1431   check.template operator()<"answer is '{:#.6A}'">(SV("answer is '-NAN'"), nan_neg);
1432 
1433   // *** zero-padding & width ***
1434   check.template operator()<"answer is '{:011.6A}'">(SV("answer is '1.000000P-5'"), 0.03125);
1435   check.template operator()<"answer is '{:+012.6A}'">(SV("answer is '+1.000000P-5'"), 0.03125);
1436   check.template operator()<"answer is '{:+013.6A}'">(SV("answer is '+01.000000P-5'"), 0.03125);
1437 
1438   check.template operator()<"answer is '{:014.6A}'">(SV("answer is '0001.000000P-5'"), 0.03125);
1439   check.template operator()<"answer is '{:-014.6A}'">(SV("answer is '0001.000000P-5'"), 0.03125);
1440   check.template operator()<"answer is '{:+014.6A}'">(SV("answer is '+001.000000P-5'"), 0.03125);
1441   check.template operator()<"answer is '{: 014.6A}'">(SV("answer is ' 001.000000P-5'"), 0.03125);
1442 
1443   check.template operator()<"answer is '{:010.6A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1444   check.template operator()<"answer is '{:-010.6A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1445   check.template operator()<"answer is '{:+010.6A}'">(SV("answer is '      +INF'"), std::numeric_limits<F>::infinity());
1446   check.template operator()<"answer is '{: 010.6A}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1447 
1448   check.template operator()<"answer is '{:010.6A}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1449   check.template operator()<"answer is '{:-010.6A}'">(SV("answer is '      -INF'"),
1450                                                       -std::numeric_limits<F>::infinity());
1451   check.template operator()<"answer is '{:+010.6A}'">(SV("answer is '      -INF'"),
1452                                                       -std::numeric_limits<F>::infinity());
1453   check.template operator()<"answer is '{: 010.6A}'">(SV("answer is '      -INF'"),
1454                                                       -std::numeric_limits<F>::infinity());
1455 
1456   check.template operator()<"answer is '{:010.6A}'">(SV("answer is '       NAN'"), nan_pos);
1457   check.template operator()<"answer is '{:-010.6A}'">(SV("answer is '       NAN'"), nan_pos);
1458   check.template operator()<"answer is '{:+010.6A}'">(SV("answer is '      +NAN'"), nan_pos);
1459   check.template operator()<"answer is '{: 010.6A}'">(SV("answer is '       NAN'"), nan_pos);
1460 
1461   check.template operator()<"answer is '{:010.6A}'">(SV("answer is '      -NAN'"), nan_neg);
1462   check.template operator()<"answer is '{:-010.6A}'">(SV("answer is '      -NAN'"), nan_neg);
1463   check.template operator()<"answer is '{:+010.6A}'">(SV("answer is '      -NAN'"), nan_neg);
1464   check.template operator()<"answer is '{: 010.6A}'">(SV("answer is '      -NAN'"), nan_neg);
1465 
1466   // *** locale-specific form ***
1467   // See locale-specific_form.pass.cpp
1468 }
1469 
1470 template <class F, class CharT, class TestFunction>
1471 void format_test_floating_point_scientific_lower_case(TestFunction check) {
1472   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1473   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1474 
1475   // *** align-fill & width ***
1476   check.template operator()<"answer is '{:15e}'">(SV("answer is '   2.500000e-01'"), F(0.25));
1477   check.template operator()<"answer is '{:>15e}'">(SV("answer is '   2.500000e-01'"), F(0.25));
1478   check.template operator()<"answer is '{:<15e}'">(SV("answer is '2.500000e-01   '"), F(0.25));
1479   check.template operator()<"answer is '{:^15e}'">(SV("answer is ' 2.500000e-01  '"), F(0.25));
1480 
1481   check.template operator()<"answer is '{:->15e}'">(SV("answer is '---1.250000e-01'"), F(125e-3));
1482   check.template operator()<"answer is '{:-<15e}'">(SV("answer is '1.250000e-01---'"), F(125e-3));
1483   check.template operator()<"answer is '{:-^15e}'">(SV("answer is '-1.250000e-01--'"), F(125e-3));
1484 
1485   check.template operator()<"answer is '{:*>6e}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
1486   check.template operator()<"answer is '{:*<6e}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
1487   check.template operator()<"answer is '{:*^6e}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
1488 
1489   check.template operator()<"answer is '{:#>7e}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
1490   check.template operator()<"answer is '{:#<7e}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
1491   check.template operator()<"answer is '{:#^7e}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
1492 
1493   check.template operator()<"answer is '{:^>6e}'">(SV("answer is '^^^nan'"), nan_pos);
1494   check.template operator()<"answer is '{:^<6e}'">(SV("answer is 'nan^^^'"), nan_pos);
1495   check.template operator()<"answer is '{:^^6e}'">(SV("answer is '^nan^^'"), nan_pos);
1496 
1497   check.template operator()<"answer is '{:0>7e}'">(SV("answer is '000-nan'"), nan_neg);
1498   check.template operator()<"answer is '{:0<7e}'">(SV("answer is '-nan000'"), nan_neg);
1499   check.template operator()<"answer is '{:0^7e}'">(SV("answer is '0-nan00'"), nan_neg);
1500 
1501   // Test whether zero padding is ignored
1502   check.template operator()<"answer is '{:>015e}'">(SV("answer is '   2.500000e-01'"), F(0.25));
1503   check.template operator()<"answer is '{:<015e}'">(SV("answer is '2.500000e-01   '"), F(0.25));
1504   check.template operator()<"answer is '{:^015e}'">(SV("answer is ' 2.500000e-01  '"), F(0.25));
1505 
1506   // *** Sign ***
1507   check.template operator()<"answer is '{:e}'">(SV("answer is '0.000000e+00'"), F(0));
1508   check.template operator()<"answer is '{:-e}'">(SV("answer is '0.000000e+00'"), F(0));
1509   check.template operator()<"answer is '{:+e}'">(SV("answer is '+0.000000e+00'"), F(0));
1510   check.template operator()<"answer is '{: e}'">(SV("answer is ' 0.000000e+00'"), F(0));
1511 
1512   check.template operator()<"answer is '{:e}'">(SV("answer is '-0.000000e+00'"), F(-0.));
1513   check.template operator()<"answer is '{:-e}'">(SV("answer is '-0.000000e+00'"), F(-0.));
1514   check.template operator()<"answer is '{:+e}'">(SV("answer is '-0.000000e+00'"), F(-0.));
1515   check.template operator()<"answer is '{: e}'">(SV("answer is '-0.000000e+00'"), F(-0.));
1516 
1517   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1518   check.template operator()<"answer is '{:e}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1519   check.template operator()<"answer is '{:-e}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1520   check.template operator()<"answer is '{:+e}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
1521   check.template operator()<"answer is '{: e}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
1522 
1523   check.template operator()<"answer is '{:e}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1524   check.template operator()<"answer is '{:-e}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1525   check.template operator()<"answer is '{:+e}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1526   check.template operator()<"answer is '{: e}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1527 
1528   check.template operator()<"answer is '{:e}'">(SV("answer is 'nan'"), nan_pos);
1529   check.template operator()<"answer is '{:-e}'">(SV("answer is 'nan'"), nan_pos);
1530   check.template operator()<"answer is '{:+e}'">(SV("answer is '+nan'"), nan_pos);
1531   check.template operator()<"answer is '{: e}'">(SV("answer is ' nan'"), nan_pos);
1532 
1533   check.template operator()<"answer is '{:e}'">(SV("answer is '-nan'"), nan_neg);
1534   check.template operator()<"answer is '{:-e}'">(SV("answer is '-nan'"), nan_neg);
1535   check.template operator()<"answer is '{:+e}'">(SV("answer is '-nan'"), nan_neg);
1536   check.template operator()<"answer is '{: e}'">(SV("answer is '-nan'"), nan_neg);
1537 
1538   // *** alternate form **
1539   // When precision is zero there's no decimal point except when the alternate form is specified.
1540   check.template operator()<"answer is '{:.0e}'">(SV("answer is '0e+00'"), F(0));
1541   check.template operator()<"answer is '{:#.0e}'">(SV("answer is '0.e+00'"), F(0));
1542 
1543   check.template operator()<"answer is '{:#e}'">(SV("answer is '0.000000e+00'"), F(0));
1544   check.template operator()<"answer is '{:#e}'">(SV("answer is '2.500000e+00'"), F(2.5));
1545 
1546   check.template operator()<"answer is '{:#e}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1547   check.template operator()<"answer is '{:#e}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1548 
1549   check.template operator()<"answer is '{:#e}'">(SV("answer is 'nan'"), nan_pos);
1550   check.template operator()<"answer is '{:#e}'">(SV("answer is '-nan'"), nan_neg);
1551 
1552   // *** zero-padding & width ***
1553   check.template operator()<"answer is '{:07e}'">(SV("answer is '3.125000e-02'"), 0.03125);
1554   check.template operator()<"answer is '{:+07e}'">(SV("answer is '+3.125000e-02'"), 0.03125);
1555   check.template operator()<"answer is '{:+08e}'">(SV("answer is '+3.125000e-02'"), 0.03125);
1556   check.template operator()<"answer is '{:+09e}'">(SV("answer is '+3.125000e-02'"), 0.03125);
1557 
1558   check.template operator()<"answer is '{:014e}'">(SV("answer is '003.125000e-02'"), 0.03125);
1559   check.template operator()<"answer is '{:-014e}'">(SV("answer is '003.125000e-02'"), 0.03125);
1560   check.template operator()<"answer is '{:+014e}'">(SV("answer is '+03.125000e-02'"), 0.03125);
1561   check.template operator()<"answer is '{: 014e}'">(SV("answer is ' 03.125000e-02'"), 0.03125);
1562 
1563   check.template operator()<"answer is '{:010e}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1564   check.template operator()<"answer is '{:-010e}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1565   check.template operator()<"answer is '{:+010e}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
1566   check.template operator()<"answer is '{: 010e}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1567 
1568   check.template operator()<"answer is '{:010e}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1569   check.template operator()<"answer is '{:-010e}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1570   check.template operator()<"answer is '{:+010e}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1571   check.template operator()<"answer is '{: 010e}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1572 
1573   check.template operator()<"answer is '{:010e}'">(SV("answer is '       nan'"), nan_pos);
1574   check.template operator()<"answer is '{:-010e}'">(SV("answer is '       nan'"), nan_pos);
1575   check.template operator()<"answer is '{:+010e}'">(SV("answer is '      +nan'"), nan_pos);
1576   check.template operator()<"answer is '{: 010e}'">(SV("answer is '       nan'"), nan_pos);
1577 
1578   check.template operator()<"answer is '{:010e}'">(SV("answer is '      -nan'"), nan_neg);
1579   check.template operator()<"answer is '{:-010e}'">(SV("answer is '      -nan'"), nan_neg);
1580   check.template operator()<"answer is '{:+010e}'">(SV("answer is '      -nan'"), nan_neg);
1581   check.template operator()<"answer is '{: 010e}'">(SV("answer is '      -nan'"), nan_neg);
1582 
1583   // *** precision ***
1584   check.template operator()<"answer is '{:.0e}'">(SV("answer is '3e-02'"), 0.03125);
1585   check.template operator()<"answer is '{:.1e}'">(SV("answer is '3.1e-02'"), 0.03125);
1586   check.template operator()<"answer is '{:.3e}'">(SV("answer is '3.125e-02'"), 0.03125);
1587   check.template operator()<"answer is '{:.10e}'">(SV("answer is '3.1250000000e-02'"), 0.03125);
1588 
1589   // *** locale-specific form ***
1590   // See locale-specific_form.pass.cpp
1591 }
1592 
1593 template <class F, class CharT, class TestFunction>
1594 void format_test_floating_point_scientific_upper_case(TestFunction check) {
1595   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1596   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1597 
1598   // *** align-fill & width ***
1599   check.template operator()<"answer is '{:15E}'">(SV("answer is '   2.500000E-01'"), F(0.25));
1600   check.template operator()<"answer is '{:>15E}'">(SV("answer is '   2.500000E-01'"), F(0.25));
1601   check.template operator()<"answer is '{:<15E}'">(SV("answer is '2.500000E-01   '"), F(0.25));
1602   check.template operator()<"answer is '{:^15E}'">(SV("answer is ' 2.500000E-01  '"), F(0.25));
1603 
1604   check.template operator()<"answer is '{:->15E}'">(SV("answer is '---1.250000E-01'"), F(125e-3));
1605   check.template operator()<"answer is '{:-<15E}'">(SV("answer is '1.250000E-01---'"), F(125e-3));
1606   check.template operator()<"answer is '{:-^15E}'">(SV("answer is '-1.250000E-01--'"), F(125e-3));
1607 
1608   check.template operator()<"answer is '{:*>6E}'">(SV("answer is '***INF'"), std::numeric_limits<F>::infinity());
1609   check.template operator()<"answer is '{:*<6E}'">(SV("answer is 'INF***'"), std::numeric_limits<F>::infinity());
1610   check.template operator()<"answer is '{:*^6E}'">(SV("answer is '*INF**'"), std::numeric_limits<F>::infinity());
1611 
1612   check.template operator()<"answer is '{:#>7E}'">(SV("answer is '###-INF'"), -std::numeric_limits<F>::infinity());
1613   check.template operator()<"answer is '{:#<7E}'">(SV("answer is '-INF###'"), -std::numeric_limits<F>::infinity());
1614   check.template operator()<"answer is '{:#^7E}'">(SV("answer is '#-INF##'"), -std::numeric_limits<F>::infinity());
1615 
1616   check.template operator()<"answer is '{:^>6E}'">(SV("answer is '^^^NAN'"), nan_pos);
1617   check.template operator()<"answer is '{:^<6E}'">(SV("answer is 'NAN^^^'"), nan_pos);
1618   check.template operator()<"answer is '{:^^6E}'">(SV("answer is '^NAN^^'"), nan_pos);
1619 
1620   check.template operator()<"answer is '{:0>7E}'">(SV("answer is '000-NAN'"), nan_neg);
1621   check.template operator()<"answer is '{:0<7E}'">(SV("answer is '-NAN000'"), nan_neg);
1622   check.template operator()<"answer is '{:0^7E}'">(SV("answer is '0-NAN00'"), nan_neg);
1623 
1624   // Test whether zero padding is ignored
1625   check.template operator()<"answer is '{:>015E}'">(SV("answer is '   2.500000E-01'"), F(0.25));
1626   check.template operator()<"answer is '{:<015E}'">(SV("answer is '2.500000E-01   '"), F(0.25));
1627   check.template operator()<"answer is '{:^015E}'">(SV("answer is ' 2.500000E-01  '"), F(0.25));
1628 
1629   // *** Sign ***
1630   check.template operator()<"answer is '{:E}'">(SV("answer is '0.000000E+00'"), F(0));
1631   check.template operator()<"answer is '{:-E}'">(SV("answer is '0.000000E+00'"), F(0));
1632   check.template operator()<"answer is '{:+E}'">(SV("answer is '+0.000000E+00'"), F(0));
1633   check.template operator()<"answer is '{: E}'">(SV("answer is ' 0.000000E+00'"), F(0));
1634 
1635   check.template operator()<"answer is '{:E}'">(SV("answer is '-0.000000E+00'"), F(-0.));
1636   check.template operator()<"answer is '{:-E}'">(SV("answer is '-0.000000E+00'"), F(-0.));
1637   check.template operator()<"answer is '{:+E}'">(SV("answer is '-0.000000E+00'"), F(-0.));
1638   check.template operator()<"answer is '{: E}'">(SV("answer is '-0.000000E+00'"), F(-0.));
1639 
1640   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1641   check.template operator()<"answer is '{:E}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1642   check.template operator()<"answer is '{:-E}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1643   check.template operator()<"answer is '{:+E}'">(SV("answer is '+INF'"), std::numeric_limits<F>::infinity());
1644   check.template operator()<"answer is '{: E}'">(SV("answer is ' INF'"), std::numeric_limits<F>::infinity());
1645 
1646   check.template operator()<"answer is '{:E}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1647   check.template operator()<"answer is '{:-E}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1648   check.template operator()<"answer is '{:+E}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1649   check.template operator()<"answer is '{: E}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1650 
1651   check.template operator()<"answer is '{:E}'">(SV("answer is 'NAN'"), nan_pos);
1652   check.template operator()<"answer is '{:-E}'">(SV("answer is 'NAN'"), nan_pos);
1653   check.template operator()<"answer is '{:+E}'">(SV("answer is '+NAN'"), nan_pos);
1654   check.template operator()<"answer is '{: E}'">(SV("answer is ' NAN'"), nan_pos);
1655 
1656   check.template operator()<"answer is '{:E}'">(SV("answer is '-NAN'"), nan_neg);
1657   check.template operator()<"answer is '{:-E}'">(SV("answer is '-NAN'"), nan_neg);
1658   check.template operator()<"answer is '{:+E}'">(SV("answer is '-NAN'"), nan_neg);
1659   check.template operator()<"answer is '{: E}'">(SV("answer is '-NAN'"), nan_neg);
1660 
1661   // *** alternate form **
1662   // When precision is zero there's no decimal point except when the alternate form is specified.
1663   check.template operator()<"answer is '{:.0E}'">(SV("answer is '0E+00'"), F(0));
1664   check.template operator()<"answer is '{:#.0E}'">(SV("answer is '0.E+00'"), F(0));
1665 
1666   check.template operator()<"answer is '{:#E}'">(SV("answer is '0.000000E+00'"), F(0));
1667   check.template operator()<"answer is '{:#E}'">(SV("answer is '2.500000E+00'"), F(2.5));
1668 
1669   check.template operator()<"answer is '{:#E}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1670   check.template operator()<"answer is '{:#E}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1671 
1672   check.template operator()<"answer is '{:#E}'">(SV("answer is 'NAN'"), nan_pos);
1673   check.template operator()<"answer is '{:#E}'">(SV("answer is '-NAN'"), nan_neg);
1674 
1675   // *** zero-padding & width ***
1676   check.template operator()<"answer is '{:07E}'">(SV("answer is '3.125000E-02'"), 0.03125);
1677   check.template operator()<"answer is '{:+07E}'">(SV("answer is '+3.125000E-02'"), 0.03125);
1678   check.template operator()<"answer is '{:+08E}'">(SV("answer is '+3.125000E-02'"), 0.03125);
1679   check.template operator()<"answer is '{:+09E}'">(SV("answer is '+3.125000E-02'"), 0.03125);
1680 
1681   check.template operator()<"answer is '{:014E}'">(SV("answer is '003.125000E-02'"), 0.03125);
1682   check.template operator()<"answer is '{:-014E}'">(SV("answer is '003.125000E-02'"), 0.03125);
1683   check.template operator()<"answer is '{:+014E}'">(SV("answer is '+03.125000E-02'"), 0.03125);
1684   check.template operator()<"answer is '{: 014E}'">(SV("answer is ' 03.125000E-02'"), 0.03125);
1685 
1686   check.template operator()<"answer is '{:010E}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1687   check.template operator()<"answer is '{:-010E}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1688   check.template operator()<"answer is '{:+010E}'">(SV("answer is '      +INF'"), std::numeric_limits<F>::infinity());
1689   check.template operator()<"answer is '{: 010E}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1690 
1691   check.template operator()<"answer is '{:010E}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1692   check.template operator()<"answer is '{:-010E}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1693   check.template operator()<"answer is '{:+010E}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1694   check.template operator()<"answer is '{: 010E}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1695 
1696   check.template operator()<"answer is '{:010E}'">(SV("answer is '       NAN'"), nan_pos);
1697   check.template operator()<"answer is '{:-010E}'">(SV("answer is '       NAN'"), nan_pos);
1698   check.template operator()<"answer is '{:+010E}'">(SV("answer is '      +NAN'"), nan_pos);
1699   check.template operator()<"answer is '{: 010E}'">(SV("answer is '       NAN'"), nan_pos);
1700 
1701   check.template operator()<"answer is '{:010E}'">(SV("answer is '      -NAN'"), nan_neg);
1702   check.template operator()<"answer is '{:-010E}'">(SV("answer is '      -NAN'"), nan_neg);
1703   check.template operator()<"answer is '{:+010E}'">(SV("answer is '      -NAN'"), nan_neg);
1704   check.template operator()<"answer is '{: 010E}'">(SV("answer is '      -NAN'"), nan_neg);
1705 
1706   // *** precision ***
1707   check.template operator()<"answer is '{:.0E}'">(SV("answer is '3E-02'"), 0.03125);
1708   check.template operator()<"answer is '{:.1E}'">(SV("answer is '3.1E-02'"), 0.03125);
1709   check.template operator()<"answer is '{:.3E}'">(SV("answer is '3.125E-02'"), 0.03125);
1710   check.template operator()<"answer is '{:.10E}'">(SV("answer is '3.1250000000E-02'"), 0.03125);
1711 
1712   // *** locale-specific form ***
1713   // See locale-specific_form.pass.cpp
1714 }
1715 
1716 template <class F, class CharT, class TestFunction>
1717 void format_test_floating_point_fixed_lower_case(TestFunction check) {
1718   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1719   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1720 
1721   // *** align-fill & width ***
1722   check.template operator()<"answer is '{:11f}'">(SV("answer is '   0.250000'"), F(0.25));
1723   check.template operator()<"answer is '{:>11f}'">(SV("answer is '   0.250000'"), F(0.25));
1724   check.template operator()<"answer is '{:<11f}'">(SV("answer is '0.250000   '"), F(0.25));
1725   check.template operator()<"answer is '{:^11f}'">(SV("answer is ' 0.250000  '"), F(0.25));
1726 
1727   check.template operator()<"answer is '{:->11f}'">(SV("answer is '---0.125000'"), F(125e-3));
1728   check.template operator()<"answer is '{:-<11f}'">(SV("answer is '0.125000---'"), F(125e-3));
1729   check.template operator()<"answer is '{:-^11f}'">(SV("answer is '-0.125000--'"), F(125e-3));
1730 
1731   check.template operator()<"answer is '{:*>6f}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
1732   check.template operator()<"answer is '{:*<6f}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
1733   check.template operator()<"answer is '{:*^6f}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
1734 
1735   check.template operator()<"answer is '{:#>7f}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
1736   check.template operator()<"answer is '{:#<7f}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
1737   check.template operator()<"answer is '{:#^7f}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
1738 
1739   check.template operator()<"answer is '{:^>6f}'">(SV("answer is '^^^nan'"), nan_pos);
1740   check.template operator()<"answer is '{:^<6f}'">(SV("answer is 'nan^^^'"), nan_pos);
1741   check.template operator()<"answer is '{:^^6f}'">(SV("answer is '^nan^^'"), nan_pos);
1742 
1743   check.template operator()<"answer is '{:0>7f}'">(SV("answer is '000-nan'"), nan_neg);
1744   check.template operator()<"answer is '{:0<7f}'">(SV("answer is '-nan000'"), nan_neg);
1745   check.template operator()<"answer is '{:0^7f}'">(SV("answer is '0-nan00'"), nan_neg);
1746 
1747   // Test whether zero padding is ignored
1748   check.template operator()<"answer is '{:>011f}'">(SV("answer is '   0.250000'"), F(0.25));
1749   check.template operator()<"answer is '{:<011f}'">(SV("answer is '0.250000   '"), F(0.25));
1750   check.template operator()<"answer is '{:^011f}'">(SV("answer is ' 0.250000  '"), F(0.25));
1751 
1752   // *** Sign ***
1753   check.template operator()<"answer is '{:f}'">(SV("answer is '0.000000'"), F(0));
1754   check.template operator()<"answer is '{:-f}'">(SV("answer is '0.000000'"), F(0));
1755   check.template operator()<"answer is '{:+f}'">(SV("answer is '+0.000000'"), F(0));
1756   check.template operator()<"answer is '{: f}'">(SV("answer is ' 0.000000'"), F(0));
1757 
1758   check.template operator()<"answer is '{:f}'">(SV("answer is '-0.000000'"), F(-0.));
1759   check.template operator()<"answer is '{:-f}'">(SV("answer is '-0.000000'"), F(-0.));
1760   check.template operator()<"answer is '{:+f}'">(SV("answer is '-0.000000'"), F(-0.));
1761   check.template operator()<"answer is '{: f}'">(SV("answer is '-0.000000'"), F(-0.));
1762 
1763   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1764   check.template operator()<"answer is '{:f}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1765   check.template operator()<"answer is '{:-f}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1766   check.template operator()<"answer is '{:+f}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
1767   check.template operator()<"answer is '{: f}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
1768 
1769   check.template operator()<"answer is '{:f}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1770   check.template operator()<"answer is '{:-f}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1771   check.template operator()<"answer is '{:+f}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1772   check.template operator()<"answer is '{: f}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1773 
1774   check.template operator()<"answer is '{:f}'">(SV("answer is 'nan'"), nan_pos);
1775   check.template operator()<"answer is '{:-f}'">(SV("answer is 'nan'"), nan_pos);
1776   check.template operator()<"answer is '{:+f}'">(SV("answer is '+nan'"), nan_pos);
1777   check.template operator()<"answer is '{: f}'">(SV("answer is ' nan'"), nan_pos);
1778 
1779   check.template operator()<"answer is '{:f}'">(SV("answer is '-nan'"), nan_neg);
1780   check.template operator()<"answer is '{:-f}'">(SV("answer is '-nan'"), nan_neg);
1781   check.template operator()<"answer is '{:+f}'">(SV("answer is '-nan'"), nan_neg);
1782   check.template operator()<"answer is '{: f}'">(SV("answer is '-nan'"), nan_neg);
1783 
1784   // *** alternate form **
1785   // When precision is zero there's no decimal point except when the alternate form is specified.
1786   check.template operator()<"answer is '{:.0f}'">(SV("answer is '0'"), F(0));
1787   check.template operator()<"answer is '{:#.0f}'">(SV("answer is '0.'"), F(0));
1788 
1789   check.template operator()<"answer is '{:#f}'">(SV("answer is '0.000000'"), F(0));
1790   check.template operator()<"answer is '{:#f}'">(SV("answer is '2.500000'"), F(2.5));
1791 
1792   check.template operator()<"answer is '{:#f}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
1793   check.template operator()<"answer is '{:#f}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
1794 
1795   check.template operator()<"answer is '{:#f}'">(SV("answer is 'nan'"), nan_pos);
1796   check.template operator()<"answer is '{:#f}'">(SV("answer is '-nan'"), nan_neg);
1797 
1798   // *** zero-padding & width ***
1799   check.template operator()<"answer is '{:07f}'">(SV("answer is '0.031250'"), 0.03125);
1800   check.template operator()<"answer is '{:+07f}'">(SV("answer is '+0.031250'"), 0.03125);
1801   check.template operator()<"answer is '{:+08f}'">(SV("answer is '+0.031250'"), 0.03125);
1802   check.template operator()<"answer is '{:+09f}'">(SV("answer is '+0.031250'"), 0.03125);
1803 
1804   check.template operator()<"answer is '{:010f}'">(SV("answer is '000.031250'"), 0.03125);
1805   check.template operator()<"answer is '{:-010f}'">(SV("answer is '000.031250'"), 0.03125);
1806   check.template operator()<"answer is '{:+010f}'">(SV("answer is '+00.031250'"), 0.03125);
1807   check.template operator()<"answer is '{: 010f}'">(SV("answer is ' 00.031250'"), 0.03125);
1808 
1809   check.template operator()<"answer is '{:010f}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1810   check.template operator()<"answer is '{:-010f}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1811   check.template operator()<"answer is '{:+010f}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
1812   check.template operator()<"answer is '{: 010f}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
1813 
1814   check.template operator()<"answer is '{:010f}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1815   check.template operator()<"answer is '{:-010f}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1816   check.template operator()<"answer is '{:+010f}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1817   check.template operator()<"answer is '{: 010f}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
1818 
1819   check.template operator()<"answer is '{:010f}'">(SV("answer is '       nan'"), nan_pos);
1820   check.template operator()<"answer is '{:-010f}'">(SV("answer is '       nan'"), nan_pos);
1821   check.template operator()<"answer is '{:+010f}'">(SV("answer is '      +nan'"), nan_pos);
1822   check.template operator()<"answer is '{: 010f}'">(SV("answer is '       nan'"), nan_pos);
1823 
1824   check.template operator()<"answer is '{:010f}'">(SV("answer is '      -nan'"), nan_neg);
1825   check.template operator()<"answer is '{:-010f}'">(SV("answer is '      -nan'"), nan_neg);
1826   check.template operator()<"answer is '{:+010f}'">(SV("answer is '      -nan'"), nan_neg);
1827   check.template operator()<"answer is '{: 010f}'">(SV("answer is '      -nan'"), nan_neg);
1828 
1829   // *** precision ***
1830   check.template operator()<"answer is '{:.0f}'">(SV("answer is '0'"), 0.03125);
1831   check.template operator()<"answer is '{:.1f}'">(SV("answer is '0.0'"), 0.03125);
1832   check.template operator()<"answer is '{:.5f}'">(SV("answer is '0.03125'"), 0.03125);
1833   check.template operator()<"answer is '{:.10f}'">(SV("answer is '0.0312500000'"), 0.03125);
1834 
1835   // *** locale-specific form ***
1836   // See locale-specific_form.pass.cpp
1837 }
1838 
1839 template <class F, class CharT, class TestFunction>
1840 void format_test_floating_point_fixed_upper_case(TestFunction check) {
1841   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1842   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1843 
1844   // *** align-fill & width ***
1845   check.template operator()<"answer is '{:11F}'">(SV("answer is '   0.250000'"), F(0.25));
1846   check.template operator()<"answer is '{:>11F}'">(SV("answer is '   0.250000'"), F(0.25));
1847   check.template operator()<"answer is '{:<11F}'">(SV("answer is '0.250000   '"), F(0.25));
1848   check.template operator()<"answer is '{:^11F}'">(SV("answer is ' 0.250000  '"), F(0.25));
1849 
1850   check.template operator()<"answer is '{:->11F}'">(SV("answer is '---0.125000'"), F(125e-3));
1851   check.template operator()<"answer is '{:-<11F}'">(SV("answer is '0.125000---'"), F(125e-3));
1852   check.template operator()<"answer is '{:-^11F}'">(SV("answer is '-0.125000--'"), F(125e-3));
1853 
1854   check.template operator()<"answer is '{:*>6F}'">(SV("answer is '***INF'"), std::numeric_limits<F>::infinity());
1855   check.template operator()<"answer is '{:*<6F}'">(SV("answer is 'INF***'"), std::numeric_limits<F>::infinity());
1856   check.template operator()<"answer is '{:*^6F}'">(SV("answer is '*INF**'"), std::numeric_limits<F>::infinity());
1857 
1858   check.template operator()<"answer is '{:#>7F}'">(SV("answer is '###-INF'"), -std::numeric_limits<F>::infinity());
1859   check.template operator()<"answer is '{:#<7F}'">(SV("answer is '-INF###'"), -std::numeric_limits<F>::infinity());
1860   check.template operator()<"answer is '{:#^7F}'">(SV("answer is '#-INF##'"), -std::numeric_limits<F>::infinity());
1861 
1862   check.template operator()<"answer is '{:^>6F}'">(SV("answer is '^^^NAN'"), nan_pos);
1863   check.template operator()<"answer is '{:^<6F}'">(SV("answer is 'NAN^^^'"), nan_pos);
1864   check.template operator()<"answer is '{:^^6F}'">(SV("answer is '^NAN^^'"), nan_pos);
1865 
1866   check.template operator()<"answer is '{:0>7F}'">(SV("answer is '000-NAN'"), nan_neg);
1867   check.template operator()<"answer is '{:0<7F}'">(SV("answer is '-NAN000'"), nan_neg);
1868   check.template operator()<"answer is '{:0^7F}'">(SV("answer is '0-NAN00'"), nan_neg);
1869 
1870   // Test whether zero padding is ignored
1871   check.template operator()<"answer is '{:>011F}'">(SV("answer is '   0.250000'"), F(0.25));
1872   check.template operator()<"answer is '{:<011F}'">(SV("answer is '0.250000   '"), F(0.25));
1873   check.template operator()<"answer is '{:^011F}'">(SV("answer is ' 0.250000  '"), F(0.25));
1874 
1875   // *** Sign ***
1876   check.template operator()<"answer is '{:F}'">(SV("answer is '0.000000'"), F(0));
1877   check.template operator()<"answer is '{:-F}'">(SV("answer is '0.000000'"), F(0));
1878   check.template operator()<"answer is '{:+F}'">(SV("answer is '+0.000000'"), F(0));
1879   check.template operator()<"answer is '{: F}'">(SV("answer is ' 0.000000'"), F(0));
1880 
1881   check.template operator()<"answer is '{:F}'">(SV("answer is '-0.000000'"), F(-0.));
1882   check.template operator()<"answer is '{:-F}'">(SV("answer is '-0.000000'"), F(-0.));
1883   check.template operator()<"answer is '{:+F}'">(SV("answer is '-0.000000'"), F(-0.));
1884   check.template operator()<"answer is '{: F}'">(SV("answer is '-0.000000'"), F(-0.));
1885 
1886   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
1887   check.template operator()<"answer is '{:F}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1888   check.template operator()<"answer is '{:-F}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1889   check.template operator()<"answer is '{:+F}'">(SV("answer is '+INF'"), std::numeric_limits<F>::infinity());
1890   check.template operator()<"answer is '{: F}'">(SV("answer is ' INF'"), std::numeric_limits<F>::infinity());
1891 
1892   check.template operator()<"answer is '{:F}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1893   check.template operator()<"answer is '{:-F}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1894   check.template operator()<"answer is '{:+F}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1895   check.template operator()<"answer is '{: F}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1896 
1897   check.template operator()<"answer is '{:F}'">(SV("answer is 'NAN'"), nan_pos);
1898   check.template operator()<"answer is '{:-F}'">(SV("answer is 'NAN'"), nan_pos);
1899   check.template operator()<"answer is '{:+F}'">(SV("answer is '+NAN'"), nan_pos);
1900   check.template operator()<"answer is '{: F}'">(SV("answer is ' NAN'"), nan_pos);
1901 
1902   check.template operator()<"answer is '{:F}'">(SV("answer is '-NAN'"), nan_neg);
1903   check.template operator()<"answer is '{:-F}'">(SV("answer is '-NAN'"), nan_neg);
1904   check.template operator()<"answer is '{:+F}'">(SV("answer is '-NAN'"), nan_neg);
1905   check.template operator()<"answer is '{: F}'">(SV("answer is '-NAN'"), nan_neg);
1906 
1907   // *** alternate form **
1908   // When precision is zero there's no decimal point except when the alternate form is specified.
1909   check.template operator()<"answer is '{:.0F}'">(SV("answer is '0'"), F(0));
1910   check.template operator()<"answer is '{:#.0F}'">(SV("answer is '0.'"), F(0));
1911 
1912   check.template operator()<"answer is '{:#F}'">(SV("answer is '0.000000'"), F(0));
1913   check.template operator()<"answer is '{:#F}'">(SV("answer is '2.500000'"), F(2.5));
1914 
1915   check.template operator()<"answer is '{:#F}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
1916   check.template operator()<"answer is '{:#F}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
1917 
1918   check.template operator()<"answer is '{:#F}'">(SV("answer is 'NAN'"), nan_pos);
1919   check.template operator()<"answer is '{:#F}'">(SV("answer is '-NAN'"), nan_neg);
1920 
1921   // *** zero-padding & width ***
1922   check.template operator()<"answer is '{:07F}'">(SV("answer is '0.031250'"), 0.03125);
1923   check.template operator()<"answer is '{:+07F}'">(SV("answer is '+0.031250'"), 0.03125);
1924   check.template operator()<"answer is '{:+08F}'">(SV("answer is '+0.031250'"), 0.03125);
1925   check.template operator()<"answer is '{:+09F}'">(SV("answer is '+0.031250'"), 0.03125);
1926 
1927   check.template operator()<"answer is '{:010F}'">(SV("answer is '000.031250'"), 0.03125);
1928   check.template operator()<"answer is '{:-010F}'">(SV("answer is '000.031250'"), 0.03125);
1929   check.template operator()<"answer is '{:+010F}'">(SV("answer is '+00.031250'"), 0.03125);
1930   check.template operator()<"answer is '{: 010F}'">(SV("answer is ' 00.031250'"), 0.03125);
1931 
1932   check.template operator()<"answer is '{:010F}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1933   check.template operator()<"answer is '{:-010F}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1934   check.template operator()<"answer is '{:+010F}'">(SV("answer is '      +INF'"), std::numeric_limits<F>::infinity());
1935   check.template operator()<"answer is '{: 010F}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
1936 
1937   check.template operator()<"answer is '{:010F}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1938   check.template operator()<"answer is '{:-010F}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1939   check.template operator()<"answer is '{:+010F}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1940   check.template operator()<"answer is '{: 010F}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
1941 
1942   check.template operator()<"answer is '{:010F}'">(SV("answer is '       NAN'"), nan_pos);
1943   check.template operator()<"answer is '{:-010F}'">(SV("answer is '       NAN'"), nan_pos);
1944   check.template operator()<"answer is '{:+010F}'">(SV("answer is '      +NAN'"), nan_pos);
1945   check.template operator()<"answer is '{: 010F}'">(SV("answer is '       NAN'"), nan_pos);
1946 
1947   check.template operator()<"answer is '{:010F}'">(SV("answer is '      -NAN'"), nan_neg);
1948   check.template operator()<"answer is '{:-010F}'">(SV("answer is '      -NAN'"), nan_neg);
1949   check.template operator()<"answer is '{:+010F}'">(SV("answer is '      -NAN'"), nan_neg);
1950   check.template operator()<"answer is '{: 010F}'">(SV("answer is '      -NAN'"), nan_neg);
1951 
1952   // *** precision ***
1953   check.template operator()<"answer is '{:.0F}'">(SV("answer is '0'"), 0.03125);
1954   check.template operator()<"answer is '{:.1F}'">(SV("answer is '0.0'"), 0.03125);
1955   check.template operator()<"answer is '{:.5F}'">(SV("answer is '0.03125'"), 0.03125);
1956   check.template operator()<"answer is '{:.10F}'">(SV("answer is '0.0312500000'"), 0.03125);
1957 
1958   // *** locale-specific form ***
1959   // See locale-specific_form.pass.cpp
1960 }
1961 
1962 template <class F, class CharT, class TestFunction>
1963 void format_test_floating_point_general_lower_case(TestFunction check) {
1964   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
1965   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
1966 
1967   // *** align-fill & width ***
1968   check.template operator()<"answer is '{:7g}'">(SV("answer is '   0.25'"), F(0.25));
1969   check.template operator()<"answer is '{:>7g}'">(SV("answer is '   0.25'"), F(0.25));
1970   check.template operator()<"answer is '{:<7g}'">(SV("answer is '0.25   '"), F(0.25));
1971   check.template operator()<"answer is '{:^7g}'">(SV("answer is ' 0.25  '"), F(0.25));
1972 
1973   check.template operator()<"answer is '{:->8g}'">(SV("answer is '---0.125'"), F(125e-3));
1974   check.template operator()<"answer is '{:-<8g}'">(SV("answer is '0.125---'"), F(125e-3));
1975   check.template operator()<"answer is '{:-^8g}'">(SV("answer is '-0.125--'"), F(125e-3));
1976 
1977   check.template operator()<"answer is '{:*>6g}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
1978   check.template operator()<"answer is '{:*<6g}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
1979   check.template operator()<"answer is '{:*^6g}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
1980 
1981   check.template operator()<"answer is '{:#>7g}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
1982   check.template operator()<"answer is '{:#<7g}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
1983   check.template operator()<"answer is '{:#^7g}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
1984 
1985   check.template operator()<"answer is '{:^>6g}'">(SV("answer is '^^^nan'"), nan_pos);
1986   check.template operator()<"answer is '{:^<6g}'">(SV("answer is 'nan^^^'"), nan_pos);
1987   check.template operator()<"answer is '{:^^6g}'">(SV("answer is '^nan^^'"), nan_pos);
1988 
1989   check.template operator()<"answer is '{:0>7g}'">(SV("answer is '000-nan'"), nan_neg);
1990   check.template operator()<"answer is '{:0<7g}'">(SV("answer is '-nan000'"), nan_neg);
1991   check.template operator()<"answer is '{:0^7g}'">(SV("answer is '0-nan00'"), nan_neg);
1992 
1993   // Test whether zero padding is ignored
1994   check.template operator()<"answer is '{:>07g}'">(SV("answer is '   0.25'"), F(0.25));
1995   check.template operator()<"answer is '{:<07g}'">(SV("answer is '0.25   '"), F(0.25));
1996   check.template operator()<"answer is '{:^07g}'">(SV("answer is ' 0.25  '"), F(0.25));
1997 
1998   // *** Sign ***
1999   check.template operator()<"answer is '{:g}'">(SV("answer is '0'"), F(0));
2000   check.template operator()<"answer is '{:-g}'">(SV("answer is '0'"), F(0));
2001   check.template operator()<"answer is '{:+g}'">(SV("answer is '+0'"), F(0));
2002   check.template operator()<"answer is '{: g}'">(SV("answer is ' 0'"), F(0));
2003 
2004   check.template operator()<"answer is '{:g}'">(SV("answer is '-0'"), F(-0.));
2005   check.template operator()<"answer is '{:-g}'">(SV("answer is '-0'"), F(-0.));
2006   check.template operator()<"answer is '{:+g}'">(SV("answer is '-0'"), F(-0.));
2007   check.template operator()<"answer is '{: g}'">(SV("answer is '-0'"), F(-0.));
2008 
2009   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
2010   check.template operator()<"answer is '{:g}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2011   check.template operator()<"answer is '{:-g}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2012   check.template operator()<"answer is '{:+g}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
2013   check.template operator()<"answer is '{: g}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
2014 
2015   check.template operator()<"answer is '{:g}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2016   check.template operator()<"answer is '{:-g}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2017   check.template operator()<"answer is '{:+g}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2018   check.template operator()<"answer is '{: g}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2019 
2020   check.template operator()<"answer is '{:g}'">(SV("answer is 'nan'"), nan_pos);
2021   check.template operator()<"answer is '{:-g}'">(SV("answer is 'nan'"), nan_pos);
2022   check.template operator()<"answer is '{:+g}'">(SV("answer is '+nan'"), nan_pos);
2023   check.template operator()<"answer is '{: g}'">(SV("answer is ' nan'"), nan_pos);
2024 
2025   check.template operator()<"answer is '{:g}'">(SV("answer is '-nan'"), nan_neg);
2026   check.template operator()<"answer is '{:-g}'">(SV("answer is '-nan'"), nan_neg);
2027   check.template operator()<"answer is '{:+g}'">(SV("answer is '-nan'"), nan_neg);
2028   check.template operator()<"answer is '{: g}'">(SV("answer is '-nan'"), nan_neg);
2029 
2030   // *** alternate form **
2031   // When precision is zero there's no decimal point except when the alternate form is specified.
2032   check.template operator()<"answer is '{:.0g}'">(SV("answer is '0'"), F(0));
2033   check.template operator()<"answer is '{:#.0g}'">(SV("answer is '0.'"), F(0));
2034 
2035   check.template operator()<"answer is '{:#g}'">(SV("answer is '0.'"), F(0));
2036   check.template operator()<"answer is '{:#g}'">(SV("answer is '2.5'"), F(2.5));
2037 
2038   check.template operator()<"answer is '{:#g}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2039   check.template operator()<"answer is '{:#g}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2040 
2041   check.template operator()<"answer is '{:#g}'">(SV("answer is 'nan'"), nan_pos);
2042   check.template operator()<"answer is '{:#g}'">(SV("answer is '-nan'"), nan_neg);
2043 
2044   // *** zero-padding & width ***
2045   check.template operator()<"answer is '{:06g}'">(SV("answer is '0.03125'"), 0.03125);
2046   check.template operator()<"answer is '{:+06g}'">(SV("answer is '+0.03125'"), 0.03125);
2047   check.template operator()<"answer is '{:+07g}'">(SV("answer is '+0.03125'"), 0.03125);
2048   check.template operator()<"answer is '{:+08g}'">(SV("answer is '+0.03125'"), 0.03125);
2049 
2050   check.template operator()<"answer is '{:09g}'">(SV("answer is '000.03125'"), 0.03125);
2051   check.template operator()<"answer is '{:-09g}'">(SV("answer is '000.03125'"), 0.03125);
2052   check.template operator()<"answer is '{:+09g}'">(SV("answer is '+00.03125'"), 0.03125);
2053   check.template operator()<"answer is '{: 09g}'">(SV("answer is ' 00.03125'"), 0.03125);
2054 
2055   check.template operator()<"answer is '{:010g}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2056   check.template operator()<"answer is '{:-010g}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2057   check.template operator()<"answer is '{:+010g}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
2058   check.template operator()<"answer is '{: 010g}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2059 
2060   check.template operator()<"answer is '{:010g}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2061   check.template operator()<"answer is '{:-010g}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2062   check.template operator()<"answer is '{:+010g}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2063   check.template operator()<"answer is '{: 010g}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2064 
2065   check.template operator()<"answer is '{:010g}'">(SV("answer is '       nan'"), nan_pos);
2066   check.template operator()<"answer is '{:-010g}'">(SV("answer is '       nan'"), nan_pos);
2067   check.template operator()<"answer is '{:+010g}'">(SV("answer is '      +nan'"), nan_pos);
2068   check.template operator()<"answer is '{: 010g}'">(SV("answer is '       nan'"), nan_pos);
2069 
2070   check.template operator()<"answer is '{:010g}'">(SV("answer is '      -nan'"), nan_neg);
2071   check.template operator()<"answer is '{:-010g}'">(SV("answer is '      -nan'"), nan_neg);
2072   check.template operator()<"answer is '{:+010g}'">(SV("answer is '      -nan'"), nan_neg);
2073   check.template operator()<"answer is '{: 010g}'">(SV("answer is '      -nan'"), nan_neg);
2074 
2075   // *** precision ***
2076   check.template operator()<"answer is '{:.0g}'">(SV("answer is '0.03'"), 0.03125);
2077   check.template operator()<"answer is '{:.1g}'">(SV("answer is '0.03'"), 0.03125);
2078   check.template operator()<"answer is '{:.2g}'">(SV("answer is '0.031'"), 0.03125);
2079   check.template operator()<"answer is '{:.3g}'">(SV("answer is '0.0312'"), 0.03125);
2080   check.template operator()<"answer is '{:.4g}'">(SV("answer is '0.03125'"), 0.03125);
2081   check.template operator()<"answer is '{:.5g}'">(SV("answer is '0.03125'"), 0.03125);
2082   check.template operator()<"answer is '{:.10g}'">(SV("answer is '0.03125'"), 0.03125);
2083 
2084   // *** locale-specific form ***
2085   // See locale-specific_form.pass.cpp
2086 }
2087 
2088 template <class F, class CharT, class TestFunction>
2089 void format_test_floating_point_general_upper_case(TestFunction check) {
2090   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
2091   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
2092 
2093   // *** align-fill & width ***
2094   check.template operator()<"answer is '{:7G}'">(SV("answer is '   0.25'"), F(0.25));
2095   check.template operator()<"answer is '{:>7G}'">(SV("answer is '   0.25'"), F(0.25));
2096   check.template operator()<"answer is '{:<7G}'">(SV("answer is '0.25   '"), F(0.25));
2097   check.template operator()<"answer is '{:^7G}'">(SV("answer is ' 0.25  '"), F(0.25));
2098 
2099   check.template operator()<"answer is '{:->8G}'">(SV("answer is '---0.125'"), F(125e-3));
2100   check.template operator()<"answer is '{:-<8G}'">(SV("answer is '0.125---'"), F(125e-3));
2101   check.template operator()<"answer is '{:-^8G}'">(SV("answer is '-0.125--'"), F(125e-3));
2102 
2103   check.template operator()<"answer is '{:*>6G}'">(SV("answer is '***INF'"), std::numeric_limits<F>::infinity());
2104   check.template operator()<"answer is '{:*<6G}'">(SV("answer is 'INF***'"), std::numeric_limits<F>::infinity());
2105   check.template operator()<"answer is '{:*^6G}'">(SV("answer is '*INF**'"), std::numeric_limits<F>::infinity());
2106 
2107   check.template operator()<"answer is '{:#>7G}'">(SV("answer is '###-INF'"), -std::numeric_limits<F>::infinity());
2108   check.template operator()<"answer is '{:#<7G}'">(SV("answer is '-INF###'"), -std::numeric_limits<F>::infinity());
2109   check.template operator()<"answer is '{:#^7G}'">(SV("answer is '#-INF##'"), -std::numeric_limits<F>::infinity());
2110 
2111   check.template operator()<"answer is '{:^>6G}'">(SV("answer is '^^^NAN'"), nan_pos);
2112   check.template operator()<"answer is '{:^<6G}'">(SV("answer is 'NAN^^^'"), nan_pos);
2113   check.template operator()<"answer is '{:^^6G}'">(SV("answer is '^NAN^^'"), nan_pos);
2114 
2115   check.template operator()<"answer is '{:0>7G}'">(SV("answer is '000-NAN'"), nan_neg);
2116   check.template operator()<"answer is '{:0<7G}'">(SV("answer is '-NAN000'"), nan_neg);
2117   check.template operator()<"answer is '{:0^7G}'">(SV("answer is '0-NAN00'"), nan_neg);
2118 
2119   // Test whether zero padding is ignored
2120   check.template operator()<"answer is '{:>07G}'">(SV("answer is '   0.25'"), F(0.25));
2121   check.template operator()<"answer is '{:<07G}'">(SV("answer is '0.25   '"), F(0.25));
2122   check.template operator()<"answer is '{:^07G}'">(SV("answer is ' 0.25  '"), F(0.25));
2123 
2124   // *** Sign ***
2125   check.template operator()<"answer is '{:G}'">(SV("answer is '0'"), F(0));
2126   check.template operator()<"answer is '{:-G}'">(SV("answer is '0'"), F(0));
2127   check.template operator()<"answer is '{:+G}'">(SV("answer is '+0'"), F(0));
2128   check.template operator()<"answer is '{: G}'">(SV("answer is ' 0'"), F(0));
2129 
2130   check.template operator()<"answer is '{:G}'">(SV("answer is '-0'"), F(-0.));
2131   check.template operator()<"answer is '{:-G}'">(SV("answer is '-0'"), F(-0.));
2132   check.template operator()<"answer is '{:+G}'">(SV("answer is '-0'"), F(-0.));
2133   check.template operator()<"answer is '{: G}'">(SV("answer is '-0'"), F(-0.));
2134 
2135   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
2136   check.template operator()<"answer is '{:G}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
2137   check.template operator()<"answer is '{:-G}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
2138   check.template operator()<"answer is '{:+G}'">(SV("answer is '+INF'"), std::numeric_limits<F>::infinity());
2139   check.template operator()<"answer is '{: G}'">(SV("answer is ' INF'"), std::numeric_limits<F>::infinity());
2140 
2141   check.template operator()<"answer is '{:G}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
2142   check.template operator()<"answer is '{:-G}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
2143   check.template operator()<"answer is '{:+G}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
2144   check.template operator()<"answer is '{: G}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
2145 
2146   check.template operator()<"answer is '{:G}'">(SV("answer is 'NAN'"), nan_pos);
2147   check.template operator()<"answer is '{:-G}'">(SV("answer is 'NAN'"), nan_pos);
2148   check.template operator()<"answer is '{:+G}'">(SV("answer is '+NAN'"), nan_pos);
2149   check.template operator()<"answer is '{: G}'">(SV("answer is ' NAN'"), nan_pos);
2150 
2151   check.template operator()<"answer is '{:G}'">(SV("answer is '-NAN'"), nan_neg);
2152   check.template operator()<"answer is '{:-G}'">(SV("answer is '-NAN'"), nan_neg);
2153   check.template operator()<"answer is '{:+G}'">(SV("answer is '-NAN'"), nan_neg);
2154   check.template operator()<"answer is '{: G}'">(SV("answer is '-NAN'"), nan_neg);
2155 
2156   // *** alternate form **
2157   // When precision is zero there's no decimal point except when the alternate form is specified.
2158   check.template operator()<"answer is '{:.0G}'">(SV("answer is '0'"), F(0));
2159   check.template operator()<"answer is '{:#.0G}'">(SV("answer is '0.'"), F(0));
2160 
2161   check.template operator()<"answer is '{:#G}'">(SV("answer is '0.'"), F(0));
2162   check.template operator()<"answer is '{:#G}'">(SV("answer is '2.5'"), F(2.5));
2163 
2164   check.template operator()<"answer is '{:#G}'">(SV("answer is 'INF'"), std::numeric_limits<F>::infinity());
2165   check.template operator()<"answer is '{:#G}'">(SV("answer is '-INF'"), -std::numeric_limits<F>::infinity());
2166 
2167   check.template operator()<"answer is '{:#G}'">(SV("answer is 'NAN'"), nan_pos);
2168   check.template operator()<"answer is '{:#G}'">(SV("answer is '-NAN'"), nan_neg);
2169 
2170   // *** zero-padding & width ***
2171   check.template operator()<"answer is '{:06G}'">(SV("answer is '0.03125'"), 0.03125);
2172   check.template operator()<"answer is '{:+06G}'">(SV("answer is '+0.03125'"), 0.03125);
2173   check.template operator()<"answer is '{:+07G}'">(SV("answer is '+0.03125'"), 0.03125);
2174   check.template operator()<"answer is '{:+08G}'">(SV("answer is '+0.03125'"), 0.03125);
2175 
2176   check.template operator()<"answer is '{:09G}'">(SV("answer is '000.03125'"), 0.03125);
2177   check.template operator()<"answer is '{:-09G}'">(SV("answer is '000.03125'"), 0.03125);
2178   check.template operator()<"answer is '{:+09G}'">(SV("answer is '+00.03125'"), 0.03125);
2179   check.template operator()<"answer is '{: 09G}'">(SV("answer is ' 00.03125'"), 0.03125);
2180 
2181   check.template operator()<"answer is '{:010G}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
2182   check.template operator()<"answer is '{:-010G}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
2183   check.template operator()<"answer is '{:+010G}'">(SV("answer is '      +INF'"), std::numeric_limits<F>::infinity());
2184   check.template operator()<"answer is '{: 010G}'">(SV("answer is '       INF'"), std::numeric_limits<F>::infinity());
2185 
2186   check.template operator()<"answer is '{:010G}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
2187   check.template operator()<"answer is '{:-010G}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
2188   check.template operator()<"answer is '{:+010G}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
2189   check.template operator()<"answer is '{: 010G}'">(SV("answer is '      -INF'"), -std::numeric_limits<F>::infinity());
2190 
2191   check.template operator()<"answer is '{:010G}'">(SV("answer is '       NAN'"), nan_pos);
2192   check.template operator()<"answer is '{:-010G}'">(SV("answer is '       NAN'"), nan_pos);
2193   check.template operator()<"answer is '{:+010G}'">(SV("answer is '      +NAN'"), nan_pos);
2194   check.template operator()<"answer is '{: 010G}'">(SV("answer is '       NAN'"), nan_pos);
2195 
2196   check.template operator()<"answer is '{:010G}'">(SV("answer is '      -NAN'"), nan_neg);
2197   check.template operator()<"answer is '{:-010G}'">(SV("answer is '      -NAN'"), nan_neg);
2198   check.template operator()<"answer is '{:+010G}'">(SV("answer is '      -NAN'"), nan_neg);
2199   check.template operator()<"answer is '{: 010G}'">(SV("answer is '      -NAN'"), nan_neg);
2200 
2201   // *** precision ***
2202   check.template operator()<"answer is '{:.0G}'">(SV("answer is '0.03'"), 0.03125);
2203   check.template operator()<"answer is '{:.1G}'">(SV("answer is '0.03'"), 0.03125);
2204   check.template operator()<"answer is '{:.2G}'">(SV("answer is '0.031'"), 0.03125);
2205   check.template operator()<"answer is '{:.3G}'">(SV("answer is '0.0312'"), 0.03125);
2206   check.template operator()<"answer is '{:.4G}'">(SV("answer is '0.03125'"), 0.03125);
2207   check.template operator()<"answer is '{:.5G}'">(SV("answer is '0.03125'"), 0.03125);
2208   check.template operator()<"answer is '{:.10G}'">(SV("answer is '0.03125'"), 0.03125);
2209 
2210   // *** locale-specific form ***
2211   // See locale-specific_form.pass.cpp
2212 }
2213 
2214 template <class F, class CharT, class TestFunction>
2215 void format_test_floating_point_default(TestFunction check) {
2216   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
2217   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
2218 
2219   // *** align-fill & width ***
2220   check.template operator()<"answer is '{:7}'">(SV("answer is '   0.25'"), F(0.25));
2221   check.template operator()<"answer is '{:>7}'">(SV("answer is '   0.25'"), F(0.25));
2222   check.template operator()<"answer is '{:<7}'">(SV("answer is '0.25   '"), F(0.25));
2223   check.template operator()<"answer is '{:^7}'">(SV("answer is ' 0.25  '"), F(0.25));
2224 
2225   check.template operator()<"answer is '{:->8}'">(SV("answer is '---0.125'"), F(125e-3));
2226   check.template operator()<"answer is '{:-<8}'">(SV("answer is '0.125---'"), F(125e-3));
2227   check.template operator()<"answer is '{:-^8}'">(SV("answer is '-0.125--'"), F(125e-3));
2228 
2229   check.template operator()<"answer is '{:*>6}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
2230   check.template operator()<"answer is '{:*<6}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
2231   check.template operator()<"answer is '{:*^6}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
2232 
2233   check.template operator()<"answer is '{:#>7}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
2234   check.template operator()<"answer is '{:#<7}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
2235   check.template operator()<"answer is '{:#^7}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
2236 
2237   check.template operator()<"answer is '{:^>6}'">(SV("answer is '^^^nan'"), nan_pos);
2238   check.template operator()<"answer is '{:^<6}'">(SV("answer is 'nan^^^'"), nan_pos);
2239   check.template operator()<"answer is '{:^^6}'">(SV("answer is '^nan^^'"), nan_pos);
2240 
2241   check.template operator()<"answer is '{:0>7}'">(SV("answer is '000-nan'"), nan_neg);
2242   check.template operator()<"answer is '{:0<7}'">(SV("answer is '-nan000'"), nan_neg);
2243   check.template operator()<"answer is '{:0^7}'">(SV("answer is '0-nan00'"), nan_neg);
2244 
2245   // Test whether zero padding is ignored
2246   check.template operator()<"answer is '{:>07}'">(SV("answer is '   0.25'"), F(0.25));
2247   check.template operator()<"answer is '{:<07}'">(SV("answer is '0.25   '"), F(0.25));
2248   check.template operator()<"answer is '{:^07}'">(SV("answer is ' 0.25  '"), F(0.25));
2249 
2250   // *** Sign ***
2251   check.template operator()<"answer is '{:}'">(SV("answer is '0'"), F(0));
2252   check.template operator()<"answer is '{:-}'">(SV("answer is '0'"), F(0));
2253   check.template operator()<"answer is '{:+}'">(SV("answer is '+0'"), F(0));
2254   check.template operator()<"answer is '{: }'">(SV("answer is ' 0'"), F(0));
2255 
2256   check.template operator()<"answer is '{:}'">(SV("answer is '-0'"), F(-0.));
2257   check.template operator()<"answer is '{:-}'">(SV("answer is '-0'"), F(-0.));
2258   check.template operator()<"answer is '{:+}'">(SV("answer is '-0'"), F(-0.));
2259   check.template operator()<"answer is '{: }'">(SV("answer is '-0'"), F(-0.));
2260 
2261   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
2262   check.template operator()<"answer is '{:}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2263   check.template operator()<"answer is '{:-}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2264   check.template operator()<"answer is '{:+}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
2265   check.template operator()<"answer is '{: }'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
2266 
2267   check.template operator()<"answer is '{:}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2268   check.template operator()<"answer is '{:-}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2269   check.template operator()<"answer is '{:+}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2270   check.template operator()<"answer is '{: }'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2271 
2272   check.template operator()<"answer is '{:}'">(SV("answer is 'nan'"), nan_pos);
2273   check.template operator()<"answer is '{:-}'">(SV("answer is 'nan'"), nan_pos);
2274   check.template operator()<"answer is '{:+}'">(SV("answer is '+nan'"), nan_pos);
2275   check.template operator()<"answer is '{: }'">(SV("answer is ' nan'"), nan_pos);
2276 
2277   check.template operator()<"answer is '{:}'">(SV("answer is '-nan'"), nan_neg);
2278   check.template operator()<"answer is '{:-}'">(SV("answer is '-nan'"), nan_neg);
2279   check.template operator()<"answer is '{:+}'">(SV("answer is '-nan'"), nan_neg);
2280   check.template operator()<"answer is '{: }'">(SV("answer is '-nan'"), nan_neg);
2281 
2282   // *** alternate form ***
2283   check.template operator()<"answer is '{:#}'">(SV("answer is '0.'"), F(0));
2284   check.template operator()<"answer is '{:#}'">(SV("answer is '2.5'"), F(2.5));
2285 
2286   check.template operator()<"answer is '{:#}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2287   check.template operator()<"answer is '{:#}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2288 
2289   check.template operator()<"answer is '{:#}'">(SV("answer is 'nan'"), nan_pos);
2290   check.template operator()<"answer is '{:#}'">(SV("answer is '-nan'"), nan_neg);
2291 
2292   // *** zero-padding & width ***
2293   check.template operator()<"answer is '{:07}'">(SV("answer is '0.03125'"), 0.03125);
2294   check.template operator()<"answer is '{:+07}'">(SV("answer is '+0.03125'"), 0.03125);
2295   check.template operator()<"answer is '{:+08}'">(SV("answer is '+0.03125'"), 0.03125);
2296   check.template operator()<"answer is '{:+09}'">(SV("answer is '+00.03125'"), 0.03125);
2297 
2298   check.template operator()<"answer is '{:010}'">(SV("answer is '0000.03125'"), 0.03125);
2299   check.template operator()<"answer is '{:-010}'">(SV("answer is '0000.03125'"), 0.03125);
2300   check.template operator()<"answer is '{:+010}'">(SV("answer is '+000.03125'"), 0.03125);
2301   check.template operator()<"answer is '{: 010}'">(SV("answer is ' 000.03125'"), 0.03125);
2302 
2303   check.template operator()<"answer is '{:010}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2304   check.template operator()<"answer is '{:-010}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2305   check.template operator()<"answer is '{:+010}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
2306   check.template operator()<"answer is '{: 010}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2307 
2308   check.template operator()<"answer is '{:010}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2309   check.template operator()<"answer is '{:-010}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2310   check.template operator()<"answer is '{:+010}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2311   check.template operator()<"answer is '{: 010}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2312 
2313   check.template operator()<"answer is '{:010}'">(SV("answer is '       nan'"), nan_pos);
2314   check.template operator()<"answer is '{:-010}'">(SV("answer is '       nan'"), nan_pos);
2315   check.template operator()<"answer is '{:+010}'">(SV("answer is '      +nan'"), nan_pos);
2316   check.template operator()<"answer is '{: 010}'">(SV("answer is '       nan'"), nan_pos);
2317 
2318   check.template operator()<"answer is '{:010}'">(SV("answer is '      -nan'"), nan_neg);
2319   check.template operator()<"answer is '{:-010}'">(SV("answer is '      -nan'"), nan_neg);
2320   check.template operator()<"answer is '{:+010}'">(SV("answer is '      -nan'"), nan_neg);
2321   check.template operator()<"answer is '{: 010}'">(SV("answer is '      -nan'"), nan_neg);
2322 
2323   // *** precision ***
2324   // See format_test_floating_point_default_precision
2325 
2326   // *** locale-specific form ***
2327   // See locale-specific_form.pass.cpp
2328 }
2329 
2330 template <class F, class CharT, class TestFunction>
2331 void format_test_floating_point_default_precision(TestFunction check) {
2332 
2333   auto nan_pos = std::numeric_limits<F>::quiet_NaN(); // "nan"
2334   auto nan_neg = std::copysign(nan_pos, -1.0);        // "-nan"
2335 
2336   // *** align-fill & width ***
2337   check.template operator()<"answer is '{:7.6}'">(SV("answer is '   0.25'"), F(0.25));
2338   check.template operator()<"answer is '{:>7.6}'">(SV("answer is '   0.25'"), F(0.25));
2339   check.template operator()<"answer is '{:<7.6}'">(SV("answer is '0.25   '"), F(0.25));
2340   check.template operator()<"answer is '{:^7.6}'">(SV("answer is ' 0.25  '"), F(0.25));
2341 
2342   check.template operator()<"answer is '{:->8.6}'">(SV("answer is '---0.125'"), F(125e-3));
2343   check.template operator()<"answer is '{:-<8.6}'">(SV("answer is '0.125---'"), F(125e-3));
2344   check.template operator()<"answer is '{:-^8.6}'">(SV("answer is '-0.125--'"), F(125e-3));
2345 
2346   check.template operator()<"answer is '{:*>6.6}'">(SV("answer is '***inf'"), std::numeric_limits<F>::infinity());
2347   check.template operator()<"answer is '{:*<6.6}'">(SV("answer is 'inf***'"), std::numeric_limits<F>::infinity());
2348   check.template operator()<"answer is '{:*^6.6}'">(SV("answer is '*inf**'"), std::numeric_limits<F>::infinity());
2349 
2350   check.template operator()<"answer is '{:#>7.6}'">(SV("answer is '###-inf'"), -std::numeric_limits<F>::infinity());
2351   check.template operator()<"answer is '{:#<7.6}'">(SV("answer is '-inf###'"), -std::numeric_limits<F>::infinity());
2352   check.template operator()<"answer is '{:#^7.6}'">(SV("answer is '#-inf##'"), -std::numeric_limits<F>::infinity());
2353 
2354   check.template operator()<"answer is '{:^>6.6}'">(SV("answer is '^^^nan'"), nan_pos);
2355   check.template operator()<"answer is '{:^<6.6}'">(SV("answer is 'nan^^^'"), nan_pos);
2356   check.template operator()<"answer is '{:^^6.6}'">(SV("answer is '^nan^^'"), nan_pos);
2357 
2358   check.template operator()<"answer is '{:0>7.6}'">(SV("answer is '000-nan'"), nan_neg);
2359   check.template operator()<"answer is '{:0<7.6}'">(SV("answer is '-nan000'"), nan_neg);
2360   check.template operator()<"answer is '{:0^7.6}'">(SV("answer is '0-nan00'"), nan_neg);
2361 
2362   // Test whether zero padding is ignored
2363   check.template operator()<"answer is '{:>07.6}'">(SV("answer is '   0.25'"), F(0.25));
2364   check.template operator()<"answer is '{:<07.6}'">(SV("answer is '0.25   '"), F(0.25));
2365   check.template operator()<"answer is '{:^07.6}'">(SV("answer is ' 0.25  '"), F(0.25));
2366 
2367   // *** Sign ***
2368   check.template operator()<"answer is '{:.6}'">(SV("answer is '0'"), F(0));
2369   check.template operator()<"answer is '{:-.6}'">(SV("answer is '0'"), F(0));
2370   check.template operator()<"answer is '{:+.6}'">(SV("answer is '+0'"), F(0));
2371   check.template operator()<"answer is '{: .6}'">(SV("answer is ' 0'"), F(0));
2372 
2373   check.template operator()<"answer is '{:.6}'">(SV("answer is '-0'"), F(-0.));
2374   check.template operator()<"answer is '{:-.6}'">(SV("answer is '-0'"), F(-0.));
2375   check.template operator()<"answer is '{:+.6}'">(SV("answer is '-0'"), F(-0.));
2376   check.template operator()<"answer is '{: .6}'">(SV("answer is '-0'"), F(-0.));
2377 
2378   // [format.string.std]/5 The sign option applies to floating-point infinity and NaN.
2379   check.template operator()<"answer is '{:.6}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2380   check.template operator()<"answer is '{:-.6}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2381   check.template operator()<"answer is '{:+.6}'">(SV("answer is '+inf'"), std::numeric_limits<F>::infinity());
2382   check.template operator()<"answer is '{: .6}'">(SV("answer is ' inf'"), std::numeric_limits<F>::infinity());
2383 
2384   check.template operator()<"answer is '{:.6}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2385   check.template operator()<"answer is '{:-.6}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2386   check.template operator()<"answer is '{:+.6}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2387   check.template operator()<"answer is '{: .6}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2388 
2389   check.template operator()<"answer is '{:.6}'">(SV("answer is 'nan'"), nan_pos);
2390   check.template operator()<"answer is '{:-.6}'">(SV("answer is 'nan'"), nan_pos);
2391   check.template operator()<"answer is '{:+.6}'">(SV("answer is '+nan'"), nan_pos);
2392   check.template operator()<"answer is '{: .6}'">(SV("answer is ' nan'"), nan_pos);
2393 
2394   check.template operator()<"answer is '{:.6}'">(SV("answer is '-nan'"), nan_neg);
2395   check.template operator()<"answer is '{:-.6}'">(SV("answer is '-nan'"), nan_neg);
2396   check.template operator()<"answer is '{:+.6}'">(SV("answer is '-nan'"), nan_neg);
2397   check.template operator()<"answer is '{: .6}'">(SV("answer is '-nan'"), nan_neg);
2398 
2399   // *** alternate form **
2400   // When precision is zero there's no decimal point except when the alternate form is specified.
2401   check.template operator()<"answer is '{:.0}'">(SV("answer is '0'"), F(0));
2402   check.template operator()<"answer is '{:#.0}'">(SV("answer is '0.'"), F(0));
2403 
2404   check.template operator()<"answer is '{:#.6}'">(SV("answer is '0.'"), F(0));
2405   check.template operator()<"answer is '{:#.6}'">(SV("answer is '2.5'"), F(2.5));
2406 
2407   check.template operator()<"answer is '{:#.6}'">(SV("answer is 'inf'"), std::numeric_limits<F>::infinity());
2408   check.template operator()<"answer is '{:#.6}'">(SV("answer is '-inf'"), -std::numeric_limits<F>::infinity());
2409 
2410   check.template operator()<"answer is '{:#.6}'">(SV("answer is 'nan'"), nan_pos);
2411   check.template operator()<"answer is '{:#.6}'">(SV("answer is '-nan'"), nan_neg);
2412 
2413   // *** zero-padding & width ***
2414   check.template operator()<"answer is '{:06.6}'">(SV("answer is '0.03125'"), 0.03125);
2415   check.template operator()<"answer is '{:+06.6}'">(SV("answer is '+0.03125'"), 0.03125);
2416   check.template operator()<"answer is '{:+07.6}'">(SV("answer is '+0.03125'"), 0.03125);
2417   check.template operator()<"answer is '{:+08.6}'">(SV("answer is '+0.03125'"), 0.03125);
2418 
2419   check.template operator()<"answer is '{:09.6}'">(SV("answer is '000.03125'"), 0.03125);
2420   check.template operator()<"answer is '{:-09.6}'">(SV("answer is '000.03125'"), 0.03125);
2421   check.template operator()<"answer is '{:+09.6}'">(SV("answer is '+00.03125'"), 0.03125);
2422   check.template operator()<"answer is '{: 09.6}'">(SV("answer is ' 00.03125'"), 0.03125);
2423 
2424   check.template operator()<"answer is '{:010.6}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2425   check.template operator()<"answer is '{:-010.6}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2426   check.template operator()<"answer is '{:+010.6}'">(SV("answer is '      +inf'"), std::numeric_limits<F>::infinity());
2427   check.template operator()<"answer is '{: 010.6}'">(SV("answer is '       inf'"), std::numeric_limits<F>::infinity());
2428 
2429   check.template operator()<"answer is '{:010.6}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2430   check.template operator()<"answer is '{:-010.6}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2431   check.template operator()<"answer is '{:+010.6}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2432   check.template operator()<"answer is '{: 010.6}'">(SV("answer is '      -inf'"), -std::numeric_limits<F>::infinity());
2433 
2434   check.template operator()<"answer is '{:010.6}'">(SV("answer is '       nan'"), nan_pos);
2435   check.template operator()<"answer is '{:-010.6}'">(SV("answer is '       nan'"), nan_pos);
2436   check.template operator()<"answer is '{:+010.6}'">(SV("answer is '      +nan'"), nan_pos);
2437   check.template operator()<"answer is '{: 010.6}'">(SV("answer is '       nan'"), nan_pos);
2438 
2439   check.template operator()<"answer is '{:010.6}'">(SV("answer is '      -nan'"), nan_neg);
2440   check.template operator()<"answer is '{:-010.6}'">(SV("answer is '      -nan'"), nan_neg);
2441   check.template operator()<"answer is '{:+010.6}'">(SV("answer is '      -nan'"), nan_neg);
2442   check.template operator()<"answer is '{: 010.6}'">(SV("answer is '      -nan'"), nan_neg);
2443 
2444   // *** precision ***
2445   check.template operator()<"answer is '{:.0}'">(SV("answer is '0.03'"), 0.03125);
2446   check.template operator()<"answer is '{:.1}'">(SV("answer is '0.03'"), 0.03125);
2447   check.template operator()<"answer is '{:.2}'">(SV("answer is '0.031'"), 0.03125);
2448   check.template operator()<"answer is '{:.3}'">(SV("answer is '0.0312'"), 0.03125);
2449   check.template operator()<"answer is '{:.4}'">(SV("answer is '0.03125'"), 0.03125);
2450   check.template operator()<"answer is '{:.5}'">(SV("answer is '0.03125'"), 0.03125);
2451   check.template operator()<"answer is '{:.10}'">(SV("answer is '0.03125'"), 0.03125);
2452 
2453   // *** locale-specific form ***
2454   // See locale-specific_form.pass.cpp
2455 }
2456 
2457 template <class F, class CharT, class TestFunction, class ExceptionTest>
2458 void format_test_floating_point(TestFunction check, ExceptionTest check_exception) {
2459   format_test_floating_point_hex_lower_case<F, CharT>(check);
2460   format_test_floating_point_hex_upper_case<F, CharT>(check);
2461   format_test_floating_point_hex_lower_case_precision<F, CharT>(check);
2462   format_test_floating_point_hex_upper_case_precision<F, CharT>(check);
2463 
2464   format_test_floating_point_scientific_lower_case<F, CharT>(check);
2465   format_test_floating_point_scientific_upper_case<F, CharT>(check);
2466 
2467   format_test_floating_point_fixed_lower_case<F, CharT>(check);
2468   format_test_floating_point_fixed_upper_case<F, CharT>(check);
2469 
2470   format_test_floating_point_general_lower_case<F, CharT>(check);
2471   format_test_floating_point_general_upper_case<F, CharT>(check);
2472 
2473   format_test_floating_point_default<F, CharT>(check);
2474   format_test_floating_point_default_precision<F, CharT>(check);
2475 
2476   // *** type ***
2477   for (const auto& fmt : invalid_types<CharT>("aAeEfFgG"))
2478     check_exception("The format-spec type has a type not supported for a floating-point argument", fmt, F(1));
2479 }
2480 
2481 template <class CharT, class TestFunction, class ExceptionTest>
2482 void format_test_floating_point(TestFunction check, ExceptionTest check_exception) {
2483   format_test_floating_point<float, CharT>(check, check_exception);
2484   format_test_floating_point<double, CharT>(check, check_exception);
2485   format_test_floating_point<long double, CharT>(check, check_exception);
2486 }
2487 
2488 template <class P, class CharT, class TestFunction, class ExceptionTest>
2489 void format_test_pointer(TestFunction check, ExceptionTest check_exception) {
2490   // *** align-fill & width ***
2491   check.template operator()<"answer is '{:6}'">(SV("answer is '   0x0'"), P(nullptr));
2492   check.template operator()<"answer is '{:>6}'">(SV("answer is '   0x0'"), P(nullptr));
2493   check.template operator()<"answer is '{:<6}'">(SV("answer is '0x0   '"), P(nullptr));
2494   check.template operator()<"answer is '{:^6}'">(SV("answer is ' 0x0  '"), P(nullptr));
2495 
2496   check.template operator()<"answer is '{:->6}'">(SV("answer is '---0x0'"), P(nullptr));
2497   check.template operator()<"answer is '{:-<6}'">(SV("answer is '0x0---'"), P(nullptr));
2498   check.template operator()<"answer is '{:-^6}'">(SV("answer is '-0x0--'"), P(nullptr));
2499 
2500   // *** Sign ***
2501   check_exception("The format-spec should consume the input or end with a '}'", SV("{:-}"), P(nullptr));
2502   check_exception("The format-spec should consume the input or end with a '}'", SV("{:+}"), P(nullptr));
2503   check_exception("The format-spec should consume the input or end with a '}'", SV("{: }"), P(nullptr));
2504 
2505   // *** alternate form ***
2506   check_exception("The format-spec should consume the input or end with a '}'", SV("{:#}"), P(nullptr));
2507 
2508   // *** zero-padding ***
2509   check_exception("A format-spec width field shouldn't have a leading zero", SV("{:0}"), P(nullptr));
2510 
2511   // *** precision ***
2512   check_exception("The format-spec should consume the input or end with a '}'", SV("{:.}"), P(nullptr));
2513 
2514   // *** locale-specific form ***
2515   check_exception("The format-spec should consume the input or end with a '}'", SV("{:L}"), P(nullptr));
2516 
2517   // *** type ***
2518   for (const auto& fmt : invalid_types<CharT>("p"))
2519     check_exception("The format-spec type has a type not supported for a pointer argument", fmt, P(nullptr));
2520 }
2521 
2522 template <class CharT, class TestFunction, class ExceptionTest>
2523 void format_test_handle(TestFunction check, ExceptionTest check_exception) {
2524   // *** Valid permuatations ***
2525   check.template operator()<"answer is '{}'">(SV("answer is '0xaaaa'"), status::foo);
2526   check.template operator()<"answer is '{:x}'">(SV("answer is '0xaaaa'"), status::foo);
2527   check.template operator()<"answer is '{:X}'">(SV("answer is '0XAAAA'"), status::foo);
2528   check.template operator()<"answer is '{:s}'">(SV("answer is 'foo'"), status::foo);
2529 
2530   check.template operator()<"answer is '{}'">(SV("answer is '0x5555'"), status::bar);
2531   check.template operator()<"answer is '{:x}'">(SV("answer is '0x5555'"), status::bar);
2532   check.template operator()<"answer is '{:X}'">(SV("answer is '0X5555'"), status::bar);
2533   check.template operator()<"answer is '{:s}'">(SV("answer is 'bar'"), status::bar);
2534 
2535   check.template operator()<"answer is '{}'">(SV("answer is '0xaa55'"), status::foobar);
2536   check.template operator()<"answer is '{:x}'">(SV("answer is '0xaa55'"), status::foobar);
2537   check.template operator()<"answer is '{:X}'">(SV("answer is '0XAA55'"), status::foobar);
2538   check.template operator()<"answer is '{:s}'">(SV("answer is 'foobar'"), status::foobar);
2539 
2540   // P2418 Changed the argument from a const reference to a forwarding reference.
2541   // This mainly affects handle classes, however since we use an abstraction
2542   // layer here it's "tricky" to verify whether this test would do the "right"
2543   // thing. So these tests are done separately.
2544 
2545   // *** type ***
2546   for (const auto& fmt : invalid_types<CharT>("xXs"))
2547     check_exception("The format-spec type has a type not supported for a status argument", fmt, status::foo);
2548 }
2549 
2550 template <class CharT, class TestFunction, class ExceptionTest>
2551 void format_test_pointer(TestFunction check, ExceptionTest check_exception) {
2552   format_test_pointer<std::nullptr_t, CharT>(check, check_exception);
2553   format_test_pointer<void*, CharT>(check, check_exception);
2554   format_test_pointer<const void*, CharT>(check, check_exception);
2555 }
2556 
2557 template <class CharT, class TestFunction, class ExceptionTest>
2558 void format_tests(TestFunction check, ExceptionTest check_exception) {
2559   // *** Test escaping  ***
2560 
2561   check.template operator()<"{{">(SV("{"));
2562   check.template operator()<"}}">(SV("}"));
2563 
2564   // *** Test argument ID ***
2565   check.template operator()<"hello {0:} {1:}">(SV("hello false true"), false, true);
2566   check.template operator()<"hello {1:} {0:}">(SV("hello true false"), false, true);
2567 
2568   // *** Test many arguments ***
2569 
2570   // [format.args]/1
2571   // An instance of basic_format_args provides access to formatting arguments.
2572   // Implementations should optimize the representation of basic_format_args
2573   // for a small number of formatting arguments.
2574   //
2575   // These's no guidances what "a small number of formatting arguments" is.
2576   // - fmtlib uses a 15 elements
2577   // - libc++ uses 12 elements
2578   // - MSVC STL uses a different approach regardless of the number of arguments
2579   // - libstdc++ has no implementation yet
2580   // fmtlib and libc++ use a similar approach, this approach can support 16
2581   // elements (based on design choices both support less elements). This test
2582   // makes sure "the large number of formatting arguments" code path is tested.
2583   check.template operator()<"{}{}{}{}{}{}{}{}{}{}\t{}{}{}{}{}{}{}{}{}{}">(SV("1234567890\t1234567890"), 1, 2, 3, 4, 5,
2584                                                                           6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
2585 
2586   // ** Test invalid format strings ***
2587   check_exception("The format string terminates at a '{'", SV("{"));
2588   check_exception("The replacement field misses a terminating '}'", SV("{:"), 42);
2589 
2590   check_exception("The format string contains an invalid escape sequence", SV("}"));
2591   check_exception("The format string contains an invalid escape sequence", SV("{:}-}"), 42);
2592 
2593   check_exception("The format string contains an invalid escape sequence", SV("} "));
2594 
2595   check_exception("The arg-id of the format-spec starts with an invalid character", SV("{-"), 42);
2596   check_exception("Argument index out of bounds", SV("hello {}"));
2597   check_exception("Argument index out of bounds", SV("hello {0}"));
2598   check_exception("Argument index out of bounds", SV("hello {1}"), 42);
2599 
2600   // *** Test char format argument ***
2601   // The `char` to `wchar_t` formatting is tested separately.
2602   check.template operator()<"hello {}{}{}{}{}{}{}">(
2603       SV("hello 09azAZ!"), CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'));
2604   format_test_char<CharT>(check, check_exception);
2605   format_test_char_as_integer<CharT>(check, check_exception);
2606 
2607   // *** Test string format argument ***
2608   {
2609     CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0};
2610     CharT* data = buffer;
2611     check.template operator()<"hello {}">(SV("hello 09azAZ!"), data);
2612   }
2613   {
2614     CharT buffer[] = {CharT('0'), CharT('9'), CharT('a'), CharT('z'), CharT('A'), CharT('Z'), CharT('!'), 0};
2615     const CharT* data = buffer;
2616     check.template operator()<"hello {}">(SV("hello 09azAZ!"), data);
2617   }
2618   {
2619     std::basic_string<CharT> data = STR("world");
2620     check.template operator()<"hello {}">(SV("hello world"), data);
2621   }
2622   {
2623     std::basic_string<CharT> buffer = STR("world");
2624     std::basic_string_view<CharT> data = buffer;
2625     check.template operator()<"hello {}">(SV("hello world"), data);
2626   }
2627   format_string_tests<CharT>(check, check_exception);
2628 
2629   // *** Test Boolean format argument ***
2630   check.template operator()<"hello {} {}">(SV("hello false true"), false, true);
2631 
2632   format_test_bool<CharT>(check, check_exception);
2633   format_test_bool_as_integer<CharT>(check, check_exception);
2634 
2635   // *** Test signed integral format argument ***
2636   check.template operator()<"hello {}">(SV("hello 42"), static_cast<signed char>(42));
2637   check.template operator()<"hello {}">(SV("hello 42"), static_cast<short>(42));
2638   check.template operator()<"hello {}">(SV("hello 42"), static_cast<int>(42));
2639   check.template operator()<"hello {}">(SV("hello 42"), static_cast<long>(42));
2640   check.template operator()<"hello {}">(SV("hello 42"), static_cast<long long>(42));
2641 #ifndef TEST_HAS_NO_INT128
2642   check.template operator()<"hello {}">(SV("hello 42"), static_cast<__int128_t>(42));
2643 #endif
2644   format_test_signed_integer<CharT>(check, check_exception);
2645 
2646   // ** Test unsigned integral format argument ***
2647   check.template operator()<"hello {}">(SV("hello 42"), static_cast<unsigned char>(42));
2648   check.template operator()<"hello {}">(SV("hello 42"), static_cast<unsigned short>(42));
2649   check.template operator()<"hello {}">(SV("hello 42"), static_cast<unsigned>(42));
2650   check.template operator()<"hello {}">(SV("hello 42"), static_cast<unsigned long>(42));
2651   check.template operator()<"hello {}">(SV("hello 42"), static_cast<unsigned long long>(42));
2652 #ifndef TEST_HAS_NO_INT128
2653   check.template operator()<"hello {}">(SV("hello 42"), static_cast<__uint128_t>(42));
2654 #endif
2655   format_test_unsigned_integer<CharT>(check, check_exception);
2656 
2657   // *** Test floating point format argument ***
2658   check.template operator()<"hello {}">(SV("hello 42"), static_cast<float>(42));
2659   check.template operator()<"hello {}">(SV("hello 42"), static_cast<double>(42));
2660   check.template operator()<"hello {}">(SV("hello 42"), static_cast<long double>(42));
2661   format_test_floating_point<CharT>(check, check_exception);
2662 
2663   // *** Test pointer formater argument ***
2664   check.template operator()<"hello {}">(SV("hello 0x0"), nullptr);
2665   check.template operator()<"hello {}">(SV("hello 0x42"), reinterpret_cast<void*>(0x42));
2666   check.template operator()<"hello {}">(SV("hello 0x42"), reinterpret_cast<const void*>(0x42));
2667   format_test_pointer<CharT>(check, check_exception);
2668 
2669   // *** Test handle formatter argument ***
2670   format_test_handle<CharT>(check, check_exception);
2671 }
2672 
2673 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
2674 template <class TestFunction>
2675 void format_tests_char_to_wchar_t(TestFunction check) {
2676   using CharT = wchar_t;
2677   check.template operator()<"hello {}{}{}{}{}">(SV("hello 09azA"), '0', '9', 'a', 'z', 'A');
2678 }
2679 #endif
2680 
2681 #endif
2682