Daily bump.
[official-gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx11.cc
blob2f75d12703cba71d8063f3a1e474fa6183f1bfbb
1 // { dg-do run { target c++11 } }
2 // { dg-options "-g -O0" }
4 // Copyright (C) 2011-2024 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.
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.
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/>.
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
32 typedef std::tuple<int, int> ExTuple;
34 template<class T>
35 void
36 placeholder(const T &s)
38 std::cout << s;
41 template<class T, class S>
42 void
43 placeholder(const std::pair<T,S> &s)
45 std::cout << s.first;
48 template<class T>
49 void
50 use(const T &container)
52 for (typename T::const_iterator i = container.begin();
53 i != container.end();
54 ++i)
55 placeholder(*i);
58 struct datum
60 std::string s;
61 int i;
64 std::unique_ptr<datum> global;
66 struct custom_cat : std::error_category {
67 const char* name() const noexcept { return "miaow"; }
68 std::string message(int) const { return ""; }
71 int
72 main()
74 std::forward_list<int> efl;
75 // { dg-final { regexp-test efl "empty std::(__debug::)?forward_list" } }
77 std::forward_list<int> &refl = efl;
78 // { dg-final { regexp-test refl "empty std::(__debug::)?forward_list" } }
80 std::forward_list<int> fl;
81 fl.push_front(2);
82 fl.push_front(1);
83 // { dg-final { regexp-test fl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
85 std::forward_list<int> &rfl = fl;
86 // { dg-final { regexp-test rfl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
88 std::unordered_map<int, std::string> eum;
89 // { dg-final { regexp-test eum "std::(__debug::)?unordered_map with 0 elements" } }
90 std::unordered_map<int, std::string> &reum = eum;
91 // { dg-final { regexp-test reum "std::(__debug::)?unordered_map with 0 elements" } }
93 std::unordered_multimap<int, std::string> eumm;
94 // { dg-final { regexp-test eumm "std::(__debug::)?unordered_multimap with 0 elements" } }
95 std::unordered_multimap<int, std::string> &reumm = eumm;
96 // { dg-final { regexp-test reumm "std::(__debug::)?unordered_multimap with 0 elements" } }
98 std::unordered_set<int> eus;
99 // { dg-final { regexp-test eus "std::(__debug::)?unordered_set with 0 elements" } }
100 std::unordered_set<int> &reus = eus;
101 // { dg-final { regexp-test reus "std::(__debug::)?unordered_set with 0 elements" } }
103 std::unordered_multiset<int> eums;
104 // { dg-final { regexp-test eums "std::(__debug::)?unordered_multiset with 0 elements" } }
105 std::unordered_multiset<int> &reums = eums;
106 // { dg-final { regexp-test reums "std::(__debug::)?unordered_multiset with 0 elements" } }
108 std::unordered_map<int, std::string> uom;
109 uom[5] = "three";
110 uom[3] = "seven";
111 // { dg-final { regexp-test uom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
113 std::unordered_map<int, std::string> &ruom = uom;
114 // { dg-final { regexp-test ruom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
116 std::unordered_multimap<int, std::string> uomm;
117 uomm.insert(std::pair<int, std::string> (5, "three"));
118 uomm.insert(std::pair<int, std::string> (5, "seven"));
119 // { dg-final { regexp-test uomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
120 std::unordered_multimap<int, std::string> &ruomm = uomm;
121 // { dg-final { regexp-test ruomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
123 std::unordered_set<int> uos;
124 uos.insert(5);
125 // { dg-final { regexp-test uos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
126 std::unordered_set<int> &ruos = uos;
127 // { dg-final { regexp-test ruos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
129 std::unordered_multiset<int> uoms;
130 uoms.insert(5);
131 // { dg-final { regexp-test uoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
132 std::unordered_multiset<int> &ruoms = uoms;
133 // { dg-final { regexp-test ruoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
135 std::unique_ptr<datum> uptr (new datum);
136 uptr->s = "hi bob";
137 uptr->i = 23;
138 // { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
139 std::unique_ptr<datum> &ruptr = uptr;
140 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
142 using data = datum[];
143 std::unique_ptr<data> arrptr (new datum[2]);
144 // { dg-final { regexp-test arrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
145 std::unique_ptr<data>& rarrptr = arrptr;
146 // { dg-final { regexp-test rarrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
148 struct Deleter
150 int deleter_member = -1;
151 using pointer = __gnu_test::NullablePointer<void>;
152 void operator()(pointer) const noexcept { }
154 static_assert( !std::is_empty<Deleter>(), "Deleter is not empty" );
155 static_assert( std::is_empty<Deleter::pointer>(), "but pointer is empty" );
157 std::unique_ptr<int, Deleter> empty_ptr;
158 // { dg-final { note-test empty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
159 std::unique_ptr<int, Deleter>& rempty_ptr = empty_ptr;
160 // { dg-final { note-test rempty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
162 struct Deleter_pr103086
164 int deleter_member = -1;
165 void operator()(int*) const noexcept { }
168 std::unique_ptr<int, Deleter_pr103086> uniq_ptr;
169 // { dg-final { note-test uniq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
170 std::unique_ptr<int, Deleter_pr103086>& runiq_ptr = uniq_ptr;
171 // { dg-final { note-test runiq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
173 ExTuple tpl(6,7);
174 // { dg-final { note-test tpl {std::tuple containing = {[0] = 6, [1] = 7}} } }
175 ExTuple &rtpl = tpl;
176 // { dg-final { note-test rtpl {std::tuple containing = {[0] = 6, [1] = 7}} } }
178 std::error_code e0;
179 // { dg-final { note-test e0 {std::error_code = { }} } }
180 std::error_condition ec0;
181 // { dg-final { note-test ec0 {std::error_condition = { }} } }
182 std::error_code einval = std::make_error_code(std::errc::invalid_argument);
183 // { dg-final { note-test einval {std::error_code = {"generic": EINVAL}} } }
184 std::error_condition ecinval = std::make_error_condition(std::errc::invalid_argument);
185 // { dg-final { note-test ecinval {std::error_condition = {"generic": EINVAL}} } }
187 custom_cat cat;
188 std::error_code emiaow(42, cat);
189 // { dg-final { note-test emiaow {std::error_code = {custom_cat: 42}} } }
190 std::error_condition ecmiaow(42, cat);
191 // { dg-final { note-test ecmiaow {std::error_condition = {custom_cat: 42}} } }
193 std::error_code ecio = std::make_error_code(std::io_errc::stream);
194 // { dg-final { note-test ecio {std::error_code = {"io": stream}} } }
195 std::error_code ecfut0 = std::make_error_code(std::future_errc{});
196 // { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } }
198 std::initializer_list<int> emptyIl = {};
199 // { dg-final { note-test emptyIl {std::initializer_list of length 0} } }
200 std::initializer_list<int> il = {3, 4};
201 // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } }
203 std::atomic<int> ai{100};
204 // { dg-final { note-test ai {std::atomic<int> = { 100 }} } }
205 long l{};
206 std::atomic<long*> ap{&l};
207 // { dg-final { regexp-test ap {std::atomic.long \*. = { 0x.* }} } }
208 struct Value { int i, j; };
209 std::atomic<Value> av{{8, 9}};
210 // { dg-final { note-test av {std::atomic<Value> = { {i = 8, j = 9} }} } }
212 std::integral_constant<int, 1> one;
213 // { dg-final { note-test one {std::integral_constant<int, 1>} } }
214 std::integral_constant<bool, true> truth;
215 // { dg-final { note-test truth {std::true_type} } }
216 std::integral_constant<bool, 0> lies;
217 // { dg-final { note-test lies {std::false_type} } }
219 placeholder(""); // Mark SPOT
220 use(efl);
221 use(fl);
222 use(eum);
223 use(eumm);
224 use(eus);
225 use(eums);
226 use(uoms);
227 use(uptr->s);
228 use(arrptr[0].s);
230 std::cout << "\n";
231 return 0;
234 // { dg-final { gdb-test SPOT } }