]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/lwg2788.cc
libstdc++: Replace hyphens in effective target keywords
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / allocator / wchar_t / lwg2788.cc
CommitLineData
046af809 1// { dg-do run { target c++11 } }
a04b73e1 2// { dg-require-effective-target cxx11_abi }
046af809
NDR
3
4// 2019-05-27 Nina Dinka Ranns <dinka.ranns@gmail.com>
5//
99dee823 6// Copyright (C) 2015-2021 Free Software Foundation, Inc.
046af809
NDR
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
26using C = wchar_t;
27using traits = std::char_traits<C>;
28int constructCount = 0;
29
30static void resetCounter()
31{
32 constructCount = 0;
33}
34
35template <class Tp>
36struct TestAllocator
37{
38 typedef Tp value_type;
39 using size_type = unsigned;
40
41 TestAllocator() noexcept { constructCount++; }
42
43 template <class T>
44 TestAllocator(const TestAllocator<T>&) {}
45
46 Tp *allocate(std::size_t n)
47 { return std::allocator<Tp>().allocate(n); }
48
49 void deallocate(Tp *p, std::size_t n)
50 { std::allocator<Tp>().deallocate(p, n); }
51
52};
53
54template <class T, class U>
55bool operator==(const TestAllocator<T>&, const TestAllocator<U>&)
56{ return true; }
57template <class T, class U>
58bool operator!=(const TestAllocator<T>&, const TestAllocator<U>&)
59{ return false; }
60
61void 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::wstring v2{L"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}
81int main()
82{
83 test01();
84 return 0;
85}