]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc
re PR testsuite/37149 (27_io/basic_ostream/inserters_other/char/error_code.cc)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / malloc_allocator / deallocate_local.cc
1 //
2 // Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 2, or (at your option)
8 // any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING. If not, write to the Free
17 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 // USA.
19
20 // 20.4.1.1 allocator members
21
22 #include <string>
23 #include <cstdio>
24 #include <ext/malloc_allocator.h>
25 #include <testsuite_hooks.h>
26
27 static size_t alloc_cnt;
28
29 void* operator new(size_t size) throw(std::bad_alloc)
30 {
31 printf("operator new is called \n");
32 void* p = malloc(size);
33 if (p == NULL)
34 throw std::bad_alloc();
35 alloc_cnt++;
36 return p;
37 }
38
39 void operator delete(void* p) throw()
40 {
41 printf("operator delete is called \n");
42 if (p == NULL)
43 return;
44 alloc_cnt--;
45 if (alloc_cnt == 0)
46 printf("All memory released \n");
47 else
48 printf("%lu allocations to be released \n",
49 static_cast<unsigned long>(alloc_cnt));
50 free(p);
51 }
52
53 typedef char char_t;
54 typedef std::char_traits<char_t> traits_t;
55 typedef __gnu_cxx::malloc_allocator<char_t> allocator_t;
56 typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
57
58 int main()
59 {
60 bool test __attribute__((unused)) = true;
61 {
62 string_t s;
63 s += "bayou bend";
64 }
65 VERIFY( alloc_cnt == 0 );
66 return 0;
67 }