aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc
blob: 255d3e7cff1e55b57ffb8084d06683df6fafa9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// { dg-options "-g -O0" }
// { dg-do run { target c++11 } }
// { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }

// Copyright (C) 2014-2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// Test that current printers still support old definitions of types.

namespace std
{
  template<typename T, typename U>
    struct tuple
    {
      T _M_head_impl;
    };

  template<typename T> struct default_delete { };

  template<typename T, typename D = default_delete<T>>
    struct unique_ptr
    {
      unique_ptr(T* p) { _M_t._M_head_impl = p; }

      tuple<T*, D> _M_t;
    };

  // Old representation of std::optional, before GCC 9
  template<typename T>
    struct _Optional_payload
    {
      _Optional_payload() : _M_empty(), _M_engaged(false) { }
      struct _Empty_byte { };
      union {
	_Empty_byte _M_empty;
	T _M_payload;
      };
      bool _M_engaged;
    };

  template<typename T>
    struct _Optional_base
    {
      _Optional_payload<T> _M_payload;
    };

  template<typename T>
    struct optional : _Optional_base<T>
    {
      optional() { }

      optional(T t)
      {
	this->_M_payload._M_payload = t;
	this->_M_payload._M_engaged = true;
      }
    };
} // namespace std

int
main()
{
  struct datum { };
  std::unique_ptr<datum> uptr (new datum);
// { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
  std::unique_ptr<datum> &ruptr = uptr;
// { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }

  using std::optional;

  optional<int> o;
// { dg-final { note-test o {std::optional<int> [no contained value]} } }
  optional<bool> ob{false};
// { dg-final { note-test ob {std::optional<bool> = {[contained value] = false}} } }
  optional<int> oi{5};
// { dg-final { note-test oi {std::optional<int> = {[contained value] = 5}} } }
  optional<void*> op{nullptr};
// { dg-final { note-test op {std::optional<void *> = {[contained value] = 0x0}} } }

  __builtin_puts("");
  return 0;			// Mark SPOT
}

// { dg-final { gdb-test SPOT } }