PR libstdc++/80276 fix pretty printers for array smart pointers
[official-gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx11.cc
blob0ecc3771351915bc6d01d5d9bb89b2db69a6e7a3
1 // { dg-do run { target c++11 } }
2 // { dg-options "-g -O0" }
3 // { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
5 // Copyright (C) 2011-2018 Free Software Foundation, Inc.
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.
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.
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/>.
22 #include <forward_list>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <string>
26 #include <memory>
27 #include <iostream>
29 typedef std::tuple<int, int> ExTuple;
31 template<class T>
32 void
33 placeholder(const T &s)
35 std::cout << s;
38 template<class T, class S>
39 void
40 placeholder(const std::pair<T,S> &s)
42 std::cout << s.first;
45 template<class T>
46 void
47 use(const T &container)
49 for (typename T::const_iterator i = container.begin();
50 i != container.end();
51 ++i)
52 placeholder(*i);
55 struct datum
57 std::string s;
58 int i;
61 std::unique_ptr<datum> global;
63 int
64 main()
66 std::forward_list<int> efl;
67 // { dg-final { note-test efl "empty std::forward_list" } }
69 std::forward_list<int> &refl = efl;
70 // { dg-final { note-test refl "empty std::forward_list" } }
72 std::forward_list<int> fl;
73 fl.push_front(2);
74 fl.push_front(1);
75 // { dg-final { note-test fl {std::forward_list = {[0] = 1, [1] = 2}} } }
77 std::forward_list<int> &rfl = fl;
78 // { dg-final { note-test rfl {std::forward_list = {[0] = 1, [1] = 2}} } }
80 std::unordered_map<int, std::string> eum;
81 // { dg-final { note-test eum "std::unordered_map with 0 elements" } }
82 std::unordered_map<int, std::string> &reum = eum;
83 // { dg-final { note-test reum "std::unordered_map with 0 elements" } }
85 std::unordered_multimap<int, std::string> eumm;
86 // { dg-final { note-test eumm "std::unordered_multimap with 0 elements" } }
87 std::unordered_multimap<int, std::string> &reumm = eumm;
88 // { dg-final { note-test reumm "std::unordered_multimap with 0 elements" } }
90 std::unordered_set<int> eus;
91 // { dg-final { note-test eus "std::unordered_set with 0 elements" } }
92 std::unordered_set<int> &reus = eus;
93 // { dg-final { note-test reus "std::unordered_set with 0 elements" } }
95 std::unordered_multiset<int> eums;
96 // { dg-final { note-test eums "std::unordered_multiset with 0 elements" } }
97 std::unordered_multiset<int> &reums = eums;
98 // { dg-final { note-test reums "std::unordered_multiset with 0 elements" } }
100 std::unordered_map<int, std::string> uom;
101 uom[5] = "three";
102 uom[3] = "seven";
103 // { dg-final { note-test uom {std::unordered_map with 2 elements = {[3] = "seven", [5] = "three"}} } }
105 std::unordered_map<int, std::string> &ruom = uom;
106 // { dg-final { note-test ruom {std::unordered_map with 2 elements = {[3] = "seven", [5] = "three"}} } }
108 std::unordered_multimap<int, std::string> uomm;
109 uomm.insert(std::pair<int, std::string> (5, "three"));
110 uomm.insert(std::pair<int, std::string> (5, "seven"));
111 // { dg-final { note-test uomm {std::unordered_multimap with 2 elements = {[5] = "seven", [5] = "three"}} } }
112 std::unordered_multimap<int, std::string> &ruomm = uomm;
113 // { dg-final { note-test ruomm {std::unordered_multimap with 2 elements = {[5] = "seven", [5] = "three"}} } }
115 std::unordered_set<int> uos;
116 uos.insert(5);
117 // { dg-final { note-test uos {std::unordered_set with 1 element = {[0] = 5}} } }
118 std::unordered_set<int> &ruos = uos;
119 // { dg-final { note-test ruos {std::unordered_set with 1 element = {[0] = 5}} } }
121 std::unordered_multiset<int> uoms;
122 uoms.insert(5);
123 // { dg-final { note-test uoms {std::unordered_multiset with 1 element = {[0] = 5}} } }
124 std::unordered_multiset<int> &ruoms = uoms;
125 // { dg-final { note-test ruoms {std::unordered_multiset with 1 element = {[0] = 5}} } }
127 std::unique_ptr<datum> uptr (new datum);
128 uptr->s = "hi bob";
129 uptr->i = 23;
130 // { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
131 std::unique_ptr<datum> &ruptr = uptr;
132 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
134 using data = datum[];
135 std::unique_ptr<data> arrptr (new datum[2]);
136 // { dg-final { regexp-test arrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
137 std::unique_ptr<data>& rarrptr = arrptr;
138 // { dg-final { regexp-test rarrptr {std::unique_ptr.datum \[\]. = {get\(\) = 0x.*}} } }
140 ExTuple tpl(6,7);
141 // { dg-final { note-test tpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
142 ExTuple &rtpl = tpl;
143 // { dg-final { note-test rtpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
144 placeholder(""); // Mark SPOT
145 use(efl);
146 use(fl);
147 use(eum);
148 use(eumm);
149 use(eus);
150 use(eums);
151 use(uoms);
152 use(uptr->s);
153 use(arrptr[0].s);
155 std::cout << "\n";
156 return 0;
159 // { dg-final { gdb-test SPOT } }