summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h
blob: 772128d95bf362a40ed6476891c24c0502cf3157 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// 23.2.2.3 list modifiers [lib.list.modifiers]

#include <testsuite_hooks.h>
#include <ext/throw_allocator.h>

// libstdc++/25288
template<typename _Tp>
void insert1()
{
  bool test __attribute__((unused)) = true;

  typedef _Tp list_type;
  typedef typename _Tp::value_type value_type;
  typedef typename _Tp::allocator_type allocator_type;
  typedef typename _Tp::size_type size_type;

  for (int j = 0; j < 10; ++j)
    for (int i = 0; i < 10; ++i)
      {
	allocator_type alloc1;
	typename allocator_type::never_adjustor adjust1;
	list_type list1(alloc1);
	
	for (int k = 0; k < j; ++k)
	  list1.push_back(value_type(-(k + 1)));
      
	try
	  {
	    typename allocator_type::always_adjustor adjust2;
	    list1.insert(list1.begin(), 10, 99);
	    VERIFY( false );
	  }
	catch (__gnu_cxx::forced_error&)
	  {
	    VERIFY( true );
	  }
	catch (...)
	  {
	    __throw_exception_again;
	  }
	
	VERIFY( list1.size() == size_type(j) );
	VERIFY( list1.size() == 0 || list1.back() == -j );
	VERIFY( list1.size() == 0 || list1.front() == -1 );

	allocator_type alloc2;
	list_type list2(alloc2);
	
	const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	
	for (int k = 0; k < j; ++k)
	  list2.push_back(-(k + 1));
	
	try
	  {
	    typename allocator_type::always_adjustor adjust3;
	    list2.insert(list2.begin(), data, data + 10);
	    VERIFY( false );
	  }
	catch (__gnu_cxx::forced_error&)
	  {
	    VERIFY( true );
	  }
	catch (...)
	  {
	    VERIFY( false );
	  }

	VERIFY( list2.size() == size_type(j) );
	VERIFY( list2.size() == 0 || list2.back() == -j );
	VERIFY( list2.size() == 0 || list2.front() == -1 );
      }
}