]> 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
493bc460
PC
1// -*- C++ -*-
2// Testing utilities for the tr1 testsuite.
3//
7adcbafe 4// Copyright (C) 2004-2022 Free Software Foundation, Inc.
493bc460
PC
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
748086b7 9// Free Software Foundation; either version 3, or (at your option)
493bc460
PC
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
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
493bc460 20//
493bc460
PC
21
22#ifndef _GLIBCXX_TESTSUITE_TR1_H
23#define _GLIBCXX_TESTSUITE_TR1_H
24
105c6331 25#include <ext/type_traits.h>
1f153a1d 26#include <testsuite_hooks.h>
ab44b018 27
493bc460 28namespace __gnu_test
0179f2c6 29{
493bc460 30 // For tr1/type_traits.
105c6331 31 template<template<typename> class Category, typename Type>
44916fe1
PC
32#if __cplusplus >= 201103L
33 constexpr
34#endif
493bc460 35 bool
db5ff236 36 test_category(bool value)
493bc460 37 {
44916fe1
PC
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);
493bc460 46 }
0f910b4f 47
e7e93965
MM
48 // For testing tr1/type_traits/extent, which has a second template
49 // parameter.
50 template<template<typename, unsigned> class Property,
f706cf18 51 typename Type, unsigned Uint>
44916fe1
PC
52#if __cplusplus >= 201103L
53 constexpr
54#endif
e7e93965
MM
55 bool
56 test_property(typename Property<Type, Uint>::value_type value)
57 {
44916fe1
PC
58 return (Property<Type, Uint>::value == value
59 && Property<Type, Uint>::type::value == value);
e7e93965
MM
60 }
61
734f5023 62#if __cplusplus >= 201103L
d6027563
JM
63 template<template<typename...> class Property,
64 typename Type1, typename... Types>
44916fe1 65 constexpr bool
d6027563 66 test_property(typename Property<Type1, Types...>::value_type value)
75995f37 67 {
44916fe1
PC
68 return (Property<Type1, Types...>::value == value
69 && Property<Type1, Types...>::type::value == value);
75995f37 70 }
57a6add2
JM
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 }
b0302c68
PC
79#endif
80
d63a0e22 81 template<template<typename, typename> class Relationship,
f706cf18 82 typename Type1, typename Type2>
44916fe1
PC
83#if __cplusplus >= 201103L
84 constexpr
85#endif
d63a0e22 86 bool
db5ff236 87 test_relationship(bool value)
d63a0e22 88 {
44916fe1
PC
89 return (Relationship<Type1, Type2>::value == value
90 && Relationship<Type1, Type2>::type::value == value);
d63a0e22
PC
91 }
92
0f910b4f
PC
93 // Test types.
94 class ClassType { };
d63a0e22
PC
95 typedef const ClassType cClassType;
96 typedef volatile ClassType vClassType;
97 typedef const volatile ClassType cvClassType;
a9e7ba81 98
c150a271
PC
99 class DerivedType : public ClassType { };
100
4db7fcb9
ESR
101#if __cplusplus >= 201103L
102 class FinalType final : public DerivedType { };
103#endif
104
dcd400b5 105 enum EnumType { e0 };
a9e7ba81
PC
106
107 struct ConvType
108 { operator int() const; };
f8023b78
PC
109
110 class AbstractClass
59cffcf6 111 {
cff001b2 112 virtual void rotate(int) = 0;
cff001b2 113 };
0179f2c6 114
442dca70 115 class PolymorphicClass
59cffcf6 116 {
cff001b2 117 virtual void rotate(int);
cff001b2 118 };
442dca70 119
59cffcf6 120 class DerivedPolymorphic : public PolymorphicClass { };
442dca70 121
22931aa4
PC
122 class VirtualDestructorClass
123 {
124 virtual ~VirtualDestructorClass();
125 };
126
9e38f702 127 union UnionType { };
0179f2c6 128
608a080c
AP
129 union IncompleteUnion;
130
516ebd44 131 class IncompleteClass;
0179f2c6 132
75995f37
PC
133 struct ExplicitClass
134 {
135 ExplicitClass(double&);
136 explicit ExplicitClass(int&);
e4f32cb0 137 ExplicitClass(double&, int&, double&);
75995f37
PC
138 };
139
e4f32cb0
PC
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 {
1f153a1d
JW
149 ThrowExplicitClass(double&) THROW(int);
150 explicit ThrowExplicitClass(int&) THROW(int);
151 ThrowExplicitClass(double&, int&, double&) THROW(int);
e4f32cb0
PC
152 };
153
65cee9bd
PC
154 struct ThrowDefaultClass
155 {
1f153a1d 156 ThrowDefaultClass() THROW(int);
65cee9bd
PC
157 };
158
159 struct ThrowCopyConsClass
160 {
1f153a1d 161 ThrowCopyConsClass(const ThrowCopyConsClass&) THROW(int);
65cee9bd
PC
162 };
163
734f5023 164#if __cplusplus >= 201103L
65cee9bd
PC
165 struct ThrowMoveConsClass
166 {
34c71b8b 167 ThrowMoveConsClass(ThrowMoveConsClass&&) noexcept(false);
65cee9bd
PC
168 };
169
e4f32cb0
PC
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);
65cee9bd
PC
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);
830dea94 207 NoexceptMoveConsClass& operator=(NoexceptMoveConsClass&&) = default;
65cee9bd
PC
208 };
209
210 struct ExceptMoveConsClass
211 {
212 ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
e4f32cb0 213 };
f263981a
PC
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 {
830dea94 229 NoexceptMoveAssignClass(NoexceptMoveAssignClass&&) = default;
f263981a
PC
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 };
173f26ae
PC
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 };
e4f32cb0
PC
287#endif
288
54add740
PC
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
734f5023 316#if __cplusplus >= 201103L
f706cf18
BK
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
9e38f702
PC
343 int truncate_float(float x) { return (int)x; }
344 long truncate_double(double x) { return (long)x; }
0179f2c6 345
9e38f702
PC
346 struct do_truncate_float_t
347 {
348 do_truncate_float_t()
349 {
350 ++live_objects;
351 }
0179f2c6 352
9e38f702
PC
353 do_truncate_float_t(const do_truncate_float_t&)
354 {
355 ++live_objects;
356 }
59cffcf6 357
9e38f702
PC
358 ~do_truncate_float_t()
359 {
360 --live_objects;
361 }
0179f2c6 362
9e38f702 363 int operator()(float x) { return (int)x; }
59cffcf6 364
9e38f702
PC
365 static int live_objects;
366 };
0179f2c6 367
9e38f702 368 int do_truncate_float_t::live_objects = 0;
0179f2c6 369
9e38f702
PC
370 struct do_truncate_double_t
371 {
372 do_truncate_double_t()
373 {
0179f2c6 374 ++live_objects;
9e38f702 375 }
0179f2c6 376
9e38f702
PC
377 do_truncate_double_t(const do_truncate_double_t&)
378 {
379 ++live_objects;
380 }
0179f2c6 381
9e38f702
PC
382 ~do_truncate_double_t()
383 {
384 --live_objects;
385 }
0179f2c6 386
9e38f702 387 long operator()(double x) { return (long)x; }
59cffcf6 388
9e38f702
PC
389 static int live_objects;
390 };
59cffcf6 391
9e38f702 392 int do_truncate_double_t::live_objects = 0;
59cffcf6 393
9e38f702
PC
394 struct X
395 {
396 int bar;
59cffcf6 397
9e38f702
PC
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 };
90922b2d
PC
403
404 // For use in 8_c_compatibility.
405 template<typename R, typename T>
f706cf18 406 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
105c6331 407 bool>::__type
90922b2d
PC
408 check_ret_type(T)
409 { return true; }
410
734f5023 411#if __cplusplus >= 201103L
62fa805f 412 namespace construct
123c516a
PC
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 }
f263981a 533
62fa805f
DK
534 namespace destruct
535 {
536 struct E
537 {};
f92ab29f 538
62fa805f
DK
539 struct NTD1
540 {
541 ~NTD1() = default;
542 };
f92ab29f 543
62fa805f
DK
544 struct NTD2
545 {
546 ~NTD2();
547 };
f92ab29f 548
62fa805f
DK
549 struct NTD3
550 {
551 ~NTD3() throw();
552 };
f92ab29f 553
62fa805f
DK
554 struct TD1
555 {
556 ~TD1() noexcept(false);
557 };
f92ab29f 558
62fa805f
DK
559 struct TD2
560 {
1f153a1d 561 ~TD2() THROW(int);
62fa805f 562 };
f92ab29f 563
62fa805f
DK
564 struct Aggr
565 {
566 int i;
567 bool b;
568 E e;
569 };
f92ab29f 570
62fa805f
DK
571 struct Aggr2
572 {
573 int i;
574 bool b;
575 TD1 r;
576 };
f92ab29f 577
62fa805f
DK
578 struct Del
579 {
580 ~Del() = delete;
581 };
f92ab29f 582
62fa805f
DK
583 struct Del2
584 {
585 ~Del2() noexcept = delete;
586 };
f92ab29f 587
62fa805f
DK
588 struct Del3
589 {
590 ~Del3() noexcept(false) = delete;
591 };
f92ab29f 592
62fa805f
DK
593 struct Der : Aggr
594 {};
f92ab29f 595
62fa805f
DK
596 struct Der2 : Aggr2
597 {};
f92ab29f 598
62fa805f
DK
599 union U1
600 {
601 int i;
602 double d;
603 void* p;
604 TD1* pt;
605 };
f92ab29f 606
62fa805f
DK
607 union Ut
608 {
609 int i;
610 double d;
611 void* p;
612 TD1 pt;
613 };
f92ab29f 614
62fa805f
DK
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 };
f92ab29f 625
62fa805f
DK
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 };
f92ab29f 636
62fa805f
DK
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 }
f92ab29f 682
f263981a
PC
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 }
cc2ba8e3
PC
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 };
123c516a
PC
874#endif
875
59cffcf6 876} // namespace __gnu_test
493bc460
PC
877
878#endif // _GLIBCXX_TESTSUITE_TR1_H