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