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