Fix warnings for ICC 15
[alexxy/gromacs.git] / src / external / boost / boost / exception / exception.hpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
2
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
8 #if defined(__ICC) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma warning(disable:367) //GMX: For ICC15 "disable duplicate friend declaration" warning
10 #endif
11 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma GCC system_header
13 #endif
14 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
15 #pragma warning(push,1)
16 #endif
17
18 namespace
19 boost
20     {
21     namespace
22     exception_detail
23         {
24         template <class T>
25         class
26         refcount_ptr
27             {
28             public:
29
30             refcount_ptr():
31                 px_(0)
32                 {
33                 }
34
35             ~refcount_ptr()
36                 {
37                 release();
38                 }
39
40             refcount_ptr( refcount_ptr const & x ):
41                 px_(x.px_)
42                 {
43                 add_ref();
44                 }
45
46             refcount_ptr &
47             operator=( refcount_ptr const & x )
48                 {
49                 adopt(x.px_);
50                 return *this;
51                 }
52
53             void
54             adopt( T * px )
55                 {
56                 release();
57                 px_=px;
58                 add_ref();
59                 }
60
61             T *
62             get() const
63                 {
64                 return px_;
65                 }
66
67             private:
68
69             T * px_;
70
71             void
72             add_ref()
73                 {
74                 if( px_ )
75                     px_->add_ref();
76                 }
77
78             void
79             release()
80                 {
81                 if( px_ && px_->release() )
82                     px_=0;
83                 }
84             };
85         }
86
87     ////////////////////////////////////////////////////////////////////////
88
89     template <class Tag,class T>
90     class error_info;
91
92     typedef error_info<struct throw_function_,char const *> throw_function;
93     typedef error_info<struct throw_file_,char const *> throw_file;
94     typedef error_info<struct throw_line_,int> throw_line;
95
96     template <>
97     class
98     error_info<throw_function_,char const *>
99         {
100         public:
101         typedef char const * value_type;
102         value_type v_;
103         explicit
104         error_info( value_type v ):
105             v_(v)
106             {
107             }
108         };
109
110     template <>
111     class
112     error_info<throw_file_,char const *>
113         {
114         public:
115         typedef char const * value_type;
116         value_type v_;
117         explicit
118         error_info( value_type v ):
119             v_(v)
120             {
121             }
122         };
123
124     template <>
125     class
126     error_info<throw_line_,int>
127         {
128         public:
129         typedef int value_type;
130         value_type v_;
131         explicit
132         error_info( value_type v ):
133             v_(v)
134             {
135             }
136         };
137
138 #if defined(__GNUC__)
139 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
140 #  pragma GCC visibility push (default)
141 # endif
142 #endif
143     class exception;
144 #if defined(__GNUC__)
145 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
146 #  pragma GCC visibility pop
147 # endif
148 #endif
149
150     template <class T>
151     class shared_ptr;
152
153     namespace
154     exception_detail
155         {
156         class error_info_base;
157         struct type_info_;
158
159         struct
160         error_info_container
161             {
162             virtual char const * diagnostic_information( char const * ) const = 0;
163             virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
164             virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
165             virtual void add_ref() const = 0;
166             virtual bool release() const = 0;
167             virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
168
169             protected:
170
171             ~error_info_container() throw()
172                 {
173                 }
174             };
175
176         template <class>
177         struct get_info;
178
179         template <>
180         struct get_info<throw_function>;
181
182         template <>
183         struct get_info<throw_file>;
184
185         template <>
186         struct get_info<throw_line>;
187
188         char const * get_diagnostic_information( exception const &, char const * );
189
190         void copy_boost_exception( exception *, exception const * );
191
192         template <class E,class Tag,class T>
193         E const & set_info( E const &, error_info<Tag,T> const & );
194
195         template <class E>
196         E const & set_info( E const &, throw_function const & );
197
198         template <class E>
199         E const & set_info( E const &, throw_file const & );
200
201         template <class E>
202         E const & set_info( E const &, throw_line const & );
203         }
204
205 #if defined(__GNUC__)
206 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
207 #  pragma GCC visibility push (default)
208 # endif
209 #endif
210     class
211     exception
212         {
213         protected:
214
215         exception():
216             throw_function_(0),
217             throw_file_(0),
218             throw_line_(-1)
219             {
220             }
221
222 #ifdef __HP_aCC
223         //On HP aCC, this protected copy constructor prevents throwing boost::exception.
224         //On all other platforms, the same effect is achieved by the pure virtual destructor.
225         exception( exception const & x ) throw():
226             data_(x.data_),
227             throw_function_(x.throw_function_),
228             throw_file_(x.throw_file_),
229             throw_line_(x.throw_line_)
230             {
231             }
232 #endif
233
234         virtual ~exception() throw()
235 #ifndef __HP_aCC
236             = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
237 #endif
238             ;
239
240 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
241         public:
242 #else
243         private:
244
245         template <class E>
246         friend E const & exception_detail::set_info( E const &, throw_function const & );
247
248         template <class E>
249         friend E const & exception_detail::set_info( E const &, throw_file const & );
250
251         template <class E>
252         friend E const & exception_detail::set_info( E const &, throw_line const & );
253
254         template <class E,class Tag,class T>
255         friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
256
257         friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
258
259         template <class>
260         friend struct exception_detail::get_info;
261         friend struct exception_detail::get_info<throw_function>;
262         friend struct exception_detail::get_info<throw_file>;
263         friend struct exception_detail::get_info<throw_line>;
264         friend void exception_detail::copy_boost_exception( exception *, exception const * );
265 #endif
266         mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
267         mutable char const * throw_function_;
268         mutable char const * throw_file_;
269         mutable int throw_line_;
270         };
271 #if defined(__GNUC__)
272 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
273 #  pragma GCC visibility pop
274 # endif
275 #endif
276
277     inline
278     exception::
279     ~exception() throw()
280         {
281         }
282
283     namespace
284     exception_detail
285         {
286         template <class E>
287         E const &
288         set_info( E const & x, throw_function const & y )
289             {
290             x.throw_function_=y.v_;
291             return x;
292             }
293
294         template <class E>
295         E const &
296         set_info( E const & x, throw_file const & y )
297             {
298             x.throw_file_=y.v_;
299             return x;
300             }
301
302         template <class E>
303         E const &
304         set_info( E const & x, throw_line const & y )
305             {
306             x.throw_line_=y.v_;
307             return x;
308             }
309         }
310
311     ////////////////////////////////////////////////////////////////////////
312
313     namespace
314     exception_detail
315         {
316 #if defined(__GNUC__)
317 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
318 #  pragma GCC visibility push (default)
319 # endif
320 #endif
321         template <class T>
322         struct
323         error_info_injector:
324             public T,
325             public exception
326             {
327             explicit
328             error_info_injector( T const & x ):
329                 T(x)
330                 {
331                 }
332
333             ~error_info_injector() throw()
334                 {
335                 }
336             };
337 #if defined(__GNUC__)
338 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
339 #  pragma GCC visibility pop
340 # endif
341 #endif
342
343         struct large_size { char c[256]; };
344         large_size dispatch_boost_exception( exception const * );
345
346         struct small_size { };
347         small_size dispatch_boost_exception( void const * );
348
349         template <class,int>
350         struct enable_error_info_helper;
351
352         template <class T>
353         struct
354         enable_error_info_helper<T,sizeof(large_size)>
355             {
356             typedef T type;
357             };
358
359         template <class T>
360         struct
361         enable_error_info_helper<T,sizeof(small_size)>
362             {
363             typedef error_info_injector<T> type;
364             };
365
366         template <class T>
367         struct
368         enable_error_info_return_type
369             {
370             typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
371             };
372         }
373
374     template <class T>
375     inline
376     typename
377     exception_detail::enable_error_info_return_type<T>::type
378     enable_error_info( T const & x )
379         {
380         typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
381         return rt(x);
382         }
383
384     ////////////////////////////////////////////////////////////////////////
385
386     namespace
387     exception_detail
388         {
389 #if defined(__GNUC__)
390 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
391 #  pragma GCC visibility push (default)
392 # endif
393 #endif
394         class
395         clone_base
396             {
397             public:
398
399             virtual clone_base const * clone() const = 0;
400             virtual void rethrow() const = 0;
401
402             virtual
403             ~clone_base() throw()
404                 {
405                 }
406             };
407 #if defined(__GNUC__)
408 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
409 #  pragma GCC visibility pop
410 # endif
411 #endif
412
413         inline
414         void
415         copy_boost_exception( exception * a, exception const * b )
416             {
417             refcount_ptr<error_info_container> data;
418             if( error_info_container * d=b->data_.get() )
419                 data = d->clone();
420             a->throw_file_ = b->throw_file_;
421             a->throw_line_ = b->throw_line_;
422             a->throw_function_ = b->throw_function_;
423             a->data_ = data;
424             }
425
426         inline
427         void
428         copy_boost_exception( void *, void const * )
429             {
430             }
431
432         template <class T>
433         class
434         clone_impl:
435             public T,
436             public virtual clone_base
437             {
438             struct clone_tag { };
439             clone_impl( clone_impl const & x, clone_tag ):
440                 T(x)
441                 {
442                 copy_boost_exception(this,&x);
443                 }
444
445             public:
446
447             explicit
448             clone_impl( T const & x ):
449                 T(x)
450                 {
451                 copy_boost_exception(this,&x);
452                 }
453
454             ~clone_impl() throw()
455                 {
456                 }
457
458             private:
459
460             clone_base const *
461             clone() const
462                 {
463                 return new clone_impl(*this,clone_tag());
464                 }
465
466             void
467             rethrow() const
468                 {
469                 throw*this;
470                 }
471             };
472         }
473
474     template <class T>
475     inline
476     exception_detail::clone_impl<T>
477     enable_current_exception( T const & x )
478         {
479         return exception_detail::clone_impl<T>(x);
480         }
481     }
482
483 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
484 #pragma warning(pop)
485 #endif
486 #endif