OSDN Git Service

e108288586ecbcab08ac0d57c20d2fcfbb5e4067
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / insert / 25288.cc
1 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 23.2.2.3 list modifiers [lib.list.modifiers]
19
20 // { dg-require-time "" }
21
22 #include <list>
23 #include <testsuite_hooks.h>
24 #include <ext/throw_allocator.h>
25
26 // libstdc++/25288
27 template<typename _Tp>
28 void insert1()
29 {
30   bool test __attribute__((unused)) = true;
31
32   typedef _Tp list_type;
33   typedef typename _Tp::value_type value_type;
34   typedef typename _Tp::allocator_type allocator_type;
35   typedef typename _Tp::size_type size_type;
36
37   for (int j = 0; j < 10; ++j)
38     for (int i = 0; i < 10; ++i)
39       {
40         allocator_type alloc1;
41         typename allocator_type::never_adjustor adjust1;
42         list_type list1(alloc1);
43         
44         for (int k = 0; k < j; ++k)
45           list1.push_back(value_type(-(k + 1)));
46       
47         try
48           {
49             typename allocator_type::always_adjustor adjust2;
50             list1.insert(list1.begin(), 10, 99);
51             VERIFY( false );
52           }
53         catch (__gnu_cxx::forced_exception_error&)
54           {
55             VERIFY( true );
56           }
57         catch (...)
58           {
59             __throw_exception_again;
60           }
61         
62         VERIFY( list1.size() == size_type(j) );
63         VERIFY( list1.size() == 0 || list1.back() == -j );
64         VERIFY( list1.size() == 0 || list1.front() == -1 );
65
66         allocator_type alloc2;
67         list_type list2(alloc2);
68         
69         const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
70         
71         for (int k = 0; k < j; ++k)
72           list2.push_back(-(k + 1));
73         
74         try
75           {
76             typename allocator_type::always_adjustor adjust3;
77             list2.insert(list2.begin(), data, data + 10);
78             VERIFY( false );
79           }
80         catch (__gnu_cxx::forced_exception_error&)
81           {
82             VERIFY( true );
83           }
84         catch (...)
85           {
86             VERIFY( false );
87           }
88
89         VERIFY( list2.size() == size_type(j) );
90         VERIFY( list2.size() == 0 || list2.back() == -j );
91         VERIFY( list2.size() == 0 || list2.front() == -1 );
92       }
93 }
94
95 int main()
96 {
97   typedef int value_type;
98   typedef __gnu_cxx::throw_allocator<value_type> allocator_type;
99   typedef std::list<value_type, allocator_type> list_type;
100
101   insert1<list_type>();
102   return 0;
103 }