]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
libstdc++: Add pretty printer for std::initializer_list
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx11.cc
CommitLineData
52066eae
JW
1// { dg-do run { target c++11 } }
2// { dg-options "-g -O0" }
8dfb08ab 3
7adcbafe 4// Copyright (C) 2011-2022 Free Software Foundation, Inc.
8dfb08ab
JW
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>
d6222d4e 25#include <memory>
8dfb08ab 26#include <iostream>
36100e0e 27#include <future>
71999fde 28#include <initializer_list>
066f9ea2 29#include "../util/testsuite_allocator.h" // NullablePointer
8dfb08ab 30
c77efe8f
PM
31typedef std::tuple<int, int> ExTuple;
32
8dfb08ab
JW
33template<class T>
34void
35placeholder(const T &s)
36{
37 std::cout << s;
38}
39
40template<class T, class S>
41void
42placeholder(const std::pair<T,S> &s)
43{
44 std::cout << s.first;
45}
46
47template<class T>
48void
49use(const T &container)
50{
51 for (typename T::const_iterator i = container.begin();
52 i != container.end();
53 ++i)
54 placeholder(*i);
55}
56
c4269a63
TT
57struct datum
58{
59 std::string s;
60 int i;
61};
62
63std::unique_ptr<datum> global;
64
8dfb08ab
JW
65int
66main()
67{
68 std::forward_list<int> efl;
3997383b 69// { dg-final { regexp-test efl "empty std::(__debug::)?forward_list" } }
8dfb08ab 70
c77efe8f 71 std::forward_list<int> &refl = efl;
3997383b 72// { dg-final { regexp-test refl "empty std::(__debug::)?forward_list" } }
c77efe8f 73
8dfb08ab
JW
74 std::forward_list<int> fl;
75 fl.push_front(2);
76 fl.push_front(1);
3997383b 77// { dg-final { regexp-test fl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
8dfb08ab 78
c77efe8f 79 std::forward_list<int> &rfl = fl;
3997383b 80// { dg-final { regexp-test rfl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } }
c77efe8f 81
8dfb08ab 82 std::unordered_map<int, std::string> eum;
3997383b 83// { dg-final { regexp-test eum "std::(__debug::)?unordered_map with 0 elements" } }
c77efe8f 84 std::unordered_map<int, std::string> &reum = eum;
3997383b 85// { dg-final { regexp-test reum "std::(__debug::)?unordered_map with 0 elements" } }
c77efe8f 86
8dfb08ab 87 std::unordered_multimap<int, std::string> eumm;
3997383b 88// { dg-final { regexp-test eumm "std::(__debug::)?unordered_multimap with 0 elements" } }
c77efe8f 89 std::unordered_multimap<int, std::string> &reumm = eumm;
3997383b 90// { dg-final { regexp-test reumm "std::(__debug::)?unordered_multimap with 0 elements" } }
c77efe8f 91
8dfb08ab 92 std::unordered_set<int> eus;
3997383b 93// { dg-final { regexp-test eus "std::(__debug::)?unordered_set with 0 elements" } }
c77efe8f 94 std::unordered_set<int> &reus = eus;
3997383b 95// { dg-final { regexp-test reus "std::(__debug::)?unordered_set with 0 elements" } }
c77efe8f 96
8dfb08ab 97 std::unordered_multiset<int> eums;
3997383b 98// { dg-final { regexp-test eums "std::(__debug::)?unordered_multiset with 0 elements" } }
c77efe8f 99 std::unordered_multiset<int> &reums = eums;
3997383b 100// { dg-final { regexp-test reums "std::(__debug::)?unordered_multiset with 0 elements" } }
8dfb08ab 101
d25b1e3a
TT
102 std::unordered_map<int, std::string> uom;
103 uom[5] = "three";
104 uom[3] = "seven";
3997383b 105// { dg-final { regexp-test uom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
d25b1e3a 106
c77efe8f 107 std::unordered_map<int, std::string> &ruom = uom;
3997383b 108// { dg-final { regexp-test ruom {std::(__debug::)?unordered_map with 2 elements = {\[3\] = "seven", \[5\] = "three"}} } }
c77efe8f 109
d25b1e3a
TT
110 std::unordered_multimap<int, std::string> uomm;
111 uomm.insert(std::pair<int, std::string> (5, "three"));
112 uomm.insert(std::pair<int, std::string> (5, "seven"));
3997383b 113// { dg-final { regexp-test uomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
c77efe8f 114 std::unordered_multimap<int, std::string> &ruomm = uomm;
3997383b 115// { dg-final { regexp-test ruomm {std::(__debug::)?unordered_multimap with 2 elements = {\[5\] = "seven", \[5\] = "three"}} } }
d25b1e3a
TT
116
117 std::unordered_set<int> uos;
118 uos.insert(5);
3997383b 119// { dg-final { regexp-test uos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
c77efe8f 120 std::unordered_set<int> &ruos = uos;
3997383b 121// { dg-final { regexp-test ruos {std::(__debug::)?unordered_set with 1 element = {\[0\] = 5}} } }
d25b1e3a
TT
122
123 std::unordered_multiset<int> uoms;
124 uoms.insert(5);
3997383b 125// { dg-final { regexp-test uoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
c77efe8f 126 std::unordered_multiset<int> &ruoms = uoms;
3997383b 127// { dg-final { regexp-test ruoms {std::(__debug::)?unordered_multiset with 1 element = {\[0\] = 5}} } }
d25b1e3a 128
c4269a63
TT
129 std::unique_ptr<datum> uptr (new datum);
130 uptr->s = "hi bob";
131 uptr->i = 23;
d2dfcf82 132// { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
c77efe8f 133 std::unique_ptr<datum> &ruptr = uptr;
d2dfcf82 134// { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
c4269a63 135
8273aa77
JW
136 using data = datum[];
137 std::unique_ptr<data> arrptr (new datum[2]);
138// { dg-final { regexp-test arrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
139 std::unique_ptr<data>& rarrptr = arrptr;
140// { dg-final { regexp-test rarrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
141
066f9ea2
JW
142 struct Deleter
143 {
144 int deleter_member = -1;
145 using pointer = __gnu_test::NullablePointer<void>;
146 void operator()(pointer) const noexcept { }
147 };
148 static_assert( !std::is_empty<Deleter>(), "Deleter is not empty" );
149 static_assert( std::is_empty<Deleter::pointer>(), "but pointer is empty" );
150
e25f488d
JW
151 std::unique_ptr<int, Deleter> empty_ptr;
152// { dg-final { note-test empty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
153 std::unique_ptr<int, Deleter>& rempty_ptr = empty_ptr;
154// { dg-final { note-test rempty_ptr {std::unique_ptr<int> = {get() = {<No data fields>}}} } }
155
c59ec55c
JW
156 struct Deleter_pr103086
157 {
158 int deleter_member = -1;
159 void operator()(int*) const noexcept { }
160 };
161
162 std::unique_ptr<int, Deleter_pr103086> uniq_ptr;
163// { dg-final { note-test uniq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
164 std::unique_ptr<int, Deleter_pr103086>& runiq_ptr = uniq_ptr;
165// { dg-final { note-test runiq_ptr {std::unique_ptr<int> = {get() = 0x0}} } }
166
c77efe8f 167 ExTuple tpl(6,7);
d2dfcf82 168// { dg-final { note-test tpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
c77efe8f 169 ExTuple &rtpl = tpl;
d2dfcf82 170// { dg-final { note-test rtpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
2db38d9f
JW
171
172 std::error_code e0;
173 // { dg-final { note-test e0 {std::error_code = { }} } }
174 std::error_condition ec0;
175 // { dg-final { note-test ec0 {std::error_condition = { }} } }
176 std::error_code einval = std::make_error_code(std::errc::invalid_argument);
177 // { dg-final { note-test einval {std::error_code = {"generic": EINVAL}} } }
178 std::error_condition ecinval = std::make_error_condition(std::errc::invalid_argument);
179 // { dg-final { note-test ecinval {std::error_condition = {"generic": EINVAL}} } }
180
181 struct custom_cat : std::error_category {
182 const char* name() const noexcept { return "miaow"; }
183 std::string message(int) const { return ""; }
184 } cat;
185 std::error_code emiaow(42, cat);
36100e0e 186 // { dg-final { note-test emiaow {std::error_code = {custom_cat: 42}} } }
2db38d9f 187 std::error_condition ecmiaow(42, cat);
36100e0e
JW
188 // { dg-final { note-test ecmiaow {std::error_condition = {custom_cat: 42}} } }
189
190 std::error_code ecio = std::make_error_code(std::io_errc::stream);
191 // { dg-final { note-test ecio {std::error_code = {"io": stream}} } }
192 std::error_code ecfut0 = std::make_error_code(std::future_errc{});
193 // { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } }
2db38d9f 194
71999fde
PF
195 std::initializer_list<int> emptyIl = {};
196 // { dg-final { note-test emptyIl {std::initializer_list of length 0} } }
197 std::initializer_list<int> il = {3, 4};
198 // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } }
199
8dfb08ab
JW
200 placeholder(""); // Mark SPOT
201 use(efl);
202 use(fl);
203 use(eum);
204 use(eumm);
205 use(eus);
206 use(eums);
c4269a63
TT
207 use(uoms);
208 use(uptr->s);
8273aa77 209 use(arrptr[0].s);
8dfb08ab 210
af583c44 211 std::cout << "\n";
8dfb08ab
JW
212 return 0;
213}
214
215// { dg-final { gdb-test SPOT } }