]> 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-2024 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 using __tuple_type = tuple<T*, D>;
57
58 __tuple_type _M_t;
59 };
60
61 // Old representation of std::optional, before GCC 9
62 template<typename T>
63 struct _Optional_payload
64 {
65 _Optional_payload() : _M_empty(), _M_engaged(false) { }
66 struct _Empty_byte { };
67 union {
68 _Empty_byte _M_empty;
69 T _M_payload;
70 };
71 bool _M_engaged;
72 };
73
74 template<typename T>
75 struct _Optional_base
76 {
77 _Optional_payload<T> _M_payload;
78 };
79
80 template<typename T>
81 struct optional : _Optional_base<T>
82 {
83 optional() { }
84
85 optional(T t)
86 {
87 this->_M_payload._M_payload = t;
88 this->_M_payload._M_engaged = true;
89 }
90 };
91 } // namespace std
92
93 int
94 main()
95 {
96 struct datum { };
97 std::unique_ptr<datum> uptr (new datum);
98 // { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
99 std::unique_ptr<datum> &ruptr = uptr;
100 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
101
102 using std::optional;
103
104 optional<int> o;
105 // { dg-final { note-test o {std::optional [no contained value]} } }
106 optional<bool> ob{false};
107 // { dg-final { note-test ob {std::optional = {[contained value] = false}} } }
108 optional<int> oi{5};
109 // { dg-final { note-test oi {std::optional = {[contained value] = 5}} } }
110 optional<void*> op{nullptr};
111 // { dg-final { note-test op {std::optional = {[contained value] = 0x0}} } }
112
113 __builtin_puts("");
114 return 0; // Mark SPOT
115 }
116
117 // { dg-final { gdb-test SPOT } }