]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx11.cc
1 // { dg-do run { target c++11 } }
2 // { dg-options "-g -O0" }
3
4 // Copyright (C) 2011-2023 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 #include <forward_list>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <string>
25 #include <memory>
26 #include <iostream>
27 #include <future>
28 #include <initializer_list>
29 #include <atomic>
30 #include "../util/testsuite_allocator.h" // NullablePointer
31
32 typedef std::tuple<int, int> ExTuple;
33
34 template<class T>
35 void
36 placeholder(const T &s)
37 {
38 std::cout << s;
39 }
40
41 template<class T, class S>
42 void
43 placeholder(const std::pair<T,S> &s)
44 {
45 std::cout << s.first;
46 }
47
48 template<class T>
49 void
50 use(const T &container)
51 {
52 for (typename T::const_iterator i = container.begin();
53 i != container.end();
54 ++i)
55 placeholder(*i);
56 }
57
58 struct datum
59 {
60 std::string s;
61 int i;
62 };
63
64 std::unique_ptr<datum> global;
65
66 int
67 main()
68 {
69 std::forward_list<int> efl;
70 // { dg-final { regexp-test efl "empty std::(__debug::)?forward_list" } }
71
72 std::forward_list<int> &refl = efl;
73 // { dg-final { regexp-test refl "empty std::(__debug::)?forward_list" } }
74
75 std::forward_list<int> fl;
76 fl.push_front(2);
77 fl.push_front(1);
78 // { dg-final { regexp-test fl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
79
80 std::forward_list<int> &rfl = fl;
81 // { dg-final { regexp-test rfl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
82
83 std::unordered_map<int, std::string> eum;
84 // { dg-final { regexp-test eum "std::(__debug::)?unordered_map with 0 elements" } }
85 std::unordered_map<int, std::string> &reum = eum;
86 // { dg-final { regexp-test reum "std::(__debug::)?unordered_map with 0 elements" } }
87
88 std::unordered_multimap<int, std::string> eumm;
89 // { dg-final { regexp-test eumm "std::(__debug::)?unordered_multimap with 0 elements" } }
90 std::unordered_multimap<int, std::string> &reumm = eumm;
91 // { dg-final { regexp-test reumm "std::(__debug::)?unordered_multimap with 0 elements" } }
92
93 std::unordered_set<int> eus;
94 // { dg-final { regexp-test eus "std::(__debug::)?unordered_set with 0 elements" } }
95 std::unordered_set<int> &reus = eus;
96 // { dg-final { regexp-test reus "std::(__debug::)?unordered_set with 0 elements" } }
97
98 std::unordered_multiset<int> eums;
99 // { dg-final { regexp-test eums "std::(__debug::)?unordered_multiset with 0 elements" } }
100 std::unordered_multiset<int> &reums = eums;
101 // { dg-final { regexp-test reums "std::(__debug::)?unordered_multiset with 0 elements" } }
102
103 std::unordered_map<int, std::string> uom;
104 uom[5] = "three";
105 uom[3] = "seven";
106 // { dg-final { regexp-test uom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
107
108 std::unordered_map<int, std::string> &ruom = uom;
109 // { dg-final { regexp-test ruom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
110
111 std::unordered_multimap<int, std::string> uomm;
112 uomm.insert(std::pair<int, std::string> (5, "three"));
113 uomm.insert(std::pair<int, std::string> (5, "seven"));
114 // { dg-final { regexp-test uomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
115 std::unordered_multimap<int, std::string> &ruomm = uomm;
116 // { dg-final { regexp-test ruomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
117
118 std::unordered_set<int> uos;
119 uos.insert(5);
120 // { dg-final { regexp-test uos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
121 std::unordered_set<int> &ruos = uos;
122 // { dg-final { regexp-test ruos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
123
124 std::unordered_multiset<int> uoms;
125 uoms.insert(5);
126 // { dg-final { regexp-test uoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
127 std::unordered_multiset<int> &ruoms = uoms;
128 // { dg-final { regexp-test ruoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
129
130 std::unique_ptr<datum> uptr (new datum);
131 uptr->s = "hi bob";
132 uptr->i = 23;
133 // { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
134 std::unique_ptr<datum> &ruptr = uptr;
135 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
136
137 using data = datum[];
138 std::unique_ptr<data> arrptr (new datum[2]);
139 // { dg-final { regexp-test arrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
140 std::unique_ptr<data>& rarrptr = arrptr;
141 // { dg-final { regexp-test rarrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
142
143 struct Deleter
144 {
145 int deleter_member = -1;
146 using pointer = __gnu_test::NullablePointer<void>;
147 void operator()(pointer) const noexcept { }
148 };
149 static_assert( !std::is_empty<Deleter>(), "Deleter is not empty" );
150 static_assert( std::is_empty<Deleter::pointer>(), "but pointer is empty" );
151
152 std::unique_ptr<int, Deleter> empty_ptr;
153 // { dg-final { note-test empty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
154 std::unique_ptr<int, Deleter>& rempty_ptr = empty_ptr;
155 // { dg-final { note-test rempty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
156
157 struct Deleter_pr103086
158 {
159 int deleter_member = -1;
160 void operator()(int*) const noexcept { }
161 };
162
163 std::unique_ptr<int, Deleter_pr103086> uniq_ptr;
164 // { dg-final { note-test uniq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
165 std::unique_ptr<int, Deleter_pr103086>& runiq_ptr = uniq_ptr;
166 // { dg-final { note-test runiq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
167
168 ExTuple tpl(6,7);
169 // { dg-final { note-test tpl {std::tuple containing = {[0] = 6, [1] = 7}} } }
170 ExTuple &rtpl = tpl;
171 // { dg-final { note-test rtpl {std::tuple containing = {[0] = 6, [1] = 7}} } }
172
173 std::error_code e0;
174 // { dg-final { note-test e0 {std::error_code = { }} } }
175 std::error_condition ec0;
176 // { dg-final { note-test ec0 {std::error_condition = { }} } }
177 std::error_code einval = std::make_error_code(std::errc::invalid_argument);
178 // { dg-final { note-test einval {std::error_code = {"generic": EINVAL}} } }
179 std::error_condition ecinval = std::make_error_condition(std::errc::invalid_argument);
180 // { dg-final { note-test ecinval {std::error_condition = {"generic": EINVAL}} } }
181
182 struct custom_cat : std::error_category {
183 const char* name() const noexcept { return "miaow"; }
184 std::string message(int) const { return ""; }
185 } cat;
186 std::error_code emiaow(42, cat);
187 // { dg-final { note-test emiaow {std::error_code = {custom_cat: 42}} } }
188 std::error_condition ecmiaow(42, cat);
189 // { dg-final { note-test ecmiaow {std::error_condition = {custom_cat: 42}} } }
190
191 std::error_code ecio = std::make_error_code(std::io_errc::stream);
192 // { dg-final { note-test ecio {std::error_code = {"io": stream}} } }
193 std::error_code ecfut0 = std::make_error_code(std::future_errc{});
194 // { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } }
195
196 std::initializer_list<int> emptyIl = {};
197 // { dg-final { note-test emptyIl {std::initializer_list of length 0} } }
198 std::initializer_list<int> il = {3, 4};
199 // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } }
200
201 std::atomic<int> ai{100};
202 // { dg-final { note-test ai {std::atomic<int> = { 100 }} } }
203 long l{};
204 std::atomic<long*> ap{&l};
205 // { dg-final { regexp-test ap {std::atomic.long \*. = { 0x.* }} } }
206 struct Value { int i, j; };
207 std::atomic<Value> av{{8, 9}};
208 // { dg-final { note-test av {std::atomic<Value> = { {i = 8, j = 9} }} } }
209
210 placeholder(""); // Mark SPOT
211 use(efl);
212 use(fl);
213 use(eum);
214 use(eumm);
215 use(eus);
216 use(eums);
217 use(uoms);
218 use(uptr->s);
219 use(arrptr[0].s);
220
221 std::cout << "\n";
222 return 0;
223 }
224
225 // { dg-final { gdb-test SPOT } }