Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
22.locale.synopsis.cpp
Go to the documentation of this file.
1
29#include <rw/_defs.h>
30
31// disable implicit inclusion to work around a limitation in
32// IBM VAC++ 5.0.2.0 (PR #26959)
33#if defined __IBMCPP__ && !defined _RWSTD_NO_IMPLICIT_INCLUSION
34# define _RWSTD_NO_IMPLICIT_INCLUSION
35#endif
36
37// make protected members accessible if possible
38#if defined _RWSTD_NO_EXPORT && !defined _MSC_VER
39# define protected public
40#endif
41
42#include <iterator>
43#include <locale>
44
45#include <rw_driver.h>
46
47static void
48test_lc_defs ()
49{
50 rw_info (0, __FILE__, __LINE__, "checking LC_XXX constants");
51
52 // check that <locale> doesn't introduce any LC_XXX constants
53 // (not required, but it's good practice to keep headers clean)
54 static const char* const lc_defs[] =
55 {
56#ifdef LC_ALL
57 "LC_ALL",
58#endif // LC_ALL
59#ifdef LC_COLLATE
60 "LC_COLLATE",
61#endif // LC_COLLATE
62#ifdef LC_CTYPE
63 "LC_CTYPE",
64#endif // LC_CTYPE
65#ifdef LC_MONETARY
66 "LC_MONETARY",
67#endif // LC_MONETARY
68#ifdef LC_NUMERIC
69 "LC_NUMERIC",
70#endif // LC_NUMERIC
71#ifdef LC_TIME
72 "LC_TIME",
73#endif // LC_TIME
74#ifdef LC_MESSAGES
75 "LC_MESSAGES",
76#endif // LC_MESSAGES
77
78 0
79 };
80
81 for (unsigned i = 0; i != sizeof lc_defs / sizeof *lc_defs; ++i) {
82 rw_assert (!lc_defs [i], __FILE__, __LINE__,
83 "<locale> unexpectedly #defines %s", lc_defs [i]);
84 }
85}
86
87static void
88test_isxxx ()
89{
90 rw_info (0, __FILE__, __LINE__, "checking isxxx() macros");
91
92 // check that <locale> doesn't introduce any isxxx() macros
93 static const char* const isxxx[] =
94 {
95#ifdef isspace
96 "isspace",
97#endif // isspace
98#ifdef isprint
99 "isprint",
100#endif // isprint
101#ifdef iscntrl
102 "iscntrl",
103#endif // iscntrl
104#ifdef isupper
105 "isupper",
106#endif // isupper
107#ifdef islower
108 "islower",
109#endif // islower
110#ifdef isalpha
111 "isalpha",
112#endif // isalpha
113#ifdef isdigit
114 "isdigit",
115#endif // isdigit
116#ifdef ispunct
117 "ispunct",
118#endif // ispunct
119#ifdef isxdigit
120 "isxdigit",
121#endif // isxdigit
122#ifdef isalnum
123 "isalnum",
124#endif // isalnum
125#ifdef isgraph
126 "isgraph",
127#endif // isgraph
128#ifdef toupper
129 "toupper",
130#endif // toupper
131#ifdef tolower
132 "tolower",
133#endif // tolower
134
135 0
136 };
137
138 for (unsigned i = 0; i != sizeof isxxx / sizeof *isxxx; ++i) {
139 rw_assert (!isxxx [i], __FILE__, __LINE__,
140 "<locale> unexpectedly #defines %s", isxxx [i]);
141 }
142}
143
144
146#include <clocale> // for LC_XXX macros
147#include <cwchar> // for mbstate_t
148
149#if !defined LC_MESSAGES && defined _RWSTD_LC_MESSAGES
150# define LC_MESSAGES _RWSTD_LC_MESSAGES
151#endif // !LC_MESSAGES && _RWSTD_LC_MESSAGES
152
153// exercise the signature of a nonmember (or static member) function
154#define FUN(result, name, arg_list) do { \
155 /* make name unique to prevent bogus gcc -Wshadow warnings */ \
156 result (*_RWSTD_PASTE (pf, __LINE__)) arg_list = &name; \
157 _RWSTD_UNUSED (_RWSTD_PASTE (pf, __LINE__)); \
158 } while (0)
159
160
162// exercise the signatures of std::{has,use}_facet<>()
163template <class charT>
164static void
165test_have_use_facet ()
166{
167 rw_info (0, __FILE__, __LINE__,
168 "std::has_facet<Facet>(std::locale&) synopsis");
169 rw_info (0, __FILE__, __LINE__,
170 "std::use_facet<Facet>(std::locale&) synopsis");
171
172#if !defined __HP_aCC || __HP_aCC > 33100
173
174// working around an HP aCC bug (see PR #23312)
175
176# if !(defined __GNUG__ || __GNUG__ > 2 || __GNUC_MINOR__ > 96) \
177 && !(defined _MSC_VER || _MSC_VER >= 0x1300)
178
179 // working around a gcc 2.9{5,6} ICE
180 // working around an MSVC 6.0 bug (PR #26307)
181 FUN (const std::ctype<charT>&,
182 std::use_facet<std::ctype<charT> >, (const std::locale&));
183 FUN (bool, std::has_facet<std::ctype<charT> >, (const std::locale&));
184
185# endif // gcc > 2.96 && MSVC > 6.0
186
187#endif // __HP_aCC > 33000
188}
189
190
192// exercise the signatures of the convenience locale interfaces
193template <class charT>
194static void
195test_convenience_funs ()
196{
197 rw_info (0, __FILE__, __LINE__,
198 "std::isxxx(std::locale&) convenience functions synopsis");
199
200 FUN (bool, std::isspace, (charT, const std::locale&));
201 FUN (bool, std::isprint, (charT, const std::locale&));
202 FUN (bool, std::iscntrl, (charT, const std::locale&));
203 FUN (bool, std::isupper, (charT, const std::locale&));
204 FUN (bool, std::islower, (charT, const std::locale&));
205 FUN (bool, std::isalpha, (charT, const std::locale&));
206 FUN (bool, std::isdigit, (charT, const std::locale&));
207 FUN (bool, std::ispunct, (charT, const std::locale&));
208 FUN (bool, std::isxdigit, (charT, const std::locale&));
209 FUN (bool, std::isalnum, (charT, const std::locale&));
210 FUN (bool, std::isgraph, (charT, const std::locale&));
211 FUN (charT, std::toupper, (charT, const std::locale&));
212 FUN (charT, std::tolower, (charT, const std::locale&));
213}
214
216
217#if !defined _MSC_VER
218
219// verify that specializations are present in the lib
220_RWSTD_SPECIALIZED_CLASS class ctype<char>;
221_RWSTD_SPECIALIZED_CLASS class ctype_byname<char>;
222
223# ifndef _RWSTD_NO_WCHAR_T
224
226_RWSTD_SPECIALIZED_CLASS class ctype_byname<wchar_t>;
227
228# endif // _RWSTD_NO_WCHAR_T
229
230#endif // _MSC_VER
231
232} // namespace std
233
234
236// test for the presence of the required facet templates
237// and their specializations (as required by Table 52)
238template <class charT>
239static void
240test_facets ()
241{
242 // introduce a typedef to work around a SunPro 5.3 bug (see PR #25967)
243 typedef charT char_type;
244
245 const std::locale::facet *pfac;
246 _RWSTD_UNUSED (pfac);
247
248 {
249 // collate category
250 const std::collate<char_type> *col = 0;
251 const std::collate_byname<char_type> *col_byname = 0;
252
253 // verify that facet publicly derives from locale::facet
254 pfac = col;
255 col = col_byname;
256 }
257
258 {
259 // ctype category
260
261 // force a link failure if required specializations aren't
262 // provided (e.g., if only the primary template is defined)
263 const std::ctype<char_type> *ctp = 0;
264 const std::ctype_byname<char_type> *ctp_byname = 0;
265
266 // verify that facet publicly derives from locale::facet
267 const std::ctype_base *ctpbase = ctp;
268 pfac = ctp;
269 ctp = ctp_byname;
270
271 _RWSTD_UNUSED (ctpbase);
272 }
273
274 {
275 const std::codecvt<char_type, char, std::mbstate_t> *cvt = 0;
276 const std::codecvt_byname<char_type, char, std::mbstate_t>
277 *cvt_byname = 0;
278
279 // verify that facet publicly derives from locale::facet
280 pfac = cvt;
281
282 const std::codecvt_base *pcvtbase = cvt;
283 _RWSTD_UNUSED (pcvtbase);
284
285 cvt = cvt_byname;
286 }
287
288 typedef std::char_traits<char_type> CTr;
289 typedef std::istreambuf_iterator<char_type, CTr > IIt;
290 typedef std::ostreambuf_iterator<char_type, CTr > OIt;
291
292 {
293 // monetary category
294
295 const std::moneypunct<char_type, false> *mpun = 0;
296 const std::moneypunct<char_type, true> *mpun_intl = 0;
297 const std::moneypunct_byname<char_type, false> *mpun_byname = 0;
298 const std::moneypunct_byname<char_type, true> *mpun_intl_byname = 0;
299 const std::money_get<char_type, IIt> *mget = 0;
300 const std::money_put<char_type, OIt> *mput = 0;
301
302 // verify that facets publicly derive from locale::facet
303 pfac = mpun;
304 pfac = mpun_intl;
305 pfac = mget;
306 pfac = mput;
307
308 mpun = mpun_byname;
309 mpun_intl = mpun_intl_byname;
310
311 // verify that punct facets publicly derive from money_base
312 const std::money_base *pmbase = mpun;
313 pmbase = mpun_intl;
314 _RWSTD_UNUSED (pmbase);
315
316#ifndef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
317
318 const std::moneypunct<char_type> *pmpun_noarg = mpun;
319 _RWSTD_UNUSED (pmpun_noarg);
320
321 // verify default template arguments
322 const std::money_get<char_type> *pmget = mget;
323 const std::money_put<char_type> *pmput = mput;
324 _RWSTD_UNUSED (pmget);
325 _RWSTD_UNUSED (pmput);
326
327#endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
328
329 }
330
331 {
332 // numeric category
333
334 const std::num_get<char_type, IIt> *nget = 0;
335 const std::num_put<char_type, OIt> *nput = 0;
336
337 // verify that facets publicly derive from locale::facet
338 pfac = nget;
339 pfac = nput;
340
341#ifndef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
342
343 // verify default template arguments
344 const std::num_get<char_type> *pnget = nget;
345 const std::num_put<char_type> *pnput = nput;
346 _RWSTD_UNUSED (pnget);
347 _RWSTD_UNUSED (pnput);
348
349#endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
350
351 }
352
353 {
354 // time category
355
356 const std::time_get<char_type, IIt> *tget = 0;
357 const std::time_put<char_type, OIt> *tput = 0;
358
359 // verify that facets publicly derive from locale::facet
360 pfac = tget;
361 pfac = tput;
362
363#ifndef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
364
365 // verify default template arguments
366 const std::time_get<char_type> *ptget = tget;
367 const std::time_put<char_type> *ptput = tput;
368 _RWSTD_UNUSED (ptget);
369 _RWSTD_UNUSED (ptput);
370
371#endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
372
373 }
374
375 {
376 // messages category
377
378 const std::messages<char_type> *msgs = 0;
379 const std::messages_byname<char_type> *msgs_byname = 0;
380
381 // verify that facets publicly derive from locale::facet
382 pfac = msgs;
383
384 const std::messages_base *pmsgbase = msgs;
385 const std::messages<char_type> *pmsgs = msgs_byname;
386
387 _RWSTD_UNUSED (pmsgbase);
388 _RWSTD_UNUSED (pmsgs);
389 }
390}
391
392
394// helper to verify that locale and facet ctors are explicit
395// not defined since they must not be referenced if test is successful
396void is_explicit (const std::locale&);
397void is_explicit (const std::locale::facet&);
398
399void is_explicit (const std::collate<char>&);
400void is_explicit (const std::ctype<char>&);
401
402# ifndef _RWSTD_NO_WCHAR_T
403
404void is_explicit (const std::collate<wchar_t>&);
405void is_explicit (const std::ctype<wchar_t>&);
406
407# endif // _RWSTD_NO_WCHAR_T
408
410{
411 // NOT explicit
412
413 // for locale::facet::facet (size_t = 0) and derived facet ctors
414 has_implicit_ctor (std::size_t) { /* empty */ }
415
416 // for ctype<char>::ctype (const mask*, bool = false, size_t = 0)
417 has_implicit_ctor (const std::ctype_base::mask*) { /* empty */ }
418
419 // for locale::locale (const char*, size_t = 0)
420 has_implicit_ctor (const char*) { /* empty */ }
421};
422
423// calls to the overloaded is_explicit() resolve to the function below
424void is_explicit (const has_implicit_ctor&) { /* empty */ }
425
426
428// local to test_locale
429static bool dtor_called = false;
430
431struct Facet: std::locale::facet
432{
433 typedef std::locale::facet Base;
434
435 // default argument provided to work around a library limitation
436 // that requires all facets to have default ctors
437 Facet (std::size_t refs = 0): Base (refs) { /* empty */ }
438
440 dtor_called = true;
441 }
442
443 static std::locale::id id;
444};
445
446
447std::locale::id Facet::id;
448
449// using a global in favor of a static local
450// to work around an MSVC 6.0 bug (see PR #26305)
451static bool is_dtor_virtual;
452
453
454template <class charT>
456{
457 typedef std::char_traits<charT> traits_type;
458 typedef std::allocator<charT> Allocator;
459 typedef std::basic_string<charT, traits_type, Allocator> string_type;
460};
461
462
463// test class locale definition
464static void
465test_locale ()
466{
467 rw_info (0, __FILE__, __LINE__, "class std::locale synopsis");
468
469 // 21.1.1.1.1
470 const std::locale::category *pcat = (int*)0;
471
472#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
473
474 // verify that category constants are defined
475 pcat = &std::locale::none;
476 pcat = &std::locale::collate;
477 pcat = &std::locale::ctype;
478 pcat = &std::locale::monetary;
479 pcat = &std::locale::numeric;
480 pcat = &std::locale::time;
481 pcat = &std::locale::messages;
482 pcat = &std::locale::all;
483
484#endif // _RWSTD_NO_STATIC_CONST_MEMBER_INIT
485
486 // verify that category constants are constant integral expressions
487 switch (*pcat) {
488 case std::locale::none:
489 case std::locale::collate:
490 case std::locale::ctype:
491 case std::locale::monetary:
492 case std::locale::numeric:
493 case std::locale::time:
494 case std::locale::messages:
495 case std::locale::all:
496 break;
497 }
498
499 static const int c_cats [] = {
501
502#ifdef LC_MESSAGES
504#endif // LC_MESSAGES
505
506 };
507
508 static const std::locale::category cats[] = {
509 std::locale::none, std::locale::collate, std::locale::ctype,
510 std::locale::monetary, std::locale::numeric, std::locale::time,
511 std::locale::messages, std::locale::all
512 };
513
514 for (pcat = cats; pcat != cats + sizeof cats / sizeof *cats - 1; ++pcat) {
515
516 bool success = true;
517
518 for (unsigned i = pcat - cats + 1; i < sizeof cats / sizeof *cats; ++i)
519 if ( *pcat != std::locale::all
520 && cats [i] != std::locale::all
521 && (*pcat & cats [i]))
522 rw_assert (success = false, __FILE__, __LINE__,
523 "(%{Lc} & %{Lc}) != 0", *pcat, cats [i]);
524
525 for (unsigned j = 0; j != sizeof c_cats / sizeof *c_cats; ++j) {
526 // locale::category values must not conflict with LC_XXX constants
527 if (*pcat & c_cats [j])
528 rw_assert (success = false, __FILE__, __LINE__,
529 "(%{Lc} & %{Lc}) != 0", *pcat, c_cats [j]);
530
531 if (*pcat == c_cats [j])
532 rw_assert (success = false, __FILE__, __LINE__,
533 "%{Lc} != %{Lc}", *pcat, c_cats [j]);
534 }
535
536 rw_assert (success, __FILE__, __LINE__, "%{Lc}", *pcat);
537 }
538
539 // 21.1.1.1.1, p1
540 const int all = std::locale::collate
541 | std::locale::ctype
542 | std::locale::monetary
543 | std::locale::numeric
544 | std::locale::time
545 | std::locale::messages;
546
547 rw_assert (std::locale::all == all, __FILE__, __LINE__,
548 "std::locale::all == %#x, got %#x", all, std::locale::all);
549
550 // 22.1.1.1.2
551
552 // verify that locale::facet::facet (size_t) is explicit
553 is_explicit (std::size_t ());
554
555 {
556 // verify that ctor takes a default argument
557 struct Facet: std::locale::facet {
558
559 typedef std::locale::facet Base;
560
561 Facet (): Base () { /* empty */ }
562 Facet (std::size_t ref): Base (ref) {/* empty */ }
563 ~Facet () {
564 is_dtor_virtual = true;
565 }
566
567 };
568
569 // delete a derived object using a pointer to the base
570 delete (std::locale::facet*)new Facet ();
571 rw_assert (is_dtor_virtual, __FILE__, __LINE__,
572 "locale::facet::~facet() not virtual");
573 }
574
575 // 22.1.1.1.3 - dfeault ctor and dtor are public
576 std::locale::id id;
577 _RWSTD_UNUSED (id);
578
579 // 22.1.1.2, p1
580 const std::locale l;
581
582 // 22.1.1.2, p3
583 std::locale l2 (l);
584
585 // 22.1.1.2, p6
586 (void)std::locale ("");
587
588 // verify that locale::locale (const char*) is explicit
589 is_explicit ((const char*)"");
590
591 // 22.1.1.2, p9
592 (void)std::locale (l, "", std::locale::all);
593
594 Facet *pf = new Facet (1 /* ref count */);
595
596 {
597 // 22.1.1.2, p12
598 // enclose unnamed temporary in its own scope to work around
599 // a SunPro 5.4 bug which amkes it calls the dtor too late
600 // see PR #27543
601 (void)std::locale (l, pf);
602 }
603
604 // exercise 22.1.1.1.2, p2, refs == 1
605 rw_assert (!dtor_called, __FILE__, __LINE__,
606 "facet dtor called for ref count of 1");
607
608 if (!dtor_called)
609 delete pf;
610
611 dtor_called = false;
612
613 // exercise 22.1.1.1.2, p2, refs == 0
614 pf = new Facet (0 /* ref count */);
615
616 {
617 // create an unnamed temporary object and force it to go out of
618 // scope (in case the compiler, such as SunPro 5.4, fails to
619 // detsroy it at the end of the expression) so that it is forced
620 // to destroy the user-defined facet
621 (void)std::locale (l, pf);
622 }
623
624 rw_assert (dtor_called, __FILE__, __LINE__,
625 "UD facet dtor not called for ref count of 0");
626
627 if (!dtor_called)
628 delete pf;
629
630 pf = 0;
631
632 // 22.1.1.2, p14
633 (void)std::locale (l, l, std::locale::all);
634
635// verify that a member function is accessible and has the appropriate
636// signature, including return type and exception specification
637#define MEMFUN(result, name, arg_list) \
638 do { \
639 /* jumping thru hoops to avoid bogus gcc -Wshadow warnings */ \
640 result (std::locale::* _RWSTD_PASTE (pf, __LINE__)) \
641 arg_list = &std::locale::name; \
642 _RWSTD_UNUSED (_RWSTD_PASTE (pf, __LINE__)); \
643 } while (0)
644
645#if !defined __HP_aCC || __HP_aCC > 33100
646
647 // working around an HP aCC bug (see PR #23312)
648
649 // 22.1.1.2, p4
650 MEMFUN (const std::locale&, operator=,(const std::locale&) _PTR_THROWS(()));
651
652#endif // __HP_aCC > 33000
653
654#if !defined __HP_aCC || __HP_aCC > 33100
655
656 // working around an HP aCC bug (see PR #23312)
657
658 // 22.1.1.3, p1
659 MEMFUN (std::locale, combine<Facet>, (const std::locale&) const);
660
661#endif // __HP_aCC > 33000
662
663 // 22.1.1.3, p5
664 MEMFUN (std::string, name, () const);
665
666 // 22.1.1.4, p1
667 MEMFUN (bool, operator==, (const std::locale&) const);
668
669 // 22.1.1.4, p2
670 MEMFUN (bool, operator!=, (const std::locale&) const);
671
672 // 22.1.1.4, p3
673 MEMFUN (bool, operator(), (const std::string&, const std::string&) const);
674
675#ifndef _RWSTD_NO_WCHAR_T
676
677 MEMFUN (bool, operator(), (const std::wstring&, const std::wstring&)const);
678
679#endif // _RWSTD_NO_WCHAR_T
680
681 // exercise a specialization other than on the default char types
682 typedef StringTypes<int>::string_type IntString;
683
684 MEMFUN (bool, operator(), (const IntString&, const IntString&) const);
685
686 // 22.1.1.5
687 FUN (std::locale, std::locale::global, (const std::locale&));
688 FUN (const std::locale&, std::locale::classic, ());
689}
690
691
693// test class template ctype definition
694
695template <class charT>
696struct CtypeDerived: std::ctype<charT>
697{
698 typedef std::ctype<charT> CtypeT;
699 typedef std::ctype_base::mask M;
700 typedef const charT* PtrT;
701
702// verify that a member function is accessible and has the appropriate
703// signature, including return type and exception specification
704#undef MEMFUN
705#define MEMFUN(result, name, arg_list) \
706 do { \
707 result (CtypeT::* pf) arg_list = &CtypeT::name; \
708 _RWSTD_UNUSED (pf); \
709 } while (0)
710
711 static void test_protected_members () {
712 // protected members (see `#define protected public' above)
713 MEMFUN (bool, do_is, (M, charT) const);
714 MEMFUN (PtrT, do_is, (PtrT, PtrT, M*) const);
715
716 // lwg issue 124
717 MEMFUN (PtrT, do_scan_is, (M, PtrT, PtrT) const);
718 MEMFUN (PtrT, do_scan_not, (M, PtrT, PtrT) const);
719 MEMFUN (charT, do_toupper, (charT) const);
720 MEMFUN (PtrT, do_toupper, (charT*, PtrT) const);
721 MEMFUN (charT, do_tolower, (charT) const);
722 MEMFUN (PtrT, do_tolower, (charT*, PtrT) const);
723 MEMFUN (charT, do_widen, (char) const);
724 MEMFUN (const char*,
725 do_widen, (const char*, const char*, charT*) const);
726 MEMFUN (char, do_narrow, (charT, char) const);
727 MEMFUN (PtrT, do_narrow,
728 (PtrT, PtrT, char, char*) const);
729 }
730};
731
732
733// exercise the primary template
734template <class charT>
735/*static*/ void
737{
739}
740
741
742struct CtypeCharDerived: std::ctype<char>
743{
744 typedef std::ctype<char> CtypeT;
745 typedef std::ctype_base::mask Mask;
746
747 // verify that all required ctors (or one with default args) exist
748 CtypeCharDerived (): CtypeT () { /* empty */ }
749 CtypeCharDerived (const Mask *tbl): CtypeT (tbl) { /* empty */ }
750 CtypeCharDerived (const Mask *tbl, bool del): CtypeT (tbl, del) { /* empty */ }
751 CtypeCharDerived (const Mask *tbl, bool del, std::size_t ref)
752 : CtypeT (tbl, del, ref) { /* empty */ }
753
754 static void test_protected_members () {
755
756#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
757
758 // verify that table_size is properly defined
759 const std::size_t *psz = &std::ctype<char>::table_size;
760
761#else
762
763 const std::size_t dummy = std::ctype<char>::table_size;
764 const std::size_t *psz = &dummy;
765
766#endif // _RWSTD_NO_STATIC_CONST_MEMBER_INIT
767
768 // verify that table_size is an integral constant expression
769 switch (*psz) {
770 case std::ctype<char>::table_size: break;
771 }
772
773 MEMFUN (char, do_toupper, (char) const);
774 MEMFUN (const char*, do_toupper, (char*, const char*) const);
775 MEMFUN (char, do_tolower, (char) const);
776 MEMFUN (const char*, do_tolower, (char*, const char*) const);
777 MEMFUN (char, do_widen, (char) const);
778 MEMFUN (const char*, do_widen,
779 (const char*, const char*, char*) const);
780 MEMFUN (char, do_narrow, (char, char) const);
781 MEMFUN (const char*, do_narrow,
782 (const char*, const char*, char, char*) const);
783
784 // 22.2.1.3.2, p12
785 MEMFUN (const std::ctype_base::mask*,
786 table, () const _PTR_THROWS (()));
787
788 // 22.2.1.3.3
789 FUN (const std::ctype_base::mask*,
790 CtypeT::classic_table, () _PTR_THROWS (()));
791 }
792};
793
794
795// exercise the char specialization
797/*static*/ void
799{
800 // prevent multiple assertions
801 static int called /* = false */;
802 if (called++)
803 return;
804
805 // 22.2.1.3.2, p3 - verify that ctor is explicit
806 is_explicit ((const std::ctype_base::mask*)0);
807
809}
810
811
812// skip POSIX-dependent behavior
813static int opt_enable_posix = 0; // --enable-posix
814
815
816template <class charT>
817static void
818test_ctype (const char* cname)
819{
820 rw_info (0, __FILE__, __LINE__,
821 "std::ctype<%s> synopsis", cname);
822
823 std::ctype_base::mask m = std::ctype_base::space;
825
826 const std::ctype_base::mask *pm = 0;
827 _RWSTD_UNUSED (pm);
828
829 // verify that mask constants are constant integral expressions
830 // whose address can be taken
831 switch (m) {
832
833#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
834 // see lwg issue 339
835# define ADDR(name) pm = &std::ctype_base::name
836#else
837# define ADDR(ignore) (void)0
838#endif
839
840#if !defined __IBMCPP__ || __IBMCPP__ > 800
841 // working around an IBM VAC++ bug #559
842 case std::ctype_base::mask (): break;
843#endif // !VAC+ || VAC++ > 7.0
844
845 case std::ctype_base::space: ADDR (space); break;
846 case std::ctype_base::print: ADDR (print); break;
847 case std::ctype_base::cntrl: ADDR (cntrl); break;
848 case std::ctype_base::upper: ADDR (upper); break;
849 case std::ctype_base::lower: ADDR (lower); break;
850 case std::ctype_base::alpha: ADDR (alpha); break;
851 case std::ctype_base::digit: ADDR (digit); break;
852 case std::ctype_base::punct: ADDR (punct); break;
853 case std::ctype_base::xdigit: ADDR (xdigit); break;
854 case std::ctype_base::alnum: ADDR (alnum); break;
855 case std::ctype_base::graph: ADDR (graph); break;
856
857 default: break;
858 }
859
860 // prevent unnecessary assertions
861 if (sizeof (charT) == sizeof (char)) {
862 rw_assert (std::ctype_base::alnum ==
863 (std::ctype_base::alpha | std::ctype_base::digit),
864 __FILE__, __LINE__,
865 "std::ctype_base::alnum = %#x, expected %#x",
866 std::ctype_base::alnum,
867 std::ctype_base::alpha | std::ctype_base::digit);
868
869 if (opt_enable_posix) {
870 // POSIX allows graph characters that aren't alnum or punct
871 // 22.2.1 says the numeric values are for exposition only
872 // which presumably applies to all the constants
873 rw_assert (std::ctype_base::graph
874 == (std::ctype_base::alnum | std::ctype_base::punct),
875 __FILE__, __LINE__,
876 "std::ctype_base::graph = %#x, expected %#x",
877 std::ctype_base::graph,
878 std::ctype_base::alnum | std::ctype_base::punct);
879 }
880 }
881
882 typedef std::ctype<charT> CtypeT;
883 typedef typename CtypeT::mask Mask;
884
885 charT *pc = (typename CtypeT::char_type*)0;
886 _RWSTD_UNUSED (pc);
887
888 typedef const charT* PtrT;
889
890 MEMFUN (bool, is, (Mask, charT) const);
891 MEMFUN (PtrT, is, (PtrT, PtrT, Mask*) const);
892 MEMFUN (PtrT, scan_is, (Mask, PtrT, PtrT) const);
893 MEMFUN (PtrT, scan_not, (Mask, PtrT, PtrT) const);
894 MEMFUN (charT, toupper, (charT) const);
895 MEMFUN (PtrT, toupper, (charT*, PtrT) const);
896 MEMFUN (charT, tolower, (charT) const);
897 MEMFUN (PtrT, tolower, (charT*, PtrT) const);
898 MEMFUN (charT, widen, (char) const);
899 MEMFUN (const char*, widen, (const char*, const char*, charT*) const);
900 MEMFUN (char, narrow, (charT, char) const);
901 MEMFUN (PtrT, narrow,
902 (PtrT, PtrT, char, char*) const);
903
904 std::locale::id *pid = &CtypeT::id;
905 _RWSTD_UNUSED (pid);
906
907 // exercise virtuals and other parts that differ between
908 // the primary template and the char specialization
909 test_ctype_specialization<charT> ();
910}
911
912
914template <class charT>
915struct CodecvtDerived: std::codecvt<charT, char, std::mbstate_t>
916{
917 typedef std::codecvt<charT, char, std::mbstate_t> Codecvt;
918 typedef std::codecvt_base::result Result;
919 typedef typename Codecvt::intern_type InternT;
920 typedef typename Codecvt::extern_type ExternT;
921 typedef typename Codecvt::state_type StateT;
922
923// verify that a member function is accessible and has the appropriate
924// signature, including return type and exception specification
925#undef MEMFUN
926#define MEMFUN(result, name, arg_list) \
927 do { \
928 result (Codecvt::*pf) arg_list = &Codecvt::name; \
929 _RWSTD_UNUSED (pf); \
930 } while (0)
931
933 // protected virtuals
935 (StateT&, const InternT*, const InternT*, const InternT*&,
936 ExternT*, ExternT*, ExternT*&) const);
937
939 (StateT&, ExternT*, ExternT*, ExternT*&) const);
940
942 (StateT&, const ExternT*, const ExternT*, const ExternT*&,
943 InternT*, InternT*, InternT*&) const);
944
945 MEMFUN (int, do_encoding, () const _PTR_THROWS (()));
946 MEMFUN (bool, do_always_noconv, () const _PTR_THROWS (()));
947
948 // lwg issue 75 changes first argument from const StateT& to State&
949 MEMFUN (int, do_length,
950 (StateT&, const ExternT*, const ExternT*,
951 std::size_t) const);
952
953 MEMFUN (int, do_max_length, () const _PTR_THROWS (()));
954 }
955 };
956
957
958template <class charT>
959static void
960test_codecvt (const char* cname)
961{
962 rw_info (0, __FILE__, __LINE__,
963 "std::codecvt<%s, char, std::mbstate_t> synopsis", cname);
964
965 // verify base class
966 std::codecvt_base b;
967 std::codecvt_base::result r = b.ok;
968
969 // prevent a bogus MSVC warning 4101 (see PR #24178)
971
972 // verify that result is a constant integral expression
973 switch (r) {
974 case std::codecvt_base::ok:
975 case std::codecvt_base::partial:
976 case std::codecvt_base::error:
977 case std::codecvt_base::noconv:
978 break;
979 }
980
981 typedef std::codecvt<charT, char, std::mbstate_t> Codecvt;
982
983 // verify that nested types exist
984 typedef typename Codecvt::intern_type InternT;
985 typedef typename Codecvt::extern_type ExternT;
986 typedef typename Codecvt::state_type StateT;
987
988 // verify nested types
989 const InternT *pint = (const charT*)0;
990 const ExternT *pext = (const char*)0;
991 const StateT *pst = (const std::mbstate_t*)0;
992
994 _RWSTD_UNUSED (pext);
995 _RWSTD_UNUSED (pst);
996
997 typedef std::codecvt_base::result Result;
998
999 // public non-virtuals
1000 MEMFUN (Result, out,
1001 (StateT&, const InternT*, const InternT*, const InternT*&,
1002 ExternT*, ExternT*, ExternT*&) const);
1003
1004 MEMFUN (Result, unshift, (StateT&, ExternT*, ExternT*, ExternT*&) const);
1005
1006 MEMFUN (Result, in,
1007 (StateT&, const ExternT*, const ExternT*, const ExternT*&,
1008 InternT*, InternT*, InternT*&) const);
1009
1010 MEMFUN (int, encoding, () const _PTR_THROWS (()));
1011 MEMFUN (bool, always_noconv, () const _PTR_THROWS (()));
1012
1013 // lwg issue 75 changes the first argument from const StateT& to State&
1014 MEMFUN (int, length,
1015 (StateT&, const ExternT*, const ExternT*, std::size_t) const);
1016
1017 MEMFUN (int, max_length, () const _PTR_THROWS (()));
1018
1019 std::locale::id *pid = &Codecvt::id;
1020 _RWSTD_UNUSED (pid);
1021
1023}
1024
1025
1027// user-defined character type; used to exercise requirements in Table 52
1028// i.e., specializations of facets on types other than char and wchar_t
1029#define UDC int
1030
1031// numeric category
1032
1033namespace std {
1034
1035// provide an explicit specialization of numpunct on UDC necessary
1036// in order to exercise num_get<UDC> and num_put<UDC>
1037
1039struct numpunct<UDC>: locale::facet
1040{
1043
1044 // working around an MSVC 6.0 bug
1045 typedef locale::facet Base;
1046
1047 explicit numpunct (size_t refs = 0)
1048 : Base (refs) { /* empty */ }
1049
1050 static locale::id id;
1051
1052 char_type decimal_point () const { return char_type (); }
1053 char_type thousands_sep () const { return char_type (); }
1054 string grouping () const { return ""; }
1055 string_type falsename () const { return string_type (); }
1056 string_type truename () const { return string_type (); }
1057};
1058
1059locale::id numpunct<UDC>::id;
1060
1061} // namespace std
1062
1063
1064template <class charT>
1065struct NumPunctDerived: std::numpunct<charT>
1066{
1067 typedef std::numpunct<charT> NumPunct;
1069
1070// verify that a member function is accessible and has the appropriate
1071// signature, including return type and exception specification
1072#undef MEMFUN
1073#define MEMFUN(result, name, arg_list) \
1074 do { \
1075 result (NumPunct::*pf) arg_list = &NumPunct::name; \
1076 _RWSTD_UNUSED (pf); \
1077 } while (0)
1078
1079 static void test_protected_members () {
1080 // protected virtuals
1081 MEMFUN (charT, do_decimal_point, () const);
1082 MEMFUN (charT, do_thousands_sep, () const);
1083 MEMFUN (std::string, do_grouping, () const);
1084 MEMFUN (StringT, do_truename, () const);
1085 MEMFUN (StringT, do_falsename, () const);
1086 }
1087};
1088
1089
1090template <class charT>
1091static void
1092test_numpunct (const char* cname)
1093{
1094 rw_info (0, __FILE__, __LINE__,
1095 "std::numpunct<%s> synopsis", cname);
1096
1097 typedef std::numpunct<charT> NumPunct;
1098 typedef typename StringTypes<charT>::string_type StringT;
1099
1100 // verify nested types
1101 typename NumPunct::char_type *pc = (charT*)0;
1102 typename NumPunct::string_type *pstr = (StringT*)0;
1103
1104 _RWSTD_UNUSED (pc);
1105 _RWSTD_UNUSED (pstr);
1106
1107 // public interface
1108 MEMFUN (charT, decimal_point, () const);
1109 MEMFUN (charT, thousands_sep, () const);
1110 MEMFUN (std::string, grouping, () const);
1111 MEMFUN (StringT, truename, () const);
1112 MEMFUN (StringT, falsename, () const);
1113
1114 // verify that id is defined and non-const
1115 std::locale::id *pid = &NumPunct::id;
1116 _RWSTD_UNUSED (pid);
1117
1119}
1120
1121
1122typedef std::ios_base IosBase;
1123typedef std::ios_base::iostate IoState;
1124
1125
1126template <class charT, class IterT>
1127struct NumGetDerived: std::num_get<charT, IterT>
1128{
1129 typedef std::num_get<charT, IterT> NumGet;
1130
1131// verify that a member function is accessible and has the appropriate
1132// signature, including return type and exception specification
1133#undef MEMFUN
1134#define MEMFUN(result, name, arg_list) \
1135 do { \
1136 result (NumGet::*pf) arg_list = &NumGet::name; \
1137 _RWSTD_UNUSED (pf); \
1138 } while (0)
1139
1140 static void test_protected_members () {
1141 // protected virtuals
1142 MEMFUN (IterT, do_get,
1143 (IterT, IterT, IosBase&, IoState&, bool&) const);
1144 MEMFUN (IterT, do_get,
1145 (IterT, IterT, IosBase& ,IoState&, long&) const);
1146 MEMFUN (IterT, do_get,
1147 (IterT, IterT, IosBase&, IoState&, unsigned short&) const);
1148 MEMFUN (IterT, do_get,
1149 (IterT, IterT, IosBase&, IoState&, unsigned&) const);
1150 MEMFUN (IterT, do_get,
1151 (IterT, IterT, IosBase&, IoState&, unsigned long&) const);
1152
1153#ifdef _RWSTD_LONG_LONG
1154
1155 // extensions disabled in strict ANSI mode
1156 MEMFUN (IterT, do_get,
1157 (IterT, IterT, IosBase&, IoState&, _RWSTD_LONG_LONG&) const);
1158 MEMFUN (IterT, do_get,
1159 (IterT, IterT, IosBase&, IoState&,
1160 unsigned _RWSTD_LONG_LONG&) const);
1161
1162#endif // _RWSTD_LONG_LONG
1163
1164 MEMFUN (IterT, do_get,
1165 (IterT, IterT, IosBase&, IoState&, float&) const);
1166 MEMFUN (IterT, do_get,
1167 (IterT, IterT, IosBase&, IoState&, double&) const);
1168 MEMFUN (IterT, do_get,
1169 (IterT, IterT, IosBase&, IoState&, long double&) const);
1170 MEMFUN (IterT, do_get,
1171 (IterT, IterT, IosBase&, IoState&, void*&) const);
1172 }
1173};
1174
1175
1176template <class charT, class IterT>
1177static void
1178test_num_get (const char* cname, const char* iname)
1179{
1180 rw_info (0, __FILE__, __LINE__,
1181 "std::num_get<%s, %s > synopsis", cname, iname);
1182
1183 typedef std::num_get<charT, IterT> NumGet;
1184
1185 // verify nested types
1186 typename NumGet::char_type *pc = (charT*)0;
1187 typename NumGet::iter_type *pi = (IterT*)0;
1188
1189 _RWSTD_UNUSED (pc);
1190 _RWSTD_UNUSED (pi);
1191
1192 // public interface
1193 MEMFUN (IterT, get, (IterT, IterT, IosBase&, IoState&, bool&) const);
1194 MEMFUN (IterT, get, (IterT, IterT, IosBase&, IoState&, long&) const);
1195 MEMFUN (IterT, get,
1196 (IterT, IterT, IosBase&, IoState&, unsigned short&) const);
1197 MEMFUN (IterT, get,
1198 (IterT, IterT, IosBase&, IoState&, unsigned&) const);
1199 MEMFUN (IterT, get,
1200 (IterT, IterT, IosBase&, IoState&, unsigned long&) const);
1201
1202#ifdef _RWSTD_LONG_LONG
1203
1204 // extensions disabled in strict ANSI mode
1205 MEMFUN (IterT, get,
1206 (IterT, IterT, IosBase&, IoState&, _RWSTD_LONG_LONG&) const);
1207 MEMFUN (IterT, get,
1208 (IterT, IterT, IosBase&, IoState&,
1209 unsigned _RWSTD_LONG_LONG&) const);
1210
1211#endif // _RWSTD_LONG_LONG
1212
1213 MEMFUN (IterT, get,
1214 (IterT, IterT, IosBase&, IoState&, float&) const);
1215 MEMFUN (IterT, get,
1216 (IterT, IterT, IosBase&, IoState&, double&) const);
1217 MEMFUN (IterT, get,
1218 (IterT, IterT, IosBase&, IoState&, long double&) const);
1219 MEMFUN (IterT, get,
1220 (IterT, IterT, IosBase&, IoState&, void*&) const);
1221
1222 std::locale::id *pid = &NumGet::id;
1223 _RWSTD_UNUSED (pid);
1224
1226}
1227
1228
1229template <class charT, class IterT>
1230struct NumPutDerived: std::num_put<charT, IterT>
1231{
1232 typedef std::num_put<charT, IterT> NumPut;
1233
1234// verify that a member function is accessible and has the appropriate
1235// signature, including return type and exception specification
1236#undef MEMFUN
1237#define MEMFUN(result, name, arg_list) \
1238 do { \
1239 result (NumPut::*pf) arg_list = &NumPut::name; \
1240 _RWSTD_UNUSED (pf); \
1241 } while (0)
1242
1243 static void test_protected_members () {
1244 // protected virtuals
1245 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, bool) const);
1246 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, long) const);
1247
1248 // no overloads for unsigned short or unsigned int
1249 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, unsigned long) const);
1250
1251#ifdef _RWSTD_LONG_LONG
1252
1253 // extensions disabled when _RWSTD_NO_LONG_LONG is #defined
1254 MEMFUN (IterT, do_put,
1255 (IterT, IosBase&, charT, _RWSTD_LONG_LONG) const);
1256 MEMFUN (IterT, do_put,
1257 (IterT, IosBase&, charT, unsigned _RWSTD_LONG_LONG) const);
1258
1259#endif // _RWSTD_LONG_LONG
1260
1261 // no float overload
1262 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, double) const);
1263 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, long double) const);
1264 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, const void*) const);
1265 }
1266};
1267
1268
1269template <class charT, class IterT>
1270static void
1271test_num_put (const char* cname, const char* iname)
1272{
1273 rw_info (0, __FILE__, __LINE__,
1274 "std::num_put<%s, %s > synopsis", cname, iname);
1275
1276 typedef std::num_put<charT, IterT> NumPut;
1277
1278 // verify nested types
1279 typename NumPut::char_type *pc = (charT*)0;
1280 typename NumPut::iter_type *pi = (IterT*)0;
1281
1282 _RWSTD_UNUSED (pc);
1283 _RWSTD_UNUSED (pi);
1284
1285 // public interface
1286 MEMFUN (IterT, put, (IterT, IosBase&, charT, bool) const);
1287 MEMFUN (IterT, put, (IterT, IosBase&, charT, long) const);
1288 MEMFUN (IterT, put, (IterT, IosBase&, charT, unsigned long) const);
1289
1290#ifdef _RWSTD_LONG_LONG
1291
1292 // extensions disabled in strict ANSI mode
1293 MEMFUN (IterT, put,
1294 (IterT, IosBase&, charT, _RWSTD_LONG_LONG) const);
1295 MEMFUN (IterT, put,
1296 (IterT, IosBase&, charT, unsigned _RWSTD_LONG_LONG) const);
1297
1298#endif // _RWSTD_LONG_LONG
1299
1300 MEMFUN (IterT, put, (IterT, IosBase&, charT, double) const);
1301 MEMFUN (IterT, put, (IterT, IosBase&, charT, long double) const);
1302 MEMFUN (IterT, put, (IterT, IosBase&, charT, const void*) const);
1303
1304 std::locale::id *pid = &NumPut::id;
1305 _RWSTD_UNUSED (pid);
1306
1308}
1309
1310
1312// collate category
1313
1314template <class charT>
1315struct CollateDerived: std::collate<charT>
1316{
1317 typedef const charT* PtrT;
1318 typedef std::collate<charT> Collate;
1320
1321// verify that a member function is accessible and has the appropriate
1322// signature, including return type and exception specification
1323#undef MEMFUN
1324#define MEMFUN(result, name, arg_list) \
1325 do { \
1326 result (Collate::* pf) arg_list = &Collate::name; \
1327 _RWSTD_UNUSED (pf); \
1328 } while (0)
1329
1330 static void test_protected_members () {
1331
1332 MEMFUN (int, compare, (PtrT, PtrT, PtrT, PtrT) const);
1333
1334 MEMFUN (StringT, transform, (PtrT, PtrT) const);
1335 MEMFUN (long, hash, (PtrT, PtrT) const);
1336
1337 std::locale::id *pid = &Collate::id;
1338 _RWSTD_UNUSED (pid);
1339
1340 // protected virtuals (see `#define protected public' above)
1341 MEMFUN (int, do_compare, (PtrT, PtrT, PtrT, PtrT) const);
1342
1343 MEMFUN (StringT, do_transform, (PtrT, PtrT) const);
1344 MEMFUN (long, do_hash, (PtrT, PtrT) const);
1345 }
1346};
1347
1348
1349template <class charT>
1350static void
1351test_collate (const char* cname)
1352{
1353 rw_info (0, __FILE__, __LINE__,
1354 "std::collate<%s> synopsis", cname);
1355
1356 typedef std::collate<charT> Collate;
1357 typedef typename StringTypes<charT>::string_type StringT;
1358
1359 // verify nested types
1360 typename Collate::char_type *pc = (charT*)0;
1361 typename Collate::string_type *pstr = (StringT*)0;
1362
1363 _RWSTD_UNUSED (pc);
1364 _RWSTD_UNUSED (pstr);
1365
1367}
1368
1369
1371// time category
1372
1373template <class charT, class IterT>
1374struct TimeGetDerived: std::time_get<charT, IterT>
1375{
1376 typedef std::time_get<charT, IterT> TimeGet;
1377
1378// verify that a member function is accessible and has the appropriate
1379// signature, including return type and exception specification
1380#undef MEMFUN
1381#define MEMFUN(result, name, arg_list) \
1382 do { \
1383 result (TimeGet::* pf) arg_list = &TimeGet::name; \
1384 _RWSTD_UNUSED (pf); \
1385 } while (0)
1386
1387 static void test_protected_members () {
1388 // protected virtuals
1389 MEMFUN (std::time_base::dateorder, do_date_order, () const);
1390 MEMFUN (IterT, do_get_time,
1391 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1392 MEMFUN (IterT, do_get_date,
1393 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1394 MEMFUN (IterT, do_get_weekday,
1395 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1396 MEMFUN (IterT, do_get_monthname,
1397 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1398 MEMFUN (IterT, do_get_year,
1399 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1400 }
1401};
1402
1403
1404template <class charT, class IterT>
1405static void
1406test_time_get (const char* cname, const char* iname)
1407{
1408 rw_info (0, __FILE__, __LINE__,
1409 "std::time_get<%s, %s > synopsis", cname, iname);
1410
1411 typedef std::time_get<charT, IterT> TimeGet;
1412
1413 // verify that dateorder constants are constant integral expressions
1414 std::time_base::dateorder ord = std::time_base::no_order;
1415 switch (ord) {
1416 case std::time_base::no_order:
1417 case std::time_base::dmy: case std::time_base::mdy:
1418 case std::time_base::ymd: case std::time_base::ydm:
1419 break;
1420 }
1421
1422 // verify values
1423 rw_assert (0 == std::time_base::no_order, __FILE__, __LINE__,
1424 "std::time_base::no_order");
1425 rw_assert (1 == std::time_base::dmy, __FILE__, __LINE__,
1426 "std::time_base::dmy");
1427 rw_assert (2 == std::time_base::mdy, __FILE__, __LINE__,
1428 "std::time_base::mdy");
1429 rw_assert (3 == std::time_base::ymd, __FILE__, __LINE__,
1430 "std::time_base::ymd");
1431 rw_assert (4 == std::time_base::ydm, __FILE__, __LINE__,
1432 "std::time_base::ydm");
1433
1434 // verify nested types
1435 typename TimeGet::char_type *pc = (charT*)0;
1436 typename TimeGet::iter_type *pi = (IterT*)0;
1437
1438 _RWSTD_UNUSED (pc);
1439 _RWSTD_UNUSED (pi);
1440
1441 // public non-virtuals
1442 MEMFUN (std::time_base::dateorder, date_order, () const);
1443 MEMFUN (IterT, get_time,
1444 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1445 MEMFUN (IterT, get_date,
1446 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1447 MEMFUN (IterT, get_weekday,
1448 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1449 MEMFUN (IterT, get_monthname,
1450 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1451 MEMFUN (IterT, get_year,
1452 (IterT, IterT, IosBase&, IoState&, std::tm*) const);
1453
1454 std::locale::id *pid = &TimeGet::id;
1455 _RWSTD_UNUSED (pid);
1456
1458}
1459
1460
1461template <class charT, class IterT>
1462struct TimePutDerived: std::time_put<charT, IterT>
1463{
1464 typedef std::time_put<charT, IterT> TimePut;
1465
1466// verify that a member function is accessible and has the appropriate
1467// signature, including return type and exception specification
1468#undef MEMFUN
1469#define MEMFUN(result, name, arg_list) \
1470 do { \
1471 result (TimePut::*pf) arg_list = &TimePut::name; \
1472 _RWSTD_UNUSED (pf); \
1473 } while (0)
1474
1475 static void test_protected_members () {
1476 // protected virtuals
1477 MEMFUN (IterT, do_put, (IterT, IosBase&, charT, const std::tm*,
1478 char, char) const);
1479 }
1480};
1481
1482
1483template <class charT, class IterT>
1484static void
1485test_time_put (const char* cname, const char* iname)
1486{
1487 rw_info (0, __FILE__, __LINE__,
1488 "std::time_put<%s, %s > synopsis", cname, iname);
1489
1490 typedef std::time_put<charT, IterT> TimePut;
1491
1492 // verify nested types
1493 typename TimePut::char_type *pc = (charT*)0;
1494 typename TimePut::iter_type *pi = (IterT*)0;
1495
1496 _RWSTD_UNUSED (pc);
1497 _RWSTD_UNUSED (pi);
1498
1499 // public non-virtuals
1500 MEMFUN (IterT, put, (IterT, IosBase&, charT, const std::tm*,
1501 const charT*, const charT*) const);
1502 MEMFUN (IterT, put, (IterT, IosBase&, charT, const std::tm*,
1503 char, char) const);
1504
1505 std::locale::id *pid = &TimePut::id;
1506 _RWSTD_UNUSED (pid);
1507
1509}
1510
1511
1513// monetary category
1514
1515namespace std {
1516
1517// (in the absence of support for partial specialization) provide explicit
1518// specializations of moneypunct on UDC necessary in order to exercise
1519// money_get<UDC> and money_put<UDC>
1520
1522struct moneypunct<UDC, false>: locale::facet, money_base
1523{
1526
1527 // working around an MSVC 6.0 bug
1528 typedef locale::facet Base;
1529
1530 explicit moneypunct (size_t refs = 0)
1531 : Base (refs), money_base () { /* empty */ }
1532
1533 static locale::id id;
1534
1535 enum { intl = false };
1536
1537 char_type decimal_point () const { return char_type (); }
1538 char_type thousands_sep () const { return char_type (); }
1539 string grouping () const { return ""; }
1540 string_type curr_symbol () const { return string_type (); }
1541 string_type positive_sign () const { return string_type (); }
1542 string_type negative_sign () const { return string_type (); }
1543 int frac_digits () const { return 0; }
1544 pattern pos_format () const { return pattern (); }
1545 pattern neg_format () const { return pattern (); }
1546};
1547
1548locale::id moneypunct<UDC, false>::id;
1549
1550
1552struct moneypunct<UDC, true>: locale::facet, money_base
1553{
1556
1557 // working around an MSVC 6.0 bug
1558 typedef locale::facet Base;
1559
1560 explicit moneypunct (size_t refs = 0)
1561 : Base (refs), money_base () { /* empty */ }
1562
1563 static locale::id id;
1564
1565 enum { intl = true };
1566
1567 char_type decimal_point () const { return char_type (); }
1568 char_type thousands_sep () const { return char_type (); }
1569 string grouping () const { return ""; }
1570 string_type curr_symbol () const { return string_type (); }
1571 string_type positive_sign () const { return string_type (); }
1572 string_type negative_sign () const { return string_type (); }
1573 int frac_digits () const { return 0; }
1574 pattern pos_format () const { return pattern (); }
1575 pattern neg_format () const { return pattern (); }
1576};
1577
1578locale::id moneypunct<UDC, true>::id;
1579
1580} // namespace std
1581
1582
1583template <class charT, bool Intl>
1584struct MoneyPunctDerived: std::moneypunct<charT, Intl>
1585{
1586 typedef std::moneypunct<charT, Intl> MoneyPunct;
1588
1589// verify that a member function is accessible and has the appropriate
1590// signature, including return type and exception specification
1591#undef MEMFUN
1592#define MEMFUN(result, name, arg_list) \
1593 do { \
1594 result (MoneyPunct::* pf) arg_list = &MoneyPunct::name; \
1595 _RWSTD_UNUSED (pf); \
1596 } while (0)
1597
1598 static void test_protected_members () {
1599
1600 // protected virtuals
1601 MEMFUN (charT, do_decimal_point, () const);
1602 MEMFUN (charT, do_thousands_sep, () const );
1603 MEMFUN (std::string, do_grouping, () const );
1604 MEMFUN (StringT, do_curr_symbol, () const);
1605 MEMFUN (StringT, do_positive_sign, () const);
1606 MEMFUN (StringT, do_negative_sign, () const);
1607 MEMFUN (int, do_frac_digits, () const);
1608 MEMFUN (std::money_base::pattern, do_pos_format, () const);
1609 MEMFUN (std::money_base::pattern, do_neg_format, () const);
1610 }
1611};
1612
1613
1614template <class charT>
1615static void
1616test_moneypunct (const char* cname)
1617{
1618 rw_info (0, __FILE__, __LINE__,
1619 "std::moneypunct<%s, bool> synopsis", cname);
1620
1621 typedef std::moneypunct<charT, false> MoneyPunct;
1622 typedef typename StringTypes<charT>::string_type StringT;
1623
1624 typename MoneyPunct::char_type *pc = (charT*)0;
1625 typename MoneyPunct::string_type *ps = (StringT*)0;
1626
1627 _RWSTD_UNUSED (pc);
1628 _RWSTD_UNUSED (ps);
1629
1630 MEMFUN (charT, decimal_point, () const );
1631 MEMFUN (charT, thousands_sep, () const );
1632 MEMFUN (std::string, grouping, () const );
1633 MEMFUN (StringT, curr_symbol, () const);
1634 MEMFUN (StringT, positive_sign, () const);
1635 MEMFUN (StringT, negative_sign, () const);
1636 MEMFUN (int, frac_digits, () const);
1637 MEMFUN (std::money_base::pattern, pos_format, () const);
1638 MEMFUN (std::money_base::pattern, neg_format, () const);
1639
1640 std::locale::id *pid = &MoneyPunct::id;
1641 _RWSTD_UNUSED (pid);
1642
1644}
1645
1646
1647template <class charT, class IterT>
1648struct MoneyGetDerived: std::money_get<charT, IterT>
1649{
1650 typedef std::money_get<charT, IterT> MoneyGet;
1652
1653// verify that a member function is accessible and has the appropriate
1654// signature, including return type and exception specification
1655#undef MEMFUN
1656#define MEMFUN(result, name, arg_list) \
1657 do { \
1658 result (MoneyGet::*pf) arg_list = &MoneyGet::name; \
1659 _RWSTD_UNUSED (pf); \
1660 } while (0)
1661
1662 static void test_protected_members () {
1663 // protected virtuals
1664
1665#ifndef _RWSTD_NO_LONG_DOUBLE
1666
1667 MEMFUN (IterT, do_get, (IterT, IterT, bool, IosBase&,
1668 IoState&, long double&) const);
1669
1670#else // if defined _RWSTD_NO_LONG_DOUBLE
1671
1672 MEMFUN (IterT, do_get, (IterT, IterT, bool, IosBase&,
1673 IoState&, double&) const);
1674
1675#endif // _RWSTD_NO_LONG_DOUBLE
1676
1677 MEMFUN (IterT, do_get, (IterT, IterT, bool, IosBase&,
1678 IoState&, StringT&) const);
1679 }
1680};
1681
1682
1683template <class charT, class IterT>
1684static void
1685test_money_get (const char* cname, const char* iname)
1686{
1687 rw_info (0, __FILE__, __LINE__,
1688 "std::money_get<%s, %s > synopsis", cname, iname);
1689
1690 typedef std::money_get<charT, IterT> MoneyGet;
1691 typedef typename StringTypes<charT>::string_type StringT;
1692
1693 // verify nested types
1694 typename MoneyGet::char_type *pc = (charT*)0;
1695 typename MoneyGet::iter_type *pi = (IterT*)0;
1696 typename MoneyGet::string_type *ps = (StringT*)0;
1697
1698 _RWSTD_UNUSED (pc);
1699 _RWSTD_UNUSED (pi);
1700 _RWSTD_UNUSED (ps);
1701
1702 // public interface
1703 MEMFUN (IterT, get, (IterT, IterT, bool, IosBase&,
1704 IoState&, long double&) const);
1705 MEMFUN (IterT, get, (IterT, IterT, bool, IosBase&,
1706 IoState&, StringT&) const);
1707
1708 std::locale::id *pid = &MoneyGet::id;
1709 _RWSTD_UNUSED (pid);
1710
1712}
1713
1714
1715template <class charT, class IterT>
1716struct MoneyPutDerived: std::money_put<charT, IterT>
1717{
1718 typedef std::money_put<charT, IterT> MoneyPut;
1720
1721// verify that a member function is accessible and has the appropriate
1722// signature, including return type and exception specification
1723#undef MEMFUN
1724#define MEMFUN(result, name, arg_list) \
1725 do { \
1726 result (MoneyPut::*pf) arg_list = &MoneyPut::name; \
1727 _RWSTD_UNUSED (pf); \
1728 } while (0)
1729
1730 static void test_protected_members () {
1731 // protected virtuals
1732
1733#ifndef _RWSTD_NO_LONG_DOUBLE
1734
1735 MEMFUN (IterT, do_put, (IterT, bool, IosBase&, charT,
1736 long double) const);
1737
1738#else // if defined _RWSTD_NO_LONG_DOUBLE
1739
1740 MEMFUN (IterT, do_put, (IterT, bool, IosBase&, charT, double) const);
1741
1742#endif // _RWSTD_NO_LONG_DOUBLE
1743
1744 MEMFUN (IterT, do_put, (IterT, bool, IosBase&, charT,
1745 const StringT&) const);
1746 }
1747};
1748
1749
1750template <class charT, class IterT>
1751static void
1752test_money_put (const char* cname, const char* iname)
1753{
1754 rw_info (0, __FILE__, __LINE__,
1755 "std::money_put<%s, %s > synopsis", cname, iname);
1756
1757 typedef std::money_put<charT, IterT> MoneyPut;
1758 typedef typename StringTypes<charT>::string_type StringT;
1759
1760 //verify nested types
1761 typename MoneyPut::char_type *pc = (charT*)0;
1762 typename MoneyPut::iter_type *pi = (IterT*)0;
1763 typename MoneyPut::string_type *ps = (StringT*)0;
1764
1765 _RWSTD_UNUSED (pc);
1766 _RWSTD_UNUSED (pi);
1767 _RWSTD_UNUSED (ps);
1768
1769 // public interface
1770 MEMFUN (IterT, put, (IterT, bool, IosBase&, charT,
1771 long double) const);
1772 MEMFUN (IterT, put, (IterT, bool, IosBase&, charT,
1773 const StringT&) const);
1774
1775 std::locale::id *pid = &MoneyPut::id;
1776 _RWSTD_UNUSED (pid);
1777
1779}
1780
1781
1783// messges category
1784
1785template <class charT>
1786struct MessagesDerived: std::messages<charT>
1787{
1788 typedef std::messages<charT> Messages;
1790
1791// verify that a member function is accessible and has the appropriate
1792// signature, including return type and exception specification
1793#undef MEMFUN
1794#define MEMFUN(result, name, arg_list) \
1795 do { \
1796 result (Messages::* pf) arg_list = &Messages::name; \
1797 _RWSTD_UNUSED (pf); \
1798 } while (0)
1799
1800
1801 static void test_protected_members () {
1802 // protected virtuals
1803 MEMFUN (int, do_open,
1804 (const std::string&, const std::locale&) const);
1805 MEMFUN (StringT, do_get, (int, int, int, const StringT&) const);
1806 MEMFUN (void, do_close, (int) const);
1807 }
1808};
1809
1810
1811template <class charT>
1812static void
1813test_messages (const char* cname)
1814{
1815 rw_info (0, __FILE__, __LINE__,
1816 "std::messages<%s> synopsis", cname);
1817
1818 typedef std::messages<charT> Messages;
1819 typedef typename StringTypes<charT>::string_type StringT;
1820
1821 // verify nested types
1822 std::messages_base::catalog *pcat = (int*)0;
1823 typename Messages::char_type *pc = (charT*)0;
1824 typename Messages::string_type *pstr = (StringT*)0;
1825
1826 _RWSTD_UNUSED (pcat);
1827 _RWSTD_UNUSED (pc);
1828 _RWSTD_UNUSED (pstr);
1829
1830 // public interface
1831 MEMFUN (int, open, (const std::string&, const std::locale&) const);
1832 MEMFUN (StringT, get, (int, int, int, const StringT&) const);
1833 MEMFUN (void, close, (int) const);
1834
1835 std::locale::id *pid = &Messages::id;
1836 _RWSTD_UNUSED (pid);
1837
1839}
1840
1841
1843static int
1844run_test (int /*unused*/, char* /*unused*/ [])
1845{
1846 test_lc_defs ();
1847 test_isxxx ();
1848
1849 // exercise the signatures of std::{has,use}_facet<>()
1850 test_have_use_facet<char> ();
1851
1852 // exercise the signatures of the convenience locale interfaces
1853 test_convenience_funs<char> ();
1854
1855 // test for the presence of the required facet templates
1856 test_facets<char> ();
1857
1858 test_locale ();
1859
1860// don't use _RWSTD_STRSTR so type macros (e.g. UDC) are not expanded
1861#undef FUN1
1862#define FUN1(fun, charT) \
1863 fun< charT > (#charT)
1864
1865 // std::locale::collate category
1866 FUN1 (test_collate, char);
1867
1868 // std::locale::ctype category
1869 FUN1 (test_codecvt, char);
1870 FUN1 (test_ctype, char);
1871
1872#undef FUN2
1873#define FUN2(fun, charT, IterT) \
1874 fun< charT, IterT > (#charT, #IterT)
1875
1876 // std::locale::monetary category
1877 FUN1 (test_moneypunct, char);
1878 FUN2 (test_money_get, char, std::istreambuf_iterator<char>);
1879 FUN2 (test_money_get, char, const char*);
1880 FUN2 (test_money_put, char, std::ostreambuf_iterator<char>);
1881 FUN2 (test_money_put, char, char*);
1882
1883 // std::locale::numeric category
1884 FUN1 (test_numpunct, char);
1885 FUN2 (test_num_get, char, std::istreambuf_iterator<char>);
1886 FUN2 (test_num_get, char, const char*);
1887 FUN2 (test_num_put, char, std::ostreambuf_iterator<char>);
1888 FUN2 (test_num_put, char, char*);
1889
1890 // std::locale::time category
1891 FUN2 (test_time_get, char, std::istreambuf_iterator<char>);
1892 FUN2 (test_time_get, char, const char*);
1893 FUN2 (test_time_put, char, std::ostreambuf_iterator<char>);
1894 FUN2 (test_time_put, char, char*);
1895
1896 // std::locale::messages category
1897 FUN1 (test_messages, char);
1898
1899#ifndef _RWSTD_NO_WCHAR_T
1900
1901 // same as above but for wchar_t
1902 test_have_use_facet<wchar_t> ();
1903 test_convenience_funs<wchar_t> ();
1904 test_facets<wchar_t> ();
1905
1906 FUN1 (test_collate, wchar_t);
1907
1908 FUN1 (test_ctype, wchar_t);
1909 FUN1 (test_codecvt, wchar_t);
1910
1911 FUN1 (test_moneypunct, wchar_t);
1912 FUN2 (test_money_get, wchar_t, std::istreambuf_iterator<wchar_t>);
1913 FUN2 (test_money_get, wchar_t, const wchar_t*);
1914 FUN2 (test_money_put, wchar_t, std::ostreambuf_iterator<wchar_t>);
1915 FUN2 (test_money_put, wchar_t, wchar_t*);
1916
1917 FUN1 (test_numpunct, wchar_t);
1918 FUN2 (test_num_get, wchar_t, std::istreambuf_iterator<wchar_t>);
1919 FUN2 (test_num_get, wchar_t, const wchar_t*);
1920 FUN2 (test_num_put, wchar_t, std::ostreambuf_iterator<wchar_t>);
1921 FUN2 (test_num_put, wchar_t, wchar_t*);
1922
1923 FUN2 (test_time_get, wchar_t, std::istreambuf_iterator<wchar_t>);
1924 FUN2 (test_time_get, wchar_t, const wchar_t*);
1925 FUN2 (test_time_put, wchar_t, std::ostreambuf_iterator<wchar_t>);
1926 FUN2 (test_time_put, wchar_t, wchar_t*);
1927
1928 FUN1 (test_messages, wchar_t);
1929
1930#endif // _RWSTD_NO_WCHAR_T
1931
1932 // test facet specializations on character types other than char and wchar_t
1933 // and iterator types other than istreambuf_iterator and ostreambuf_iterator
1934 // as per requirements in Table 52
1935
1936 FUN2 (test_money_get, UDC, std::istreambuf_iterator<UDC>);
1937 FUN2 (test_money_get, UDC, const UDC*);
1938
1939 FUN2 (test_money_put, UDC, std::ostreambuf_iterator<UDC>);
1940 FUN2 (test_money_put, UDC, UDC*);
1941
1942 FUN2 (test_num_get, UDC, std::istreambuf_iterator<UDC>);
1943 FUN2 (test_num_get, UDC, const UDC*);
1944
1945 FUN2 (test_num_put, UDC, std::ostreambuf_iterator<UDC>);
1946 FUN2 (test_num_put, UDC, UDC*);
1947
1948 FUN2 (test_time_get, char, const char*);
1949 FUN2 (test_time_put, char, char*);
1950
1951 return 0;
1952}
1953
1954/* extern */ int
1955main (int argc, char* argv [])
1956{
1957 return rw_test (argc, argv, __FILE__,
1958 "lib.locales", "header <locale> synopsis",
1959 run_test, "|-enable-posix# ", &opt_enable_posix);
1960}
1961
int * pint
const char lower[]
const char graph[]
const char upper[]
const char cntrl[]
const char print[]
const char punct[]
#define m
Definition 17.names.cpp:129
#define i
Definition 17.names.cpp:126
#define Result
Definition 17.names.cpp:530
#define r
Definition 17.names.cpp:134
#define pf
Definition 17.names.cpp:516
#define j
Definition 17.names.cpp:127
#define b
Definition 17.names.cpp:110
#define charT
Definition 17.names.cpp:456
#define _PTR_THROWS(spec)
std::codecvt< char, char, std::mbstate_t > Codecvt
void test_codecvt(const Codecvt *pcvt=0)
const char * widen(char *dst, const char *src)
const char * narrow(char *dst, const char *src)
std::collate< char > Collate
std::time_get< char > TimeGet
std::messages< char > Messages
std::time_put< char > TimePut
#define open(f, m)
void test_messages(charT, const char *cname, const char *locname)
#define close(f)
#define UDC
_RWSTD_SPECIALIZED_FUNCTION void test_ctype_specialization< char >()
std::ios_base IosBase
#define ADDR(name)
void is_explicit(const std::locale &)
#define FUN2(fun, charT, IterT)
#define FUN(result, name, arg_list)
#define MEMFUN(result, name, arg_list)
std::ios_base::iostate IoState
void test_ctype_specialization()
#define FUN1(fun, charT)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
const int out
const int in
#define main
#define _RWSTD_SPECIALIZED_CLASS
#define LC_CTYPE
#define LC_NUMERIC
#define LC_MONETARY
#define LC_TIME
#define LC_COLLATE
#define _RWSTD_LONG_LONG
unsigned short wchar_t
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_SPECIALIZED_FUNCTION
Definition _defs.h:556
A TOML table.
Definition table.hpp:190
const char * name
Definition codecvt1.cpp:72
Definition json.h:5363
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_RWSTD_MBSTATE_T StateT
Definition codecvt.cpp:68
#define LC_MESSAGES
Definition time_put.cpp:60
#define true
Definition stdbool.h:25
#define false
Definition stdbool.h:26
int do_encoding() const _THROWS(())
Codecvt::state_type StateT
Codecvt::intern_type InternT
std::codecvt< charT, char, std::mbstate_t > Codecvt
Codecvt::extern_type ExternT
std::codecvt_base::result Result
int do_max_length() const _THROWS(())
bool do_always_noconv() const _THROWS(())
static void test_protected_members()
StringTypes< charT >::string_type StringT
std::collate< charT > Collate
static void test_protected_members()
CtypeCharDerived(const Mask *tbl, bool del)
CtypeCharDerived(const Mask *tbl)
CtypeCharDerived(const Mask *tbl, bool del, std::size_t ref)
std::ctype< char > CtypeT
std::ctype_base::mask Mask
static void test_protected_members()
std::ctype< charT > CtypeT
std::ctype_base::mask M
Facet(std::size_t refs=0)
static std::locale::id id
std::locale::facet Base
StringTypes< charT >::string_type StringT
std::messages< charT > Messages
static void test_protected_members()
static void test_protected_members()
std::money_get< charT, IterT > MoneyGet
StringTypes< charT >::string_type StringT
std::moneypunct< charT, Intl > MoneyPunct
static void test_protected_members()
StringTypes< charT >::string_type StringT
static void test_protected_members()
StringTypes< charT >::string_type StringT
std::money_put< charT, IterT > MoneyPut
static void test_protected_members()
std::num_get< charT, IterT > NumGet
std::numpunct< charT > NumPunct
static void test_protected_members()
StringTypes< charT >::string_type StringT
static void test_protected_members()
std::num_put< charT, IterT > NumPut
Base::char_type char_type
Base::iter_type iter_type
std::char_traits< charT > traits_type
std::allocator< charT > Allocator
std::basic_string< charT, traits_type, Allocator > string_type
std::time_get< charT, IterT > TimeGet
static void test_protected_members()
std::time_put< charT, IterT > TimePut
static void test_protected_members()
has_implicit_ctor(const char *)
has_implicit_ctor(const std::ctype_base::mask *)
StringTypes< char_type >::string_type string_type
StringTypes< char_type >::string_type string_type
StringTypes< char_type >::string_type string_type
char_type decimal_point() const
char_type thousands_sep() const
string_type falsename() const
string_type truename() const
std::__rw_smanip< time_get_manip< charT >, const charT * > get_time(std::tm *tmb, const charT *fmt)