| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-options "-g -O0" } |
| 3 | |
| 4 | // Copyright (C) 2011-2025 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 | struct custom_cat : std::error_category { |
| 67 | const char* name() const noexcept { return "miaow"; } |
| 68 | std::string message(int) const { return ""; } |
| 69 | }; |
| 70 | |
| 71 | int |
| 72 | main() |
| 73 | { |
| 74 | std::forward_list<int> efl; |
| 75 | // { dg-final { regexp-test efl "empty std::(__debug::)?forward_list" } } |
| 76 | |
| 77 | std::forward_list<int> &refl = efl; |
| 78 | // { dg-final { regexp-test refl "empty std::(__debug::)?forward_list" } } |
| 79 | |
| 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}} } } |
| 84 | |
| 85 | std::forward_list<int> &rfl = fl; |
| 86 | // { dg-final { regexp-test rfl {std::(__debug::)?forward_list = {\[0\] = 1, \[1\] = 2}} } } |
| 87 | |
| 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" } } |
| 92 | |
| 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" } } |
| 97 | |
| 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" } } |
| 102 | |
| 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" } } |
| 107 | |
| 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"}} } } |
| 112 | |
| 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"}} } } |
| 115 | |
| 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"}} } } |
| 122 | |
| 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}} } } |
| 128 | |
| 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}} } } |
| 134 | |
| 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.*}} } } |
| 141 | |
| 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.*}} } } |
| 147 | |
| 148 | struct Deleter |
| 149 | { |
| 150 | int deleter_member = -1; |
| 151 | using pointer = __gnu_test::NullablePointer<void>; |
| 152 | void operator()(pointer) const noexcept { } |
| 153 | }; |
| 154 | static_assert( !std::is_empty<Deleter>(), "Deleter is not empty" ); |
| 155 | static_assert( std::is_empty<Deleter::pointer>(), "but pointer is empty" ); |
| 156 | |
| 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>}}} } } |
| 161 | |
| 162 | struct Deleter_pr103086 |
| 163 | { |
| 164 | int deleter_member = -1; |
| 165 | void operator()(int*) const noexcept { } |
| 166 | }; |
| 167 | |
| 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}} } } |
| 172 | |
| 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}} } } |
| 177 | |
| 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}} } } |
| 186 | |
| 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}} } } |
| 192 | |
| 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}} } } |
| 197 | |
| 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}} } } |
| 202 | |
| 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} }} } } |
| 211 | |
| 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} } } |
| 218 | |
| 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); |
| 229 | |
| 230 | std::cout << "\n"; |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | // { dg-final { gdb-test SPOT } } |