1 // { dg-do run { target c++11 } }
2 // { dg-require-effective-target cxx11-abi }
3 
4 // 2019-05-27  Nina Dinka Ranns  <dinka.ranns@gmail.com>
5 //
6 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library.  This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
13 
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3.  If not see
21 // <http://www.gnu.org/licenses/>.
22 
23 #include <string>
24 #include <testsuite_hooks.h>
25 
26 using C = char;
27 using traits = std::char_traits<C>;
28 int constructCount = 0;
29 
resetCounter()30 static void resetCounter()
31 {
32  constructCount = 0;
33 }
34 
35 template <class Tp>
36 struct TestAllocator
37 {
38   typedef Tp value_type;
39   using size_type = unsigned;
40 
TestAllocatorTestAllocator41   TestAllocator() noexcept { constructCount++; }
42 
43   template <class T>
TestAllocatorTestAllocator44   TestAllocator(const TestAllocator<T>&) {}
45 
allocateTestAllocator46   Tp *allocate(std::size_t n)
47   { return std::allocator<Tp>().allocate(n); }
48 
deallocateTestAllocator49   void deallocate(Tp *p, std::size_t n)
50   { std::allocator<Tp>().deallocate(p, n); }
51 
52 };
53 
54 template <class T, class U>
operator ==(const TestAllocator<T> &,const TestAllocator<U> &)55 bool operator==(const TestAllocator<T>&, const TestAllocator<U>&)
56 { return true; }
57 template <class T, class U>
operator !=(const TestAllocator<T> &,const TestAllocator<U> &)58 bool operator!=(const TestAllocator<T>&, const TestAllocator<U>&)
59 { return false; }
60 
test01()61 void test01()
62 {
63   typedef TestAllocator<C> alloc_type;
64   typedef std::basic_string<C, traits, alloc_type> test_type;
65   test_type v1{alloc_type()};
66   std::string v2{"some_content"};
67 
68   resetCounter();
69   v1.assign(v2.begin(),v2.end());
70   VERIFY( constructCount == 0);
71 
72   v1.append(v2.begin(),v2.end());
73   VERIFY( constructCount == 0);
74 
75   v1.insert(v1.begin(),v1.begin(),v1.end());
76   VERIFY( constructCount == 0);
77 
78   v1.replace(v1.begin(),v1.end(),v1.begin(),v1.end());
79   VERIFY( constructCount == 0);
80 }
main()81 int main()
82 {
83   test01();
84   return 0;
85 }
86