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