]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_tr1.h
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004-2014 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20 //
21
22 #ifndef _GLIBCXX_TESTSUITE_TR1_H
23 #define _GLIBCXX_TESTSUITE_TR1_H
24
25 #include <ext/type_traits.h>
26
27 namespace __gnu_test
28 {
29 // For tr1/type_traits.
30 template<template<typename> class Category, typename Type>
31 #if __cplusplus >= 201103L
32 constexpr
33 #endif
34 bool
35 test_category(bool value)
36 {
37 return (Category<Type>::value == value
38 && Category<const Type>::value == value
39 && Category<volatile Type>::value == value
40 && Category<const volatile Type>::value == value
41 && Category<Type>::type::value == value
42 && Category<const Type>::type::value == value
43 && Category<volatile Type>::type::value == value
44 && Category<const volatile Type>::type::value == value);
45 }
46
47 template<template<typename> class Property, typename Type>
48 #if __cplusplus >= 201103L
49 constexpr
50 #endif
51 bool
52 test_property(typename Property<Type>::value_type value)
53 {
54 return (Property<Type>::value == value
55 && Property<Type>::type::value == value);
56 }
57
58 // For testing tr1/type_traits/extent, which has a second template
59 // parameter.
60 template<template<typename, unsigned> class Property,
61 typename Type, unsigned Uint>
62 #if __cplusplus >= 201103L
63 constexpr
64 #endif
65 bool
66 test_property(typename Property<Type, Uint>::value_type value)
67 {
68 return (Property<Type, Uint>::value == value
69 && Property<Type, Uint>::type::value == value);
70 }
71
72 #if __cplusplus >= 201103L
73 template<template<typename...> class Property,
74 typename Type1, typename... Types>
75 constexpr bool
76 test_property(typename Property<Type1, Types...>::value_type value)
77 {
78 return (Property<Type1, Types...>::value == value
79 && Property<Type1, Types...>::type::value == value);
80 }
81 #endif
82
83 template<template<typename, typename> class Relationship,
84 typename Type1, typename Type2>
85 #if __cplusplus >= 201103L
86 constexpr
87 #endif
88 bool
89 test_relationship(bool value)
90 {
91 return (Relationship<Type1, Type2>::value == value
92 && Relationship<Type1, Type2>::type::value == value);
93 }
94
95 // Test types.
96 class ClassType { };
97 typedef const ClassType cClassType;
98 typedef volatile ClassType vClassType;
99 typedef const volatile ClassType cvClassType;
100
101 class DerivedType : public ClassType { };
102
103 enum EnumType { e0 };
104
105 struct ConvType
106 { operator int() const; };
107
108 class AbstractClass
109 {
110 virtual void rotate(int) = 0;
111 };
112
113 class PolymorphicClass
114 {
115 virtual void rotate(int);
116 };
117
118 class DerivedPolymorphic : public PolymorphicClass { };
119
120 class VirtualDestructorClass
121 {
122 virtual ~VirtualDestructorClass();
123 };
124
125 union UnionType { };
126
127 class IncompleteClass;
128
129 struct ExplicitClass
130 {
131 ExplicitClass(double&);
132 explicit ExplicitClass(int&);
133 ExplicitClass(double&, int&, double&);
134 };
135
136 struct NothrowExplicitClass
137 {
138 NothrowExplicitClass(double&) throw();
139 explicit NothrowExplicitClass(int&) throw();
140 NothrowExplicitClass(double&, int&, double&) throw();
141 };
142
143 struct ThrowExplicitClass
144 {
145 ThrowExplicitClass(double&) throw(int);
146 explicit ThrowExplicitClass(int&) throw(int);
147 ThrowExplicitClass(double&, int&, double&) throw(int);
148 };
149
150 struct ThrowDefaultClass
151 {
152 ThrowDefaultClass() throw(int);
153 };
154
155 struct ThrowCopyConsClass
156 {
157 ThrowCopyConsClass(const ThrowCopyConsClass&) throw(int);
158 };
159
160 #if __cplusplus >= 201103L
161 struct ThrowMoveConsClass
162 {
163 ThrowMoveConsClass(ThrowMoveConsClass&&) throw(int);
164 };
165
166 struct NoexceptExplicitClass
167 {
168 NoexceptExplicitClass(double&) noexcept(true);
169 explicit NoexceptExplicitClass(int&) noexcept(true);
170 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
171 };
172
173 struct ExceptExplicitClass
174 {
175 ExceptExplicitClass(double&) noexcept(false);
176 explicit ExceptExplicitClass(int&) noexcept(false);
177 ExceptExplicitClass(double&, int&, double&) noexcept(false);
178 };
179
180 struct NoexceptDefaultClass
181 {
182 NoexceptDefaultClass() noexcept(true);
183 };
184
185 struct ExceptDefaultClass
186 {
187 ExceptDefaultClass() noexcept(false);
188 };
189
190 struct NoexceptCopyConsClass
191 {
192 NoexceptCopyConsClass(const NoexceptCopyConsClass&) noexcept(true);
193 };
194
195 struct ExceptCopyConsClass
196 {
197 ExceptCopyConsClass(const ExceptCopyConsClass&) noexcept(false);
198 };
199
200 struct NoexceptMoveConsClass
201 {
202 NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
203 NoexceptMoveConsClass& operator=(NoexceptMoveConsClass&&) = default;
204 };
205
206 struct ExceptMoveConsClass
207 {
208 ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
209 };
210
211 struct NoexceptCopyAssignClass
212 {
213 NoexceptCopyAssignClass&
214 operator=(const NoexceptCopyAssignClass&) noexcept(true);
215 };
216
217 struct ExceptCopyAssignClass
218 {
219 ExceptCopyAssignClass&
220 operator=(const ExceptCopyAssignClass&) noexcept(false);
221 };
222
223 struct NoexceptMoveAssignClass
224 {
225 NoexceptMoveAssignClass(NoexceptMoveAssignClass&&) = default;
226 NoexceptMoveAssignClass&
227 operator=(NoexceptMoveAssignClass&&) noexcept(true);
228 };
229
230 struct ExceptMoveAssignClass
231 {
232 ExceptMoveAssignClass&
233 operator=(ExceptMoveAssignClass&&) noexcept(false);
234 };
235
236 struct DeletedCopyAssignClass
237 {
238 DeletedCopyAssignClass&
239 operator=(const DeletedCopyAssignClass&) = delete;
240 };
241
242 struct DeletedMoveAssignClass
243 {
244 DeletedMoveAssignClass&
245 operator=(DeletedMoveAssignClass&&) = delete;
246 };
247
248 struct NoexceptMoveConsNoexceptMoveAssignClass
249 {
250 NoexceptMoveConsNoexceptMoveAssignClass
251 (NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
252
253 NoexceptMoveConsNoexceptMoveAssignClass&
254 operator=(NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
255 };
256
257 struct ExceptMoveConsNoexceptMoveAssignClass
258 {
259 ExceptMoveConsNoexceptMoveAssignClass
260 (ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(false);
261
262 ExceptMoveConsNoexceptMoveAssignClass&
263 operator=(ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
264 };
265
266 struct NoexceptMoveConsExceptMoveAssignClass
267 {
268 NoexceptMoveConsExceptMoveAssignClass
269 (NoexceptMoveConsExceptMoveAssignClass&&) noexcept(true);
270
271 NoexceptMoveConsExceptMoveAssignClass&
272 operator=(NoexceptMoveConsExceptMoveAssignClass&&) noexcept(false);
273 };
274
275 struct ExceptMoveConsExceptMoveAssignClass
276 {
277 ExceptMoveConsExceptMoveAssignClass
278 (ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
279
280 ExceptMoveConsExceptMoveAssignClass&
281 operator=(ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
282 };
283 #endif
284
285 struct NType // neither trivial nor standard-layout
286 {
287 int i;
288 int j;
289 virtual ~NType();
290 };
291
292 struct TType // trivial but not standard-layout
293 {
294 int i;
295 private:
296 int j;
297 };
298
299 struct SLType // standard-layout but not trivial
300 {
301 int i;
302 int j;
303 ~SLType();
304 };
305
306 struct PODType // both trivial and standard-layout
307 {
308 int i;
309 int j;
310 };
311
312 #if __cplusplus >= 201103L
313 struct LType // literal type
314 {
315 int _M_i;
316
317 constexpr LType(int __i) : _M_i(__i) { }
318 };
319
320 struct LTypeDerived : public LType
321 {
322 constexpr LTypeDerived(int __i) : LType(__i) { }
323 };
324
325 struct NLType // not literal type
326 {
327 int _M_i;
328
329 NLType() : _M_i(0) { }
330
331 constexpr NLType(int __i) : _M_i(__i) { }
332
333 NLType(const NLType& __other) : _M_i(__other._M_i) { }
334
335 ~NLType() { _M_i = 0; }
336 };
337 #endif
338
339 int truncate_float(float x) { return (int)x; }
340 long truncate_double(double x) { return (long)x; }
341
342 struct do_truncate_float_t
343 {
344 do_truncate_float_t()
345 {
346 ++live_objects;
347 }
348
349 do_truncate_float_t(const do_truncate_float_t&)
350 {
351 ++live_objects;
352 }
353
354 ~do_truncate_float_t()
355 {
356 --live_objects;
357 }
358
359 int operator()(float x) { return (int)x; }
360
361 static int live_objects;
362 };
363
364 int do_truncate_float_t::live_objects = 0;
365
366 struct do_truncate_double_t
367 {
368 do_truncate_double_t()
369 {
370 ++live_objects;
371 }
372
373 do_truncate_double_t(const do_truncate_double_t&)
374 {
375 ++live_objects;
376 }
377
378 ~do_truncate_double_t()
379 {
380 --live_objects;
381 }
382
383 long operator()(double x) { return (long)x; }
384
385 static int live_objects;
386 };
387
388 int do_truncate_double_t::live_objects = 0;
389
390 struct X
391 {
392 int bar;
393
394 int foo() { return 1; }
395 int foo_c() const { return 2; }
396 int foo_v() volatile { return 3; }
397 int foo_cv() const volatile { return 4; }
398 };
399
400 // For use in 8_c_compatibility.
401 template<typename R, typename T>
402 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
403 bool>::__type
404 check_ret_type(T)
405 { return true; }
406
407 #if __cplusplus >= 201103L
408 namespace construct
409 {
410 struct Empty {};
411
412 struct B { int i; B(){} };
413 struct D : B {};
414
415 enum E { ee1 };
416 enum E2 { ee2 };
417 enum class SE { e1 };
418 enum class SE2 { e2 };
419
420 enum OpE : int;
421 enum class OpSE : bool;
422
423 union U { int i; Empty b; };
424
425 struct Abstract
426 {
427 virtual ~Abstract() = 0;
428 };
429
430 struct AbstractDelDtor
431 {
432 ~AbstractDelDtor() = delete;
433 virtual void foo() = 0;
434 };
435
436 struct Ukn;
437
438 template<class To>
439 struct ImplicitTo
440 {
441 operator To();
442 };
443
444 template<class To>
445 struct DelImplicitTo
446 {
447 operator To() = delete;
448 };
449
450 template<class To>
451 struct ExplicitTo
452 {
453 explicit operator To();
454 };
455
456 struct Ellipsis
457 {
458 Ellipsis(...){}
459 };
460
461 struct DelEllipsis
462 {
463 DelEllipsis(...) = delete;
464 };
465
466 struct Any
467 {
468 template<class T>
469 Any(T&&){}
470 };
471
472 struct nAny
473 {
474 template<class... T>
475 nAny(T&&...){}
476 };
477
478 struct DelnAny
479 {
480 template<class... T>
481 DelnAny(T&&...) = delete;
482 };
483
484 template<class... Args>
485 struct FromArgs
486 {
487 FromArgs(Args...);
488 };
489
490 struct DelDef
491 {
492 DelDef() = delete;
493 };
494
495 struct DelCopy
496 {
497 DelCopy(const DelCopy&) = delete;
498 };
499
500 struct DelDtor
501 {
502 DelDtor() = default;
503 DelDtor(const DelDtor&) = default;
504 DelDtor(DelDtor&&) = default;
505 DelDtor(int);
506 DelDtor(int, B, U);
507 ~DelDtor() = delete;
508 };
509
510 struct Nontrivial
511 {
512 Nontrivial();
513 Nontrivial(const Nontrivial&);
514 Nontrivial& operator=(const Nontrivial&);
515 ~Nontrivial();
516 };
517
518 union NontrivialUnion
519 {
520 int i;
521 Nontrivial n;
522 };
523
524 struct UnusualCopy
525 {
526 UnusualCopy(UnusualCopy&);
527 };
528 }
529
530 namespace destruct
531 {
532 struct E
533 {};
534
535 struct NTD1
536 {
537 ~NTD1() = default;
538 };
539
540 struct NTD2
541 {
542 ~NTD2();
543 };
544
545 struct NTD3
546 {
547 ~NTD3() throw();
548 };
549
550 struct TD1
551 {
552 ~TD1() noexcept(false);
553 };
554
555 struct TD2
556 {
557 ~TD2() throw(int);
558 };
559
560 struct Aggr
561 {
562 int i;
563 bool b;
564 E e;
565 };
566
567 struct Aggr2
568 {
569 int i;
570 bool b;
571 TD1 r;
572 };
573
574 struct Del
575 {
576 ~Del() = delete;
577 };
578
579 struct Del2
580 {
581 ~Del2() noexcept = delete;
582 };
583
584 struct Del3
585 {
586 ~Del3() noexcept(false) = delete;
587 };
588
589 struct Der : Aggr
590 {};
591
592 struct Der2 : Aggr2
593 {};
594
595 union U1
596 {
597 int i;
598 double d;
599 void* p;
600 TD1* pt;
601 };
602
603 union Ut
604 {
605 int i;
606 double d;
607 void* p;
608 TD1 pt;
609 };
610
611 enum class En { a, b, c, d };
612 enum En2 { En2a, En2b, En2c, En2d };
613
614 enum OpE : int;
615 enum class OpSE : bool;
616
617 struct Abstract1
618 {
619 virtual ~Abstract1() = 0;
620 };
621
622 struct AbstractDelDtor
623 {
624 ~AbstractDelDtor() = delete;
625 virtual void foo() = 0;
626 };
627
628 struct Abstract2
629 {
630 virtual ~Abstract2() noexcept(false) = 0;
631 };
632
633 struct Abstract3
634 {
635 ~Abstract3() noexcept(false);
636 virtual void foo() noexcept = 0;
637 };
638
639 struct Nontrivial
640 {
641 Nontrivial();
642 Nontrivial(const Nontrivial&);
643 Nontrivial& operator=(const Nontrivial&);
644 ~Nontrivial();
645 };
646
647 union NontrivialUnion
648 {
649 int i;
650 Nontrivial n;
651 };
652
653 struct UnusualCopy
654 {
655 UnusualCopy(UnusualCopy&);
656 };
657
658 struct Ellipsis
659 {
660 Ellipsis(...){}
661 };
662
663 struct DelEllipsis
664 {
665 DelEllipsis(...) = delete;
666 };
667
668 struct DelDef
669 {
670 DelDef() = delete;
671 };
672
673 struct DelCopy
674 {
675 DelCopy(const DelCopy&) = delete;
676 };
677 }
678
679 namespace assign
680 {
681 struct Empty {};
682
683 struct B { int i; B(){} };
684 struct D : B {};
685
686 enum E { ee1 };
687 enum E2 { ee2 };
688 enum class SE { e1 };
689 enum class SE2 { e2 };
690
691 enum OpE : int;
692 enum class OpSE : bool;
693
694 union U { int i; Empty b; };
695
696 union UAssignAll
697 {
698 bool b;
699 char c;
700 template<class T>
701 void operator=(T&&);
702 };
703
704 union UDelAssignAll
705 {
706 bool b;
707 char c;
708 template<class T>
709 void operator=(T&&) = delete;
710 };
711
712 struct Abstract
713 {
714 virtual ~Abstract() = 0;
715 };
716
717 struct AbstractDelDtor
718 {
719 ~AbstractDelDtor() = delete;
720 virtual void foo() = 0;
721 };
722
723 struct Ukn;
724
725 template<class To>
726 struct ImplicitTo
727 {
728 operator To();
729 };
730
731 template<class To>
732 struct ExplicitTo
733 {
734 explicit operator To();
735 };
736
737 template<class To>
738 struct DelImplicitTo
739 {
740 operator To() = delete;
741 };
742
743 template<class To>
744 struct DelExplicitTo
745 {
746 explicit operator To() = delete;
747 };
748
749 struct Ellipsis
750 {
751 Ellipsis(...){}
752 };
753
754 struct DelEllipsis
755 {
756 DelEllipsis(...) = delete;
757 };
758
759 struct Any
760 {
761 template<class T>
762 Any(T&&){}
763 };
764
765 struct nAny
766 {
767 template<class... T>
768 nAny(T&&...){}
769 };
770
771 struct DelnAny
772 {
773 template<class... T>
774 DelnAny(T&&...) = delete;
775 };
776
777 template<class... Args>
778 struct FromArgs
779 {
780 FromArgs(Args...);
781 };
782
783 template<class... Args>
784 struct DelFromArgs
785 {
786 DelFromArgs(Args...) = delete;
787 };
788
789 struct DelDef
790 {
791 DelDef() = delete;
792 };
793
794 struct DelCopy
795 {
796 DelCopy(const DelCopy&) = delete;
797 };
798
799 struct DelDtor
800 {
801 DelDtor() = default;
802 DelDtor(const DelDtor&) = default;
803 DelDtor(DelDtor&&) = default;
804 DelDtor(int);
805 DelDtor(int, B, U);
806 ~DelDtor() = delete;
807 };
808
809 struct Nontrivial
810 {
811 Nontrivial();
812 Nontrivial(const Nontrivial&);
813 Nontrivial& operator=(const Nontrivial&);
814 ~Nontrivial();
815 };
816
817 union NontrivialUnion
818 {
819 int i;
820 Nontrivial n;
821 };
822
823 struct UnusualCopy
824 {
825 UnusualCopy(UnusualCopy&);
826 };
827
828 struct AnyAssign
829 {
830 template<class T>
831 void operator=(T&&);
832 };
833
834 struct DelAnyAssign
835 {
836 template<class T>
837 void operator=(T&&) = delete;
838 };
839
840 struct DelCopyAssign
841 {
842 DelCopyAssign& operator=(const DelCopyAssign&) = delete;
843 DelCopyAssign& operator=(DelCopyAssign&&) = default;
844 };
845
846 struct MO
847 {
848 MO(MO&&) = default;
849 MO& operator=(MO&&) = default;
850 };
851 }
852
853 struct CopyConsOnlyType
854 {
855 CopyConsOnlyType(int) { }
856 CopyConsOnlyType(CopyConsOnlyType&&) = delete;
857 CopyConsOnlyType(const CopyConsOnlyType&) = default;
858 CopyConsOnlyType& operator=(const CopyConsOnlyType&) = delete;
859 CopyConsOnlyType& operator=(CopyConsOnlyType&&) = delete;
860 };
861
862 struct MoveConsOnlyType
863 {
864 MoveConsOnlyType(int) { }
865 MoveConsOnlyType(const MoveConsOnlyType&) = delete;
866 MoveConsOnlyType(MoveConsOnlyType&&) = default;
867 MoveConsOnlyType& operator=(const MoveConsOnlyType&) = delete;
868 MoveConsOnlyType& operator=(MoveConsOnlyType&&) = delete;
869 };
870 #endif
871
872 } // namespace __gnu_test
873
874 #endif // _GLIBCXX_TESTSUITE_TR1_H