]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/unique_ptr/creation/for_overwrite.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / creation / for_overwrite.cc
CommitLineData
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
7adcbafe 5// Copyright (C) 2020-2022 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
29void* operator new(std::size_t n)
30{
31 void* p = std::malloc(n);
32 std::memset(p, 0xaa, n);
33 return p;
34}
35
36void operator delete(void* p) { std::free(p); }
37void operator delete(void* p, std::size_t) { std::free(p); }
38
39void
40test01()
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
50void
51test02()
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
61int
62main()
63{
64 test01();
65 test02();
66}