* doc/invoke.texi: Document -std=c++17 and -std=gnu++17 and document
[official-gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx17.cc
blob004738052e463af72f6d324ddbccc2e455876487
1 // { dg-options "-g -O0 -std=gnu++17" }
2 // { dg-do run { target c++17 } }
3 // { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
5 // Copyright (C) 2014-2017 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 // Type printers only recognize the old std::string for now.
23 #define _GLIBCXX_USE_CXX11_ABI 0
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 <iostream>
34 using std::any;
35 using std::optional;
36 using std::variant;
37 using std::string_view;
38 using std::map;
39 using std::unordered_set;
41 int
42 main()
44 string_view str = "string";
45 // { dg-final { note-test str "\"string\"" } }
47 optional<int> o;
48 // { dg-final { note-test o {std::optional<int> [no contained value]} } }
49 optional<bool> ob{false};
50 // { dg-final { note-test ob {std::optional<bool> = {[contained value] = false}} } }
51 optional<int> oi{5};
52 // { dg-final { note-test oi {std::optional<int> = {[contained value] = 5}} } }
53 optional<void*> op{nullptr};
54 // { dg-final { note-test op {std::optional<void *> = {[contained value] = 0x0}} } }
55 optional<std::map<int, double>> om;
56 om = std::map<int, double>{ {1, 2.}, {3, 4.}, {5, 6.} };
57 // { dg-final { note-test om {std::optional<std::map<int, double>> containing std::map with 3 elements = {[1] = 2, [3] = 4, [5] = 6}} } }
58 optional<std::string> os{ "stringy" };
59 // { dg-final { note-test os {std::optional<std::string> = {[contained value] = "stringy"}} } }
61 any a;
62 // { dg-final { note-test a {std::any [no contained value]} } }
63 any ab(false);
64 // { dg-final { note-test ab {std::any containing bool = {[contained value] = false}} } }
65 any ai(6);
66 // { dg-final { note-test ai {std::any containing int = {[contained value] = 6}} } }
67 any ap = (void*)nullptr;
68 // { dg-final { note-test ap {std::any containing void * = {[contained value] = 0x0}} } }
69 any as = *os;
70 // { dg-final { note-test as {std::any containing std::string = {[contained value] = "stringy"}} } }
71 any as2("stringiest");
72 // { dg-final { regexp-test as2 {std::any containing const char \* = {\[contained value\] = 0x[[:xdigit:]]+ "stringiest"}} } }
73 any am = *om;
74 // { dg-final { note-test am {std::any containing std::map with 3 elements = {[1] = 2, [3] = 4, [5] = 6}} } }
76 struct S { operator int() { throw 42; }};
77 variant<float, int, string_view> v0;
78 // { dg-final { note-test v0 {std::variant<float, int, std::string_view> [index 0] = {0}} } }
79 variant<float, int, string_view> v1{ 0.5f };
80 // { dg-final { note-test v1 {std::variant<float, int, std::string_view> [index 0] = {0.5}} } }
81 variant<float, int, string_view> v2;
82 try {
83 v2.emplace<1>(S());
84 } catch (int) { }
85 // { dg-final { note-test v2 {std::variant<float, int, std::string_view> [no contained value]} } }
86 variant<float, int, string_view> v3{ 3 };
87 // { dg-final { note-test v3 {std::variant<float, int, std::string_view> [index 1] = {3}} } }
88 variant<float, int, string_view> v4{ str };
89 // { dg-final { note-test v4 {std::variant<float, int, std::string_view> [index 2] = {"string"}} } }
91 map<int, string_view> m{ {1, "one"} };
92 map<int, string_view>::node_type n0;
93 // { dg-final { note-test n0 {empty node handle for map}}}
94 map<int, string_view>::node_type n1 = m.extract(1);
95 // { dg-final { note-test n1 {node handle for map with element = {{first = 1, second = "two"}}}}}
97 unordered_set<int> s{ 3, 4 };
98 unordered_set<int>::node_type n2;
99 // { dg-final { note-test n2 {empty node handle for unordered set}}}
100 unordered_set<int>::node_type n3 = s.extract(3);
101 // { dg-final { note-test n1 {node handle for unordered set with element = {3}}}}
103 std::cout << "\n";
104 return 0; // Mark SPOT
107 // { dg-final { gdb-test SPOT } }