1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 // <memory>
12 
13 // template <class OuterAlloc, class... InnerAllocs>
14 //   class scoped_allocator_adaptor
15 
16 // template <class T> void destroy(T* p);
17 
18 #include <scoped_allocator>
19 #include <cassert>
20 #include <string>
21 
22 #include "test_macros.h"
23 #include "allocators.h"
24 
25 struct B
26 {
27     static bool constructed;
28 
BB29     B() {constructed = true;}
~BB30     ~B() {constructed = false;}
31 };
32 
33 bool B::constructed = false;
34 
main(int,char **)35 int main(int, char**)
36 {
37     {
38         typedef std::scoped_allocator_adaptor<A1<B>> A;
39         A a;
40         char buf[100];
41         typedef B S;
42         S* s = (S*)buf;
43         assert(!S::constructed);
44         a.construct(s);
45         assert(S::constructed);
46         a.destroy(s);
47         assert(!S::constructed);
48     }
49 
50     {
51         typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A;
52         A a;
53         char buf[100];
54         typedef B S;
55         S* s = (S*)buf;
56         assert(!S::constructed);
57         assert(!A3<S>::constructed);
58         assert(!A3<S>::destroy_called);
59         a.construct(s);
60         assert(S::constructed);
61         assert(A3<S>::constructed);
62         assert(!A3<S>::destroy_called);
63         a.destroy(s);
64         assert(!S::constructed);
65         assert(A3<S>::constructed);
66         assert(A3<S>::destroy_called);
67     }
68 
69 
70   return 0;
71 }
72