Debian Codegraph @

gcc/testsuite/g++.dg/torture/pr44972.C

raw
1 /* { dg-do compile } */
2 /* { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } */
3
4 #include<cassert>
5 #include<new>
6 #include<utility>
7
8 namespace boost {
9
10 template<class T>
11 class optional;
12
13 class aligned_storage
14 {
15 char data[ 1000 ];
16 public:
17 void const* address() const { return &data[0]; }
18 void * address() { return &data[0]; }
19 } ;
20
21
22 template<class T>
23 class optional_base
24 {
25 protected :
26 optional_base(){}
27 optional_base ( T const& val )
28 {
29 construct(val);
30 }
31
32 template<class U>
33 void assign ( optional<U> const& rhs )
34 {
35 if (!is_initialized())
36 if ( rhs.is_initialized() )
37 construct(T());
38 }
39
40 public :
41
42 bool is_initialized() const { return m_initialized ; }
43
44 protected :
45
46 void construct ( T const& val )
47 {
48 new (m_storage.address()) T(val) ;
49 }
50
51 T const* get_ptr_impl() const
52 { return static_cast<T const*>(m_storage.address()); }
53
54 private :
55
56 bool m_initialized ;
57 aligned_storage m_storage ;
58 } ;
59
60
61 template<class T>
62 class optional : public optional_base<T>
63 {
64 typedef optional_base<T> base ;
65
66 public :
67
68 optional() : base() {}
69 optional ( T const& val ) : base(val) {}
70 optional& operator= ( optional const& rhs )
71 {
72 this->assign( rhs ) ;
73 return *this ;
74 }
75
76 T const& get() const ;
77
78 T const* operator->() const { assert(this->is_initialized()) ; return this->get_ptr_impl() ; }
79
80 } ;
81
82
83 } // namespace boost
84
85
86 namespace std
87 {
88
89 template<typename _Tp, std::size_t _Nm>
90 struct array
91 {
92 typedef _Tp value_type;
93 typedef const value_type* const_iterator;
94
95 value_type _M_instance[_Nm];
96
97 };
98 }
99
100
101 class NT
102 {
103 double _inf, _sup;
104 };
105
106
107 template < typename T > inline
108 std::array<T, 1>
109 make_array(const T& b1)
110 {
111 std::array<T, 1> a = { { b1 } };
112 return a;
113 }
114
115 class V
116 {
117 typedef std::array<NT, 1> Base;
118 Base base;
119
120 public:
121 V() {}
122 V(const NT &x)
123 : base(make_array(x)) {}
124
125 };
126
127 using boost::optional ;
128
129 optional< std::pair< NT, NT > >
130 linsolve_pointC2() ;
131
132 optional< V > construct_normal_offset_lines_isecC2 ( )
133 {
134 optional< std::pair<NT,NT> > ip;
135
136 ip = linsolve_pointC2();
137
138 V a(ip->first) ;
139 return a;
140 }
141
142
143