Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.meta.unary.prop.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2
30#include <rw_driver.h>
31#include <rw/_defs.h>
32
33// compile out all test code if extensions disabled
34#ifndef _RWSTD_NO_EXT_CXX_0X
35
36#include <type_traits>
37
38#include <stddef.h>
39
40
42// function with C linkage
43extern "C" typedef void cfun_t ();
44
45// incomplete type (never defined)
46struct incomplete_t;
47
48struct struct_t {
49 int i_; float f_;
50};
51
52class class_t {
53 int i_; float f_;
54};
55
56union union_t {
57 int i_; float f_;
58};
59
61};
62
63enum enum_t {
65};
66
67// for is_empty
68struct empty_t
69{
70};
71
73{
74 char c;
75};
76
77// for is_polymorphic
79{
80 virtual ~polymorphic_t() { } // need not be defined
81 virtual void vfunc ();
82};
83
85{
86 void vfunc ();
87};
88
89// for is_abstract
91{
92 virtual ~abstract_t () { }
93 virtual void vfunc () = 0;
94};
95
96template <class T>
98{
101};
102
103// used by is_polymorphic and is_abstract
104template <class T>
106{
107};
108
109template <class T, class U>
111{
113};
114
115template <class T>
116struct protected_derived_t : protected T
117{
118};
119
120template <class T>
121struct private_derived_t : private T
122{
123};
124
126{
127 // just to avoid warning without a ctor
128 static access_controlled_t make (char, char);
129private:
130 char pc1;
131protected:
132 char pc2;
133};
134
135template <class T>
137{
139};
140
141template <class T>
142struct virtual_derived_t : virtual T
143{
144};
145
148};
149
152};
153
157 return *this;
158 }
159};
160
163};
164
166{
168 : val_ (v) { }
169
172 {
173 if (rhs.val_ != 0)
174 throw empty_t ();
175 return *this;
176 }
177
178 int val_;
179};
180
182{
184 : val_ (v)
185 {
186 if (val_)
187 throw empty_t ();
188 }
189
190 int val_;
191};
192
194{
196 : val_ (v) { }
197
199 : val_ (rhs.val_)
200 {
201 if (rhs.val_ != 0)
202 throw empty_t ();
203 }
204
205 int val_;
206};
207
208
209
211void test_trait (int line, bool value, bool expect,
212 const char* trait, const char* type)
213{
214 rw_assert (value == expect, 0, line,
215 "%s<%s>::value is %b, expected %b",
216 trait, type, value, expect);
217}
218
219void test_trait (int line,
220 const char* trait, const char* type,
221 size_t value, size_t expect)
222{
223 rw_assert (value == expect, 0, line,
224 "%s<%s>::value is %zu, expected %zu",
225 trait, type, value, expect);
226}
227
228void test_trait (int line, size_t depth,
229 size_t value, size_t expect,
230 const char* trait, const char* type)
231{
232 rw_assert (value == expect, 0, line,
233 "%s<%s,%zu>::value is %zu, expected %zu",
234 trait, type, depth,
235 value, expect);
236}
237
238#define _TEST(Trait, Type, Expect) \
239 test_trait (__LINE__, Trait< Type >::value, Expect, #Trait, #Type)
240
241#define TEST(Trait, Type, Expect) \
242 _TEST (Trait, Type, Expect)
243
244
246#define C const
247#define V volatile
248#define CV const volatile
249
250
253{
254 TEST (std::is_const, void, false);
255 TEST (std::is_const, C void, true);
256 TEST (std::is_const, V void, false);
257 TEST (std::is_const, CV void, true);
258
259 // incomplete type other than void
260 TEST (std::is_const, incomplete_t, false);
261 TEST (std::is_const, C incomplete_t, true);
262 TEST (std::is_const, V incomplete_t, false);
263 TEST (std::is_const, CV incomplete_t, true);
264
265 TEST (std::is_const, int, false);
266 TEST (std::is_const, C int, true);
267 TEST (std::is_const, V int, false);
268 TEST (std::is_const, CV int, true);
269
270 // pointer types
271 TEST (std::is_const, int*, false);
272 TEST (std::is_const, C int*, false);
273 TEST (std::is_const, V int*, false);
274 TEST (std::is_const, CV int*, false);
275
276 TEST (std::is_const, int* C, true);
277 TEST (std::is_const, C int* C, true);
278 TEST (std::is_const, V int* C, true);
279 TEST (std::is_const, CV int* C, true);
280
281 TEST (std::is_const, int* V, false);
282 TEST (std::is_const, C int* V, false);
283 TEST (std::is_const, V int* V, false);
284 TEST (std::is_const, CV int* V, false);
285
286 TEST (std::is_const, int* CV, true);
287 TEST (std::is_const, C int* CV, true);
288 TEST (std::is_const, V int* CV, true);
289 TEST (std::is_const, CV int* CV, true);
290
291 // reference types
292 TEST (std::is_const, int&, false);
293 TEST (std::is_const, C int&, false);
294 TEST (std::is_const, V int&, false);
295 TEST (std::is_const, CV int&, false);
296
297 // array types
298 TEST (std::is_const, int [], false);
299 TEST (std::is_const, C int [], true);
300 TEST (std::is_const, V int [], false);
301 TEST (std::is_const, CV int [], true);
302
303 TEST (std::is_const, int [2], false);
304 TEST (std::is_const, C int [2], true);
305 TEST (std::is_const, V int [2], false);
306 TEST (std::is_const, CV int [2], true);
307
308 // array of incomplete type
309 TEST (std::is_const, incomplete_t [], false);
310 TEST (std::is_const, C incomplete_t [], true);
311 TEST (std::is_const, V incomplete_t [], false);
312 TEST (std::is_const, CV incomplete_t [], true);
313
314 // C++ function, C function, and pointers to member functions
315 TEST (std::is_const, void (), false);
316 TEST (std::is_const, cfun_t, false);
317 TEST (std::is_const, void (struct_t::*)(), false);
318 TEST (std::is_const, void (struct_t::*)() const, false);
319}
320
321
323{
324 TEST (std::is_volatile, void, false);
325 TEST (std::is_volatile, C void, false);
326 TEST (std::is_volatile, V void, true);
327 TEST (std::is_volatile, CV void, true);
328
329 // incomplete type other than void
330 TEST (std::is_volatile, incomplete_t, false);
331 TEST (std::is_volatile, C incomplete_t, false);
332 TEST (std::is_volatile, V incomplete_t, true);
333 TEST (std::is_volatile, CV incomplete_t, true);
334
335 TEST (std::is_volatile, int, false);
336 TEST (std::is_volatile, C int, false);
337 TEST (std::is_volatile, V int, true);
338 TEST (std::is_volatile, CV int, true);
339
340 // pointer types
341 TEST (std::is_volatile, int*, false);
342 TEST (std::is_volatile, C int*, false);
343 TEST (std::is_volatile, V int*, false);
344 TEST (std::is_volatile, CV int*, false);
345
346 TEST (std::is_volatile, int* C, false);
347 TEST (std::is_volatile, C int* C, false);
348 TEST (std::is_volatile, V int* C, false);
349 TEST (std::is_volatile, CV int* C, false);
350
351 TEST (std::is_volatile, int* V, true);
352 TEST (std::is_volatile, C int* V, true);
353 TEST (std::is_volatile, V int* V, true);
354 TEST (std::is_volatile, CV int* V, true);
355
356 TEST (std::is_volatile, int* CV, true);
357 TEST (std::is_volatile, C int* CV, true);
358 TEST (std::is_volatile, V int* CV, true);
359 TEST (std::is_volatile, CV int* CV, true);
360
361 // reference types
362 TEST (std::is_volatile, int&, false);
363 TEST (std::is_volatile, C int&, false);
364 TEST (std::is_volatile, V int&, false);
365 TEST (std::is_volatile, CV int&, false);
366
367 // array types
368 TEST (std::is_volatile, int [], false);
369 TEST (std::is_volatile, C int [], false);
370 TEST (std::is_volatile, V int [], true);
371 TEST (std::is_volatile, CV int [], true);
372
373 TEST (std::is_volatile, int [2], false);
374 TEST (std::is_volatile, C int [2], false);
375 TEST (std::is_volatile, V int [2], true);
376 TEST (std::is_volatile, CV int [2], true);
377
378 // array of incomplete type
379 TEST (std::is_volatile, incomplete_t [], false);
380 TEST (std::is_volatile, C incomplete_t [], false);
381 TEST (std::is_volatile, V incomplete_t [], true);
382 TEST (std::is_volatile, CV incomplete_t [], true);
383
384 // C++ function, C function, and pointers to member functions
385 TEST (std::is_volatile, void (), false);
386 TEST (std::is_volatile, cfun_t, false);
387 TEST (std::is_volatile, void (struct_t::*)(), false);
388 TEST (std::is_volatile, void (struct_t::*)() volatile, false);
389}
390
391
392static void test_has_trivial_assign ()
393{
394 TEST (std::has_trivial_assign, long, true);
395 TEST (std::has_trivial_assign, C long, false);
396 TEST (std::has_trivial_assign, V long, true);
397 TEST (std::has_trivial_assign, CV long, false);
398
399 TEST (std::has_trivial_assign, long&, false);
400 TEST (std::has_trivial_assign, C long&, false);
401 TEST (std::has_trivial_assign, V long&, false);
402 TEST (std::has_trivial_assign, CV long&, false);
403
404 TEST (std::has_trivial_assign, long [2], false);
405
406#if defined (_RWSTD_TT_HAS_TRIVIAL_ASSIGN) \
407 || defined (_RWSTD_TT_IS_POD)
408 TEST (std::has_trivial_assign, struct_t, true);
409#else
410 rw_warn (0, 0, __LINE__,
411 "portions of test_has_trivial_assign() have been disabled "
412 "due to lack of compiler support.");
413#endif
414
415 TEST (std::has_trivial_assign, struct_t [2], false);
416 TEST (std::has_trivial_assign, const struct_t, false);
417 TEST (std::has_trivial_assign, struct_t&, false);
418
419#if defined (_RWSTD_TT_HAS_TRIVIAL_ASSIGN)
420 TEST (std::has_trivial_assign, no_trivial_ctor_t, true);
421 TEST (std::has_trivial_assign, no_trivial_copy_t, true);
422 TEST (std::has_trivial_assign, no_trivial_dtor_t, true);
423#else
424 rw_warn (0, 0, __LINE__,
425 "portions of test_has_trivial_assign() have been disabled "
426 "due to lack of compiler support.");
427#endif
428
429 TEST (std::has_trivial_assign, no_trivial_assign_t, false);
430 TEST (std::has_trivial_assign, public_derived_t<no_trivial_assign_t>, false);
431}
432
433static void test_has_nothrow_assign ()
434{
435 TEST (std::has_nothrow_assign, long, true);
436 TEST (std::has_nothrow_assign, C long, false);
437 TEST (std::has_nothrow_assign, V long, true);
438 TEST (std::has_nothrow_assign, CV long, false);
439
440 TEST (std::has_nothrow_assign, long&, false);
441 TEST (std::has_nothrow_assign, C long&, false);
442 TEST (std::has_nothrow_assign, V long&, false);
443 TEST (std::has_nothrow_assign, CV long&, false);
444
445 TEST (std::has_nothrow_assign, long [2], false);
446
447#if defined (_RWSTD_TT_HAS_NOTHROW_ASSIGN) \
448 || defined (_RWSTD_TT_HAS_TRIVIAL_ASSIGN) \
449 || defined (_RWSTD_TT_IS_POD)
450 TEST (std::has_nothrow_assign, struct_t, true);
451 TEST (std::has_nothrow_assign, volatile struct_t, true);
452#else
453 rw_warn (0, 0, __LINE__,
454 "portions of test_has_nothrow_assign() have been disabled "
455 "due to lack of compiler support.");
456#endif
457
458 TEST (std::has_nothrow_assign, struct_t [2], false);
459 TEST (std::has_nothrow_assign, const struct_t, false);
460 TEST (std::has_nothrow_assign, struct_t&, false);
461
462#if defined (_RWSTD_TT_HAS_NOTHROW_ASSIGN)
463 TEST (std::has_nothrow_assign, no_trivial_ctor_t, true);
464 TEST (std::has_nothrow_assign, no_trivial_copy_t, true);
465 TEST (std::has_nothrow_assign, no_trivial_dtor_t, true);
466#else
467 rw_warn (0, 0, __LINE__,
468 "portions of test_has_nothrow_assign() have been disabled "
469 "due to lack of compiler support.");
470#endif
471
472 TEST (std::has_nothrow_assign, throwing_assign_t, false);
473}
474
475static void test_is_trivial ()
476{
477 TEST (std::is_trivial, void, false);
478 TEST (std::is_trivial, C void, false);
479 TEST (std::is_trivial, V void, false);
480 TEST (std::is_trivial, CV void, false);
481
482 TEST (std::is_trivial, long, true);
483 TEST (std::is_trivial, C long, true);
484 TEST (std::is_trivial, V long, true);
485 TEST (std::is_trivial, CV long, true);
486
487 TEST (std::is_trivial, long&, false);
488 TEST (std::is_trivial, C long&, false);
489 TEST (std::is_trivial, V long&, false);
490 TEST (std::is_trivial, CV long&, false);
491
492#if ( defined (_RWSTD_TT_HAS_TRIVIAL_CTOR) \
493 && defined (_RWSTD_TT_HAS_TRIVIAL_COPY) \
494 && defined (_RWSTD_TT_HAS_TRIVIAL_ASSIGN) \
495 && defined (_RWSTD_TT_HAS_TRIVIAL_DTOR)) \
496 || defined (_RWSTD_TT_IS_POD)
497 TEST (std::is_trivial, class_t, true);
498 TEST (std::is_trivial, struct_t, true);
499 TEST (std::is_trivial, union_t, true);
500
501 TEST (std::is_trivial, empty_t, true);
502 TEST (std::is_trivial, public_derived_t<empty_t>, true);
503
504 TEST (std::is_trivial, non_empty_t, true);
505 TEST (std::is_trivial, public_derived_t<non_empty_t>, true);
506#else
507 rw_warn (0, 0, __LINE__,
508 "portions of test_is_trivial() have been disabled "
509 "due to lack of compiler support.");
510#endif
511
512 TEST (std::is_trivial, abstract_t, false);
513 TEST (std::is_trivial, public_derived_t<abstract_t>, false);
514
515 TEST (std::is_trivial, polymorphic_t, false);
516 TEST (std::is_trivial, public_derived_t<polymorphic_t>, false);
517
518 TEST (std::is_trivial, no_trivial_ctor_t, false);
519 TEST (std::is_trivial, no_trivial_copy_t, false);
520 TEST (std::is_trivial, no_trivial_assign_t, false);
521 TEST (std::is_trivial, no_trivial_dtor_t, false);
522}
523
524
525// use traits to avoid warnings on gcc when adding qualifiers to some
526// types
527#undef TEST
528#define TEST(Trait,Type,Expect) \
529 _TEST(Trait, Type, Expect); \
530 _TEST(Trait, std::add_const< Type >::type, Expect); \
531 _TEST(Trait, std::add_volatile< Type >::type, Expect); \
532 _TEST(Trait, std::add_cv< Type >::type, Expect)
533
534static void test_is_standard_layout ()
535{
536 TEST (std::is_standard_layout, long, true);
537
538 // no non-static data members of non-standard-layout type
539 TEST (std::is_standard_layout, member_t<access_controlled_t>, false);
540 TEST (std::is_standard_layout, member_t<public_derived_t<polymorphic_t> >, false);
541
542 // no reference member
543 TEST (std::is_standard_layout, member_t<int&>, false);
544
545 // no virtual function
546 TEST (std::is_standard_layout, abstract_t, false);
547 TEST (std::is_standard_layout, polymorphic_t, false);
548
549 // no virtual base
550 TEST (std::is_standard_layout, virtual_derived_t<empty_t>, false);
551 TEST (std::is_standard_layout, virtual_derived_t<non_empty_t>, false);
552
553 // no access control changes for non-statics
554 TEST (std::is_standard_layout, access_controlled_t, false);
555
556 // no non-standard layout base classes
557 TEST (std::is_standard_layout, public_derived_t<member_t<access_controlled_t> >, false);
558 TEST (std::is_standard_layout, public_derived_t<member_t<public_derived_t<polymorphic_t> > >, false);
559 TEST (std::is_standard_layout, public_derived_t<member_t<int&> >, false);
560 TEST (std::is_standard_layout, public_derived_t<abstract_t>, false);
561 TEST (std::is_standard_layout, public_derived_t<polymorphic_t>, false);
562 TEST (std::is_standard_layout, public_derived_t<virtual_derived_t<empty_t> >, false);
563 TEST (std::is_standard_layout, public_derived_t<virtual_derived_t<non_empty_t> >, false);
564 TEST (std::is_standard_layout, public_derived_t<access_controlled_t>, false);
565
566 // no non-static data members in the most-derived class
567 typedef public_derived_with_member<empty_t,int> derived_from_empty_with_member;
568 TEST (std::is_standard_layout, derived_from_empty_with_member, false);
569
570#if defined (_RWSTD_TT_IS_STANDARD_LAYOUT) \
571 || defined (_RWSTD_TT_IS_POD)
572 TEST (std::is_standard_layout, non_empty_t, true);
573
574# if defined (_RWSTD_TT_STRICT_CXX_0X_CONFORM)
575
576 // but we are allowed non-static members in one base class
577 TEST (std::is_standard_layout, public_derived_t<non_empty_t>, true);
578 TEST (std::is_standard_layout,
580
581# endif // _RWSTD_TT_STRICT_CXX_0X_CONFORM
582
583#else
584 rw_warn (0, 0, __LINE__,
585 "portions of test_is_standard_layout() have been disabled "
586 "due to lack of compiler support.");
587#endif
588
589 // but not two base classes with non-static members
590 typedef public_derived_with_member<non_empty_t, int> derived_from_non_empty_with_member;
591 TEST (std::is_standard_layout, derived_from_non_empty_with_member, false);
592
593 // no base classes of the same type as the first non-static data member
594 TEST (std::is_standard_layout, special_case_t<empty_t>, false);
595 TEST (std::is_standard_layout, special_case_t<non_empty_t>, false);
596
597 // everything else should be good to go
598 TEST (std::is_standard_layout, member_t<int>, false);
599 TEST (std::is_standard_layout, member_t<member_t<int> >, false);
600}
601
602static void test_is_pod ()
603{
604 TEST (std::is_pod, long, true);
605 TEST (std::is_pod, long [], true);
606 TEST (std::is_pod, long [2], true);
607 TEST (std::is_pod, long (*) [2], true);
608
609 TEST (std::is_pod, void*, true);
610 TEST (std::is_pod, void (*)(), true);
611 TEST (std::is_pod, void (* [])(), true);
612 TEST (std::is_pod, void (class_t::*)(), true);
613
614#if defined (_RWSTD_TT_IS_POD)
615 // standard layout and trivial
616 //
617 TEST (std::is_pod, struct_t, true);
618 TEST (std::is_pod, union_t, true);
619 TEST (std::is_pod, enum_t, true);
620
621 TEST (std::is_pod, empty_t, true);
622 TEST (std::is_pod, non_empty_t, true);
623
624# if defined (_RWSTD_TT_STRICT_CXX_0X_CONFORM)
625 TEST (std::is_pod, public_derived_t<empty_t>, true);
626 TEST (std::is_pod, public_derived_t<non_empty_t>, true);
627# endif
628
629#else
630 rw_warn (0, 0, __LINE__,
631 "portions of test_is_pod() have been disabled "
632 "due to lack of compiler support.");
633#endif
634
635 TEST (std::is_pod, abstract_t, false);
636 TEST (std::is_pod, public_derived_t<abstract_t>, false);
637
638 TEST (std::is_pod, polymorphic_t, false);
639 TEST (std::is_pod, public_derived_t<polymorphic_t>, false);
640
641 TEST (std::is_pod, no_trivial_ctor_t, false);
642 TEST (std::is_pod, no_trivial_copy_t, false);
643 TEST (std::is_pod, no_trivial_assign_t, false);
644 TEST (std::is_pod, no_trivial_dtor_t, false);
645
646 TEST (std::is_pod, access_controlled_t, false);
647}
648
649static void test_is_empty ()
650{
651 TEST (std::is_empty, void, false);
652
653 TEST (std::is_empty, struct_t, false);
654 TEST (std::is_empty, class_t, false);
655 TEST (std::is_empty, union_t, false);
656 TEST (std::is_empty, enum_t, false);
657
658 TEST (std::is_empty, empty_union, false);
659
660#if defined(_RWSTD_TT_IS_EMPTY) \
661 || defined (_RWSTD_TT_IS_CLASS) \
662 || defined (_RWSTD_TT_IS_UNION)
663 TEST (std::is_empty, empty_t, true);
664 TEST (std::is_empty, public_derived_t<empty_t>, true);
665#else
666 rw_warn (0, 0, __LINE__,
667 "portions of test_is_empty() have been disabled "
668 "due to lack of compiler support.");
669#endif
670
671 TEST (std::is_empty, non_empty_t, false);
672 TEST (std::is_empty, public_derived_t<non_empty_t>, false);
673
674 TEST (std::is_empty, abstract_t, false);
675 TEST (std::is_empty, public_derived_t<abstract_t>, false);
676
677 TEST (std::is_empty, polymorphic_t, false);
678 TEST (std::is_empty, public_derived_t<polymorphic_t>, false);
679
680 TEST (std::is_empty, virtual_derived_t<empty_t>, false);
681 TEST (std::is_empty, virtual_derived_t<non_empty_t>, false);
682}
683
684static void test_is_polymorphic ()
685{
686 // if we can reliably detect a class type, the fallback will evaluate
687 // to true for all polymorphic types. otherwise, it will evaluate to
688 // true for all class and union types.
689
690 TEST (std::is_polymorphic, void, false);
691 TEST (std::is_polymorphic, long, false);
692 TEST (std::is_polymorphic, int*, false);
693
694 TEST (std::is_polymorphic, polymorphic_t, true);
695 TEST (std::is_polymorphic, public_derived_t<polymorphic_t>, true);
696
697#if defined (_RWSTD_TT_IS_POLYMORPHIC) \
698 || defined (_RWSTD_TT_IS_CLASS) \
699 || defined (_RWSTD_TT_IS_UNION)
700 TEST (std::is_polymorphic, non_polymorphic_t, false);
701 TEST (std::is_polymorphic, public_derived_t<non_polymorphic_t>, false);
702#else
703 rw_warn (0, 0, __LINE__,
704 "portions of test_is_polymorphic() have been disabled "
705 "due to lack of compiler support.");
706#endif
707
708 TEST (std::is_polymorphic, abstract_t, true);
709 TEST (std::is_polymorphic, public_derived_t<abstract_t>, true);
710}
711
712static void test_is_abstract ()
713{
714 // if we can reliably detect a class type, the fallback will evaluate
715 // to true for all abstract types. otherwise, it will evaluate to
716 // true for all class and union types.
717
718 TEST (std::is_abstract, void, false);
719 TEST (std::is_abstract, long, false);
720 TEST (std::is_abstract, int*, false);
721
722 TEST (std::is_abstract, abstract_t, true);
723 TEST (std::is_abstract, public_derived_t<abstract_t>, true);
724
725#if defined (_RWSTD_TT_IS_ABSTRACT) \
726 || defined (_RWSTD_TT_IS_CLASS) \
727 || defined (_RWSTD_TT_IS_UNION)
728 TEST (std::is_abstract, polymorphic_t, false); // polymorphic_t is not an abstract type
729 TEST (std::is_abstract, public_derived_t<polymorphic_t>, false);
730#else
731 rw_warn (0, 0, __LINE__,
732 "portions of test_is_abstract() have been disabled "
733 "due to lack of compiler support.");
734#endif
735}
736
737static void test_has_trivial_constructor ()
738{
739 TEST (std::has_trivial_default_constructor, long, true);
740 TEST (std::has_trivial_default_constructor, const long, true);
741 TEST (std::has_trivial_default_constructor, volatile long, true);
742 TEST (std::has_trivial_default_constructor, long&, false);
743 TEST (std::has_trivial_default_constructor, long [2], true);
744
745#if defined (_RWSTD_TT_HAS_TRIVIAL_CTOR) \
746 || defined (_RWSTD_TT_IS_POD)
747 TEST (std::has_trivial_default_constructor, struct_t, true);
748 TEST (std::has_trivial_default_constructor, const struct_t, true);
749 TEST (std::has_trivial_default_constructor, volatile struct_t, true);
750 TEST (std::has_trivial_default_constructor, struct_t [2], true);
751#else
752 rw_warn (0, 0, __LINE__,
753 "portions of test_has_trivial_constructor() have been "
754 "disabled due to lack of compiler support.");
755#endif
756
757#if defined (_RWSTD_TT_HAS_TRIVIAL_CTOR)
758 TEST (std::has_trivial_default_constructor, no_trivial_assign_t, true);
759 TEST (std::has_trivial_default_constructor, no_trivial_dtor_t, true);
760#else
761 rw_warn (0, 0, __LINE__,
762 "portions of test_has_trivial_constructor() have been "
763 "disabled due to lack of compiler support.");
764#endif
765
766 TEST (std::has_trivial_default_constructor, no_trivial_ctor_t, false);
767 TEST (std::has_trivial_default_constructor, public_derived_t<no_trivial_ctor_t>, false);
768}
769
770static void test_has_trivial_copy ()
771{
772 TEST (std::has_trivial_copy_constructor, long, true);
773 TEST (std::has_trivial_copy_constructor, const long, true);
774 TEST (std::has_trivial_copy_constructor, volatile long, true);
775 TEST (std::has_trivial_copy_constructor, long&, true);
776 TEST (std::has_trivial_copy_constructor, long [2], false);
777
778#if defined (_RWSTD_TT_HAS_TRIVIAL_COPY) \
779 || defined (_RWSTD_TT_IS_POD)
780 TEST (std::has_trivial_copy_constructor, struct_t, true);
781 TEST (std::has_trivial_copy_constructor, const struct_t, true);
782 TEST (std::has_trivial_copy_constructor, volatile struct_t, true);
783#else
784 rw_warn (0, 0, __LINE__,
785 "portions of test_has_trivial_copy() have been "
786 "disabled due to lack of compiler support.");
787#endif
788
789 TEST (std::has_trivial_copy_constructor, struct_t [2], false);
790
791#if defined (_RWSTD_TT_HAS_TRIVIAL_COPY)
792 TEST (std::has_trivial_copy_constructor, no_trivial_ctor_t, true);
793 TEST (std::has_trivial_copy_constructor, no_trivial_assign_t, true);
794 TEST (std::has_trivial_copy_constructor, no_trivial_dtor_t, true);
795#else
796 rw_warn (0, 0, __LINE__,
797 "portions of test_has_trivial_copy() have been "
798 "disabled due to lack of compiler support.");
799#endif
800
801 TEST (std::has_trivial_copy_constructor, no_trivial_copy_t, false);
802 TEST (std::has_trivial_copy_constructor, public_derived_t<no_trivial_copy_t>, false);
803}
804
805static void test_has_trivial_destructor ()
806{
807 TEST (std::has_trivial_destructor, long, true);
808 TEST (std::has_trivial_destructor, const long, true);
809 TEST (std::has_trivial_destructor, volatile long, true);
810 TEST (std::has_trivial_destructor, long&, true);
811 TEST (std::has_trivial_destructor, long [2], true);
812
813#if defined (_RWSTD_TT_HAS_TRIVIAL_DTOR) \
814 || defined (_RWSTD_TT_IS_POD)
815 TEST (std::has_trivial_destructor, struct_t, true);
816 TEST (std::has_trivial_destructor, const struct_t, true);
817 TEST (std::has_trivial_destructor, volatile struct_t, true);
818 TEST (std::has_trivial_destructor, struct_t [2], true);
819#else
820 rw_warn (0, 0, __LINE__,
821 "portions of test_has_trivial_destructor() have been "
822 "disabled due to lack of compiler support.");
823#endif
824
825#if defined (_RWSTD_TT_HAS_TRIVIAL_DTOR)
826 TEST (std::has_trivial_destructor, no_trivial_ctor_t, true);
827 TEST (std::has_trivial_destructor, no_trivial_copy_t, true);
828 TEST (std::has_trivial_destructor, no_trivial_assign_t, true);
829#else
830 rw_warn (0, 0, __LINE__,
831 "portions of test_has_trivial_destructor() have been "
832 "disabled due to lack of compiler support.");
833#endif
834
835 TEST (std::has_trivial_destructor, no_trivial_dtor_t, false);
836 TEST (std::has_trivial_destructor, public_derived_t<no_trivial_dtor_t>, false);
837}
838
839static void test_has_nothrow_constructor ()
840{
841 TEST (std::has_nothrow_default_constructor, long, true);
842 TEST (std::has_nothrow_default_constructor, const long, true);
843 TEST (std::has_nothrow_default_constructor, volatile long, true);
844 TEST (std::has_nothrow_default_constructor, long&, false);
845 TEST (std::has_nothrow_default_constructor, long [2], true);
846
847#if defined (_RWSTD_TT_HAS_NOTHROW_CTOR) \
848 || defined (_RWSTD_TT_HAS_TRIVIAL_CTOR) \
849 || defined (_RWSTD_TT_IS_POD)
850 TEST (std::has_nothrow_default_constructor, struct_t, true);
851 TEST (std::has_nothrow_default_constructor, const struct_t, true);
852 TEST (std::has_nothrow_default_constructor, volatile struct_t, true);
853 TEST (std::has_nothrow_default_constructor, struct_t [2], true);
854#else
855 rw_warn (0, 0, __LINE__,
856 "portions of test_has_nothrow_constructor() have been "
857 "disabled due to lack of compiler support.");
858#endif
859
860#if defined (_RWSTD_TT_HAS_NOTHROW_CTOR)
861 TEST (std::has_nothrow_default_constructor, no_trivial_ctor_t, true);
862 //TEST (std::has_nothrow_default_constructor, no_trivial_copy_t, true);
863 TEST (std::has_nothrow_default_constructor, no_trivial_assign_t, true);
864 TEST (std::has_nothrow_default_constructor, struct_t, true);
865#else
866 rw_warn (0, 0, __LINE__,
867 "portions of test_has_nothrow_constructor() have been "
868 "disabled due to lack of compiler support.");
869#endif
870
871 TEST (std::has_nothrow_default_constructor, throwing_ctor_t, false);
872}
873
874static void test_has_nothrow_copy ()
875{
876 TEST (std::has_nothrow_copy_constructor, long, true);
877 TEST (std::has_nothrow_copy_constructor, const long, true);
878 TEST (std::has_nothrow_copy_constructor, volatile long, true);
879 TEST (std::has_nothrow_copy_constructor, long&, true);
880 TEST (std::has_nothrow_copy_constructor, long [2], false);
881
882#if defined (_RWSTD_TT_HAS_NOTHROW_COPY) \
883 || defined (_RWSTD_TT_HAS_TRIVIAL_COPY) \
884 || defined (_RWSTD_TT_IS_POD)
885 TEST (std::has_nothrow_copy_constructor, struct_t, true);
886 TEST (std::has_nothrow_copy_constructor, const struct_t, true);
887 TEST (std::has_nothrow_copy_constructor, volatile struct_t, true);
888#else
889 rw_warn (0, 0, __LINE__,
890 "portions of test_has_nothrow_copy() have been "
891 "disabled due to lack of compiler support.");
892#endif
893
894 TEST (std::has_nothrow_copy_constructor, struct_t [2], false);
895
896#if defined (_RWSTD_TT_HAS_NOTHROW_COPY)
897 TEST (std::has_nothrow_copy_constructor, no_trivial_ctor_t, true);
898 TEST (std::has_nothrow_copy_constructor, no_trivial_copy_t, true);
899 TEST (std::has_nothrow_copy_constructor, no_trivial_assign_t, true);
900#else
901 rw_warn (0, 0, __LINE__,
902 "portions of test_has_nothrow_copy() have been "
903 "disabled due to lack of compiler support.");
904#endif
905
906 TEST (std::has_nothrow_copy_constructor, throwing_copy_t, false);
907}
908
909static void test_has_virtual_destructor ()
910{
911 TEST (std::has_virtual_destructor, abstract_t, true);
912 TEST (std::has_virtual_destructor, public_derived_t<abstract_t>, true);
913
914 TEST (std::has_virtual_destructor, polymorphic_t, true);
915 TEST (std::has_virtual_destructor, public_derived_t<polymorphic_t>, true);
916
917#if defined (_RWSTD_TT_HAS_VIRTUAL_DTOR) \
918 || defined (_RWSTD_TT_IS_CLASS) \
919 || defined (_RWSTD_TT_IS_UNION)
920 TEST (std::has_virtual_destructor, non_polymorphic_t, false);
921 TEST (std::has_virtual_destructor, public_derived_t<non_polymorphic_t>, false);
922#else
923 rw_warn (0, 0, __LINE__,
924 "portions of test_has_virtual_destructor() have been "
925 "disabled due to lack of compiler support.");
926#endif
927}
928
929static void test_is_signed ()
930{
931 TEST (std::is_signed, char, char(-1) < char(0));
932
933 TEST (std::is_signed, signed char, true);
934 TEST (std::is_signed, signed short, true);
935 TEST (std::is_signed, signed int, true);
936 TEST (std::is_signed, signed long, true);
937
938 TEST (std::is_signed, unsigned char, false);
939 TEST (std::is_signed, unsigned short, false);
940 TEST (std::is_signed, unsigned int, false);
941 TEST (std::is_signed, unsigned long, false);
942
943#ifndef _RWSTD_NO_LONG_LONG
944 TEST (std::is_signed, signed long long, true);
945 TEST (std::is_signed, unsigned long long, false);
946#endif
947
948 TEST (std::is_signed, float, true);
949 TEST (std::is_signed, double, true);
950
951#ifndef _RWSTD_NO_LONG_DOUBLE
952 TEST (std::is_signed, long double, true);
953#endif
954
955 TEST (std::is_signed, enum_t, false);
956 TEST (std::is_signed, struct_t, false);
957 TEST (std::is_signed, class_t, false);
958 TEST (std::is_signed, union_t, false);
959
960 TEST (std::is_signed, long&, false);
961 TEST (std::is_signed, long*, false);
962 TEST (std::is_signed, long [2], false);
963 TEST (std::is_signed, long (), false);
964}
965
966static void test_is_unsigned ()
967{
968 TEST (std::is_unsigned, char, char(0) < char(-1));
969
970 TEST (std::is_unsigned, signed char, false);
971 TEST (std::is_unsigned, signed short, false);
972 TEST (std::is_unsigned, signed int, false);
973 TEST (std::is_unsigned, signed long, false);
974
975 TEST (std::is_unsigned, unsigned char, true);
976 TEST (std::is_unsigned, unsigned short, true);
977 TEST (std::is_unsigned, unsigned int, true);
978 TEST (std::is_unsigned, unsigned long, true);
979
980#ifndef _RWSTD_NO_LONG_LONG
981 TEST (std::is_unsigned, signed long long, false);
982 TEST (std::is_unsigned, unsigned long long, true);
983#endif
984
985 TEST (std::is_unsigned, float, false);
986 TEST (std::is_unsigned, double, false);
987
988#ifndef _RWSTD_NO_LONG_DOUBLE
989 TEST (std::is_unsigned, long double, false);
990#endif
991
992 TEST (std::is_unsigned, enum_t, false);
993 TEST (std::is_unsigned, struct_t, false);
994 TEST (std::is_unsigned, class_t, false);
995 TEST (std::is_unsigned, union_t, false);
996
997 TEST (std::is_unsigned, unsigned long&, false);
998 TEST (std::is_unsigned, unsigned long*, false);
999 TEST (std::is_unsigned, unsigned long [2], false);
1000 TEST (std::is_unsigned, unsigned long (), false);
1001}
1002
1003static void test_alignment_of ()
1004{
1005#ifdef _RWSTD_NO_ALIGN_TRAITS
1006
1007 rw_warn (0, 0, __LINE__,
1008 "test_alignment_of() disabled because "
1009 "_RWSTD_NO_ALIGN_TRAITS is defined");
1010
1011#else
1012
1013# undef TEST
1014# define TEST(Trait,Type) \
1015 test_trait (__LINE__, #Trait, #Type, \
1016 Trait<Type>::value, _RWSTD_TT_ALIGN_OF(Type))
1017
1018 TEST (std::alignment_of, signed char);
1019 TEST (std::alignment_of, signed short);
1020 TEST (std::alignment_of, signed int);
1021 TEST (std::alignment_of, signed long);
1022
1023 TEST (std::alignment_of, unsigned char);
1024 TEST (std::alignment_of, unsigned short);
1025 TEST (std::alignment_of, unsigned int);
1026 TEST (std::alignment_of, unsigned long);
1027
1028#ifndef _RWSTD_NO_LONG_LONG
1029 TEST (std::alignment_of, signed long long);
1030 TEST (std::alignment_of, unsigned long long);
1031#endif
1032
1033 TEST (std::alignment_of, float);
1034 TEST (std::alignment_of, double);
1035
1036#ifndef _RWSTD_NO_LONG_DOUBLE
1037 TEST (std::alignment_of, long double);
1038#endif
1039
1040 TEST (std::alignment_of, enum_t);
1041 TEST (std::alignment_of, struct_t);
1042 TEST (std::alignment_of, class_t);
1043 TEST (std::alignment_of, union_t);
1044 TEST (std::alignment_of, polymorphic_t);
1045
1046 TEST (std::alignment_of, void*);
1047
1048# undef TEST
1049#endif // _RWSTD_TT_ALIGN_OF
1050}
1051
1052static void test_rank ()
1053{
1054#undef TEST
1055#define TEST(Trait, Type, Expect) \
1056 test_trait (__LINE__, #Trait, #Type, Trait<Type>::value, Expect)
1057
1058 TEST (std::rank, int, 0ul);
1059 TEST (std::rank, int [2], 1ul);
1060 TEST (std::rank, int [][4], 2ul);
1061 TEST (std::rank, int [4][4], 2ul);
1062
1063 TEST (std::rank, void, 0ul);
1064 TEST (std::rank, void*, 0ul);
1065
1066#undef TEST
1067}
1068
1069static void test_extent ()
1070{
1071#undef TEST
1072#define TEST(Trait, Type, Depth, Expect) \
1073 test_trait (__LINE__, Depth, Trait<Type,Depth>::value, Expect, \
1074 #Trait, #Type)
1075
1076 TEST (std::extent, int, 0, 0ul);
1077 TEST (std::extent, int [2], 0, 2ul);
1078 TEST (std::extent, int [2][4], 0, 2ul);
1079 TEST (std::extent, int [][4], 0, 0ul);
1080
1081 TEST (std::extent, int, 1, 0ul);
1082 TEST (std::extent, int [2], 1, 0ul);
1083
1084 TEST (std::extent, int [2][4], 0, 2ul);
1085 TEST (std::extent, int [2][4], 1, 4ul);
1086 TEST (std::extent, int [2][4], 2, 0ul);
1087
1088 TEST (std::extent, int [][4], 0, 0ul);
1089 TEST (std::extent, int [][4], 1, 4ul);
1090 TEST (std::extent, int [][4], 2, 0ul);
1091
1092#undef TEST
1093}
1094
1095static int run_test (int, char* [])
1096{
1097 test_is_const ();
1099 test_is_trivial ();
1100 test_is_standard_layout ();
1101 test_is_pod ();
1102 test_is_empty ();
1103 test_is_polymorphic ();
1104 test_is_abstract ();
1105 test_has_trivial_constructor ();
1106 test_has_trivial_copy ();
1107 test_has_trivial_assign ();
1108 test_has_trivial_destructor ();
1109 test_has_nothrow_constructor ();
1110 test_has_nothrow_copy ();
1111 test_has_nothrow_assign ();
1112 test_has_virtual_destructor ();
1113 test_is_signed ();
1114 test_is_unsigned ();
1115 test_alignment_of ();
1116 test_rank ();
1117 test_extent ();
1118
1119 return 0;
1120}
1121
1122
1124#else // _RWSTD_NO_EXT_CXX_0X
1125
1126
1128static int run_test (int, char* [])
1129{
1130 rw_warn (0, 0, __LINE__,
1131 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
1132 return 0;
1133}
1134
1135#endif // !_RWSTD_NO_EXT_CXX_0X
1136
1137
1139int main (int argc, char* argv [])
1140{
1141 return rw_test (argc, argv, __FILE__,
1142 "meta.unary.prop",
1143 0 /* no comment*/,
1144 run_test,
1145 0);
1146}
#define T
Definition 17.names.cpp:163
#define rhs
Definition 17.names.cpp:536
#define v
Definition 17.names.cpp:138
#define line
Definition 17.names.cpp:490
#define U
Definition 17.names.cpp:164
enum_t
void test_is_const()
void test_is_volatile()
#define CV
void test_trait(int line, bool value, bool expect, const char *trait, const char *type)
void cfun_t()
#define TEST(Trait, Type, Expect)
#define V
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
#define main
#define _THROWS()
unsigned long ul
_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_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647
#define true
Definition stdbool.h:25
virtual void vfunc()=0
virtual ~abstract_t()
static access_controlled_t make(char, char)
no_trivial_assign_t & operator=(const no_trivial_assign_t &) _THROWS(())
no_trivial_copy_t(const no_trivial_copy_t &) _THROWS(())
no_trivial_ctor_t() _THROWS(())
virtual void vfunc()
throwing_assign_t & operator=(const throwing_assign_t &rhs)
throwing_copy_t(const throwing_copy_t &rhs)