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// <memory>
10
11// allocator:
12// template <class... Args> void construct(pointer p, Args&&... args);
13
14// Removed in C++20.
15
16// UNSUPPORTED: c++03, c++11, c++14, c++17
17
18#include <memory>
19#include <cassert>
20
21int A_constructed = 0;
22
23struct A {
24 int data;
25 A() { ++A_constructed; }
26
27 A(const A&) { ++A_constructed; }
28
29 explicit A(int) { ++A_constructed; }
30 A(int, int*) { ++A_constructed; }
31
32 ~A() { --A_constructed; }
33};
34
35int move_only_constructed = 0;
36
37class move_only {
38 move_only(const move_only&) = delete;
39 move_only& operator=(const move_only&) = delete;
40
41public:
42 move_only(move_only&&) { ++move_only_constructed; }
43 move_only& operator=(move_only&&) { return *this; }
44
45 move_only() { ++move_only_constructed; }
46 ~move_only() { --move_only_constructed; }
47
48public:
49 int data; // unused other than to make sizeof(move_only) == sizeof(int).
50 // but public to suppress "-Wunused-private-field"
51};
52
53int main(int, char**) {
54 {
55 std::allocator<A> a;
56 A* ap = a.allocate(n: 3);
57 a.construct(p: ap); // expected-error {{no member}}
58 a.destroy(p: ap); // expected-error {{no member}}
59 a.construct(p: ap, args: A()); // expected-error {{no member}}
60 a.destroy(p: ap); // expected-error {{no member}}
61 a.construct(p: ap, args: 5); // expected-error {{no member}}
62 a.destroy(p: ap); // expected-error {{no member}}
63 a.construct(p: ap, args: 5, args: (int*)0); // expected-error {{no member}}
64 a.destroy(p: ap); // expected-error {{no member}}
65 a.deallocate(p: ap, n: 3);
66 }
67 {
68 std::allocator<move_only> a;
69 move_only* ap = a.allocate(n: 3);
70 a.construct(p: ap); // expected-error {{no member}}
71 a.destroy(p: ap); // expected-error {{no member}}
72 a.construct(p: ap, args: move_only()); // expected-error {{no member}}
73 a.destroy(p: ap); // expected-error {{no member}}
74 a.deallocate(p: ap, n: 3);
75 }
76 return 0;
77}
78

source code of libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/construct.cxx20.verify.cpp