OSDN Git Service

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