]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / compat.cc
1 // { dg-options "-g -O0" }
2 // { dg-do run { target c++11 } }
3
4 // Copyright (C) 2014-2020 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 // Test that current printers still support old definitions of types.
22
23 namespace std
24 {
25 template<typename T>
26 struct _Head_base : T
27 { };
28
29 template<typename T>
30 struct _Head_base<T*>
31 {
32 T* _M_head_impl;
33 };
34
35 template<unsigned long, typename ...> struct _Tuple_impl;
36
37 template<typename T, typename U>
38 struct _Tuple_impl<0, T, U> : _Tuple_impl<1, U>, _Head_base<T>
39 { };
40
41 template<typename U>
42 struct _Tuple_impl<1, U> : _Head_base<U>
43 { };
44
45 template<typename T, typename U>
46 struct tuple : _Tuple_impl<0, T, U>
47 { };
48
49 template<typename T> struct default_delete { };
50
51 template<typename T, typename D = default_delete<T>>
52 struct unique_ptr
53 {
54 unique_ptr(T* p) { _M_t._M_head_impl = p; }
55
56 tuple<T*, D> _M_t;
57 };
58
59 // Old representation of std::optional, before GCC 9
60 template<typename T>
61 struct _Optional_payload
62 {
63 _Optional_payload() : _M_empty(), _M_engaged(false) { }
64 struct _Empty_byte { };
65 union {
66 _Empty_byte _M_empty;
67 T _M_payload;
68 };
69 bool _M_engaged;
70 };
71
72 template<typename T>
73 struct _Optional_base
74 {
75 _Optional_payload<T> _M_payload;
76 };
77
78 template<typename T>
79 struct optional : _Optional_base<T>
80 {
81 optional() { }
82
83 optional(T t)
84 {
85 this->_M_payload._M_payload = t;
86 this->_M_payload._M_engaged = true;
87 }
88 };
89 } // namespace std
90
91 int
92 main()
93 {
94 struct datum { };
95 std::unique_ptr<datum> uptr (new datum);
96 // { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
97 std::unique_ptr<datum> &ruptr = uptr;
98 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
99
100 using std::optional;
101
102 optional<int> o;
103 // { dg-final { note-test o {std::optional<int> [no contained value]} } }
104 optional<bool> ob{false};
105 // { dg-final { note-test ob {std::optional<bool> = {[contained value] = false}} } }
106 optional<int> oi{5};
107 // { dg-final { note-test oi {std::optional<int> = {[contained value] = 5}} } }
108 optional<void*> op{nullptr};
109 // { dg-final { note-test op {std::optional<void *> = {[contained value] = 0x0}} } }
110
111 __builtin_puts("");
112 return 0; // Mark SPOT
113 }
114
115 // { dg-final { gdb-test SPOT } }