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