1 // { dg-options "-g -O0" }
2 // { dg-do run { target c++17 } }
3 
4 // Copyright (C) 2014-2021 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 // Type printers only recognize the old std::string for now.
22 #define _GLIBCXX_USE_CXX11_ABI 0
23 
24 #include <filesystem>
25 #include <any>
26 #include <optional>
27 #include <variant>
28 #include <string_view>
29 #include <string>
30 #include <map>
31 #include <unordered_set>
32 #include <memory>
33 #include <iostream>
34 
35 using std::any;
36 using std::optional;
37 using std::variant;
38 using std::string_view;
39 using std::map;
40 using std::unordered_set;
41 using std::shared_ptr;
42 using std::weak_ptr;
43 
44 struct X {
XX45   X(int) { }
XX46   X(const X&) { } // not trivially-copyable
47 };
48 
49 int
main()50 main()
51 {
52   string_view str = "string";
53 // { dg-final { note-test str "\"string\"" } }
54 
55   optional<int> o;
56 // { dg-final { note-test o {std::optional<int> [no contained value]} } }
57   optional<bool> ob{false};
58 // { dg-final { note-test ob {std::optional<bool> = {[contained value] = false}} } }
59   optional<int> oi{5};
60 // { dg-final { note-test oi {std::optional<int> = {[contained value] = 5}} } }
61   optional<void*> op{nullptr};
62 // { dg-final { note-test op {std::optional<void *> = {[contained value] = 0x0}} } }
63   optional<std::map<int, double>> om;
64   om = std::map<int, double>{ {1, 2.}, {3, 4.}, {5, 6.} };
65 // { dg-final { regexp-test om {std::optional<std::(__debug::)?map<int, double>> containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } }
66   optional<std::string> os{ "stringy" };
67 // { dg-final { note-test os {std::optional<std::string> = {[contained value] = "stringy"}} } }
68 
69   any a;
70 // { dg-final { note-test a {std::any [no contained value]} } }
71   any ab(false);
72 // { dg-final { note-test ab {std::any containing bool = {[contained value] = false}} } }
73   any ai(6);
74 // { dg-final { note-test ai {std::any containing int = {[contained value] = 6}} } }
75   any ap = (void*)nullptr;
76 // { dg-final { note-test ap {std::any containing void * = {[contained value] = 0x0}} } }
77   any as = *os;
78 // { dg-final { note-test as {std::any containing std::string = {[contained value] = "stringy"}} } }
79   any as2("stringiest");
80 // { dg-final { regexp-test as2 {std::any containing const char \* = {\[contained value\] = 0x[[:xdigit:]]+ "stringiest"}} } }
81   any am = *om;
82 // { dg-final { regexp-test am {std::any containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } }
83   struct local_type { int i = 99; };
84   any al = local_type{};
85 // { dg-final { note-test al {std::any containing local_type = {[contained value] = {i = 99}}} } }
86 
87   struct S { operator int() { throw 42; }};
88   variant<float, int, string_view> v0;
89 // { dg-final { note-test v0 {std::variant<float, int, std::string_view> [index 0] = {0}} } }
90   variant<float, int, string_view> v1{ 0.5f };
91 // { dg-final { note-test v1 {std::variant<float, int, std::string_view> [index 0] = {0.5}} } }
92   variant<float, X, string_view> v2;
93   try {
94     v2.emplace<1>(S());
95   } catch (int) { }
96 // { dg-final { note-test v2 {std::variant<float, X, std::string_view> [no contained value]} } }
97   variant<float, int, string_view> v3{ 3 };
98 // { dg-final { note-test v3 {std::variant<float, int, std::string_view> [index 1] = {3}} } }
99   variant<float, int, string_view> v4{ str };
100 // { dg-final { note-test v4 {std::variant<float, int, std::string_view> [index 2] = {"string"}} } }
101 
102   map<int, string_view> m{ {1, "one"} };
103   map<int, string_view>::node_type n0;
104 // { dg-final { note-test n0 {empty node handle for map}}}
105   map<int, string_view>::node_type n1 = m.extract(1);
106 // { dg-final { note-test n1 {node handle for map with element = {{first = 1, second = "two"}}}}}
107 
108   unordered_set<int> s{ 3, 4 };
109   unordered_set<int>::node_type n2;
110 // { dg-final { note-test n2 {empty node handle for unordered set}}}
111   unordered_set<int>::node_type n3 = s.extract(3);
112 // { dg-final { note-test n1 {node handle for unordered set with element = {3}}}}
113 
114   shared_ptr<int[]> p(new int[1]);
115   weak_ptr wp = p;
116   weak_ptr wp2 = p;
117 // { dg-final { regexp-test p {std::shared_ptr.int \[\]. \(use count 1, weak count 2\) = {get\(\) = 0x.*}} } }
118 // { dg-final { regexp-test wp {std::weak_ptr.int \[\]. \(use count 1, weak count 2\) = {get\(\) = 0x.*}} } }
119 
120   shared_ptr<int[2]> q(new int[2]);
121   shared_ptr q2 = q;
122   weak_ptr wq = q;
123 // { dg-final { regexp-test q {std::shared_ptr.int \[2\]. \(use count 2, weak count 1\) = {get\(\) = 0x.*}} } }
124 // { dg-final { regexp-test wq {std::weak_ptr.int \[2\]. \(use count 2, weak count 1\) = {get\(\) = 0x.*}} } }
125 
126   std::filesystem::path path0;
127 // { dg-final { note-test path0 {filesystem::path ""} } }
128   std::filesystem::path path1("filename");
129 // { dg-final { note-test path1 {filesystem::path "filename"} } }
130   std::filesystem::path path2("/dir/.");
131 // { dg-final { note-test path2 {filesystem::path "/dir/." = {[root-directory] = "/", [1] = "dir", [2] = "."}} } }
132 
133   std::cout << "\n";
134   return 0;			// Mark SPOT
135 }
136 
137 // { dg-final { gdb-test SPOT } }
138