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