]>
Commit | Line | Data |
---|---|---|
e7a0af84 JW |
1 | // { dg-options "-std=gnu++20" } |
2 | // { dg-do run { target c++2a } } | |
dec1eb4c | 3 | // { dg-xfail-run-if "AIX operator new" { powerpc-ibm-aix* } } |
e7a0af84 | 4 | |
99dee823 | 5 | // Copyright (C) 2020-2021 Free Software Foundation, Inc. |
e7a0af84 JW |
6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | ||
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | // C++20 20.11.1.5 unique_ptr creation [unique.ptr.create] | |
23 | ||
24 | #include <memory> | |
25 | #include <cstdlib> | |
26 | #include <cstring> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | void* operator new(std::size_t n) | |
30 | { | |
31 | void* p = std::malloc(n); | |
32 | std::memset(p, 0xaa, n); | |
33 | return p; | |
34 | } | |
35 | ||
36 | void operator delete(void* p) { std::free(p); } | |
37 | void operator delete(void* p, std::size_t) { std::free(p); } | |
38 | ||
39 | void | |
40 | test01() | |
41 | { | |
42 | std::unique_ptr<int> a = std::make_unique_for_overwrite<int>(); | |
43 | VERIFY( a != nullptr ); | |
44 | unsigned char buf[sizeof(int)]; | |
45 | std::memcpy(buf, a.get(), sizeof(buf)); | |
46 | for (unsigned char c : buf) | |
47 | VERIFY( c == 0xaa ); | |
48 | } | |
49 | ||
50 | void | |
51 | test02() | |
52 | { | |
53 | std::unique_ptr<int[]> a = std::make_unique_for_overwrite<int[]>(3); | |
54 | VERIFY( a != nullptr ); | |
55 | unsigned char buf[3 * sizeof(int)]; | |
56 | std::memcpy(buf, a.get(), sizeof(buf)); | |
57 | for (unsigned char c : buf) | |
58 | VERIFY( c == 0xaa ); | |
59 | } | |
60 | ||
61 | int | |
62 | main() | |
63 | { | |
64 | test01(); | |
65 | test02(); | |
66 | } |