* config/abi/pre/gnu.ver (_ZNSt11regex_errorC*): Export regex_error
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / destroy.cc
blob56d598a21d1baed5c2b18d6f5ee0d82119e5a2e6
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 #include <memory>
21 #include <new>
22 #include <testsuite_hooks.h>
24 struct X
26 static int counter;
27 ~X() { ++counter; }
30 int X::counter = 0;
32 template<typename T>
33 struct allocator_with_destroy
35 typedef T value_type;
37 allocator_with_destroy() : called() { }
39 void destroy(T* p) { called = true; }
41 int called;
44 template<typename T>
45 struct allocator_without_destroy
47 typedef T value_type;
49 allocator_without_destroy() : called() { }
51 int called;
54 void test01()
56 bool test __attribute__((unused)) = true;
58 typedef std::allocator_traits<allocator_with_destroy<X>> traits_type;
59 traits_type::allocator_type a;
60 X* p = 0;
61 traits_type::destroy(a, p);
62 VERIFY( a.called );
63 VERIFY( X::counter == 0 );
66 void test02()
68 bool test __attribute__((unused)) = true;
70 typedef std::allocator_traits<allocator_without_destroy<X>> traits_type;
71 traits_type::allocator_type a;
72 char buf[sizeof(X)];
73 X* p = ::new (static_cast<void*>(buf)) X();
74 traits_type::destroy(a, p);
75 VERIFY( !a.called );
76 VERIFY( X::counter == 1 );
79 int main()
81 test01();
82 test02();