Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / torture / pr44972.C
blob1ace4d9f6b264e3d400f39ff51344ffc6b33033d
1 /* { dg-do compile } */
2 /* { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } */
4 #include<cassert>
5 #include<new>
6 #include<utility>
8 namespace boost {
10 template<class T>
11 class optional;
13 class aligned_storage
15         char data[ 1000 ];
16   public:
17     void const* address() const { return &data[0]; }
18     void      * address()       { return &data[0]; }
19 } ;
22 template<class T>
23 class optional_base
25   protected :
26     optional_base(){}
27     optional_base ( T const& val )
28     {
29       construct(val);
30     }
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     }
40   public :
42     bool is_initialized() const { return m_initialized ; }
44   protected :
46     void construct ( T const& val )
47      {
48        new (m_storage.address()) T(val) ;
49      }
51     T const* get_ptr_impl() const
52     { return static_cast<T const*>(m_storage.address()); }
54   private :
56     bool m_initialized ;
57     aligned_storage  m_storage ;
58 } ;
61 template<class T>
62 class optional : public optional_base<T>
64     typedef optional_base<T> base ;
66   public :
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       }
76     T const& get() const ;
78     T const* operator->() const { assert(this->is_initialized()) ; return this->get_ptr_impl() ; }
80 } ;
83 } // namespace boost
86 namespace std
89   template<typename _Tp, std::size_t _Nm>
90     struct array
91     {
92       typedef _Tp                                     value_type;
93       typedef const value_type*                       const_iterator;
95       value_type _M_instance[_Nm];
97     };
101 class NT
103   double _inf, _sup;
107 template < typename T > inline
108 std::array<T, 1>
109 make_array(const T& b1)
111   std::array<T, 1> a = { { b1 } };
112   return a;
115 class V
117   typedef std::array<NT, 1>               Base;
118   Base base;
120 public:
121   V() {}
122   V(const NT &x)
123     : base(make_array(x)) {}
127 using boost::optional ;
129 optional< std::pair< NT, NT > >
130   linsolve_pointC2() ;
132 optional< V > construct_normal_offset_lines_isecC2 ( )
134   optional< std::pair<NT,NT> > ip;
136   ip = linsolve_pointC2();
138   V a(ip->first) ;
139   return a;