]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/56166.cc
1 // Copyright (C) 2016-2018 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
22 #ifndef _GLIBCXX_USE_CXX11_ABI
23 # define _GLIBCXX_USE_CXX11_ABI 0
28 static int fail_after
= -1;
35 // Need these typedefs because COW string doesn't use allocator_traits.
37 using const_pointer
= const T
*;
39 using const_reference
= const T
&;
40 using difference_type
= long;
41 using size_type
= unsigned long;
44 using other
= Allocator
<U
>;
50 Allocator(const Allocator
<U
>&) { }
52 T
* allocate(size_type n
)
54 if (fail_after
>= 0) {
55 if (fail_after
-- == 0) {
56 throw std::bad_alloc();
59 return (T
*)new char[n
* sizeof(T
)];
62 void deallocate(T
* p
, size_type
)
68 template<typename T
, typename U
>
69 bool operator==(const Allocator
<T
>&, const Allocator
<U
>&) { return true; }
70 template<typename T
, typename U
>
71 bool operator!=(const Allocator
<T
>&, const Allocator
<U
>&) { return false; }
73 using string
= std::basic_string
<char, std::char_traits
<char>, Allocator
<char>>;
85 for (int i
= 0; i
< 10; i
++) {
90 } catch (std::bad_alloc
) {