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#include <testsuite_hooks.h> 21#include <ext/throw_allocator.h> 22 23// libstdc++/25288 24template<typename _Tp> 25void insert1() 26{ 27 bool test __attribute__((unused)) = true; 28 29 typedef _Tp list_type; 30 typedef typename _Tp::value_type value_type; 31 typedef typename _Tp::allocator_type allocator_type; 32 typedef typename _Tp::size_type size_type; 33 34 for (int j = 0; j < 10; ++j) 35 for (int i = 0; i < 10; ++i) 36 { 37 allocator_type alloc1; 38 typename allocator_type::never_adjustor adjust1; 39 list_type list1(alloc1); 40 41 for (int k = 0; k < j; ++k) 42 list1.push_back(value_type(-(k + 1))); 43 44 try 45 { 46 typename allocator_type::always_adjustor adjust2; 47 list1.insert(list1.begin(), 10, 99); 48 VERIFY( false ); 49 } 50 catch (__gnu_cxx::forced_error&) 51 { 52 VERIFY( true ); 53 } 54 catch (...) 55 { 56 __throw_exception_again; 57 } 58 59 VERIFY( list1.size() == size_type(j) ); 60 VERIFY( list1.size() == 0 || list1.back() == -j ); 61 VERIFY( list1.size() == 0 || list1.front() == -1 ); 62 63 allocator_type alloc2; 64 list_type list2(alloc2); 65 66 const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 67 68 for (int k = 0; k < j; ++k) 69 list2.push_back(-(k + 1)); 70 71 try 72 { 73 typename allocator_type::always_adjustor adjust3; 74 list2.insert(list2.begin(), data, data + 10); 75 VERIFY( false ); 76 } 77 catch (__gnu_cxx::forced_error&) 78 { 79 VERIFY( true ); 80 } 81 catch (...) 82 { 83 VERIFY( false ); 84 } 85 86 VERIFY( list2.size() == size_type(j) ); 87 VERIFY( list2.size() == 0 || list2.back() == -j ); 88 VERIFY( list2.size() == 0 || list2.front() == -1 ); 89 } 90} 91