• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---------------------------- system_error ------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This was lifted from libc++ and modified for C++03. This is called
11 // system_error even though it does not define that class because that's what
12 // it's called in C++0x. We don't define system_error because it is only used
13 // for exception handling, which we don't use in LLVM.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_SYSTEM_SYSTEM_ERROR_H
18 #define LLVM_SYSTEM_SYSTEM_ERROR_H
19 
20 /*
21     system_error synopsis
22 
23 namespace std
24 {
25 
26 class error_category
27 {
28 public:
29     virtual ~error_category();
30 
31     error_category(const error_category&) = delete;
32     error_category& operator=(const error_category&) = delete;
33 
34     virtual const char* name() const = 0;
35     virtual error_condition default_error_condition(int ev) const;
36     virtual bool equivalent(int code, const error_condition& condition) const;
37     virtual bool equivalent(const error_code& code, int condition) const;
38     virtual std::string message(int ev) const = 0;
39 
40     bool operator==(const error_category& rhs) const;
41     bool operator!=(const error_category& rhs) const;
42     bool operator<(const error_category& rhs) const;
43 };
44 
45 const error_category& generic_category();
46 const error_category& system_category();
47 
48 template <class T> struct is_error_code_enum
49     : public false_type {};
50 
51 template <class T> struct is_error_condition_enum
52     : public false_type {};
53 
54 class error_code
55 {
56 public:
57     // constructors:
58     error_code();
59     error_code(int val, const error_category& cat);
60     template <class ErrorCodeEnum>
61         error_code(ErrorCodeEnum e);
62 
63     // modifiers:
64     void assign(int val, const error_category& cat);
65     template <class ErrorCodeEnum>
66         error_code& operator=(ErrorCodeEnum e);
67     void clear();
68 
69     // observers:
70     int value() const;
71     const error_category& category() const;
72     error_condition default_error_condition() const;
73     std::string message() const;
74     explicit operator bool() const;
75 };
76 
77 // non-member functions:
78 bool operator<(const error_code& lhs, const error_code& rhs);
79 template <class charT, class traits>
80     basic_ostream<charT,traits>&
81     operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
82 
83 class error_condition
84 {
85 public:
86     // constructors:
87     error_condition();
88     error_condition(int val, const error_category& cat);
89     template <class ErrorConditionEnum>
90         error_condition(ErrorConditionEnum e);
91 
92     // modifiers:
93     void assign(int val, const error_category& cat);
94     template <class ErrorConditionEnum>
95         error_condition& operator=(ErrorConditionEnum e);
96     void clear();
97 
98     // observers:
99     int value() const;
100     const error_category& category() const;
101     std::string message() const;
102     explicit operator bool() const;
103 };
104 
105 bool operator<(const error_condition& lhs, const error_condition& rhs);
106 
107 class system_error
108     : public runtime_error
109 {
110 public:
111     system_error(error_code ec, const std::string& what_arg);
112     system_error(error_code ec, const char* what_arg);
113     system_error(error_code ec);
114     system_error(int ev, const error_category& ecat, const std::string& what_arg);
115     system_error(int ev, const error_category& ecat, const char* what_arg);
116     system_error(int ev, const error_category& ecat);
117 
118     const error_code& code() const throw();
119     const char* what() const throw();
120 };
121 
122 enum class errc
123 {
124     address_family_not_supported,       // EAFNOSUPPORT
125     address_in_use,                     // EADDRINUSE
126     address_not_available,              // EADDRNOTAVAIL
127     already_connected,                  // EISCONN
128     argument_list_too_long,             // E2BIG
129     argument_out_of_domain,             // EDOM
130     bad_address,                        // EFAULT
131     bad_file_descriptor,                // EBADF
132     bad_message,                        // EBADMSG
133     broken_pipe,                        // EPIPE
134     connection_aborted,                 // ECONNABORTED
135     connection_already_in_progress,     // EALREADY
136     connection_refused,                 // ECONNREFUSED
137     connection_reset,                   // ECONNRESET
138     cross_device_link,                  // EXDEV
139     destination_address_required,       // EDESTADDRREQ
140     device_or_resource_busy,            // EBUSY
141     directory_not_empty,                // ENOTEMPTY
142     executable_format_error,            // ENOEXEC
143     file_exists,                        // EEXIST
144     file_too_large,                     // EFBIG
145     filename_too_long,                  // ENAMETOOLONG
146     function_not_supported,             // ENOSYS
147     host_unreachable,                   // EHOSTUNREACH
148     identifier_removed,                 // EIDRM
149     illegal_byte_sequence,              // EILSEQ
150     inappropriate_io_control_operation, // ENOTTY
151     interrupted,                        // EINTR
152     invalid_argument,                   // EINVAL
153     invalid_seek,                       // ESPIPE
154     io_error,                           // EIO
155     is_a_directory,                     // EISDIR
156     message_size,                       // EMSGSIZE
157     network_down,                       // ENETDOWN
158     network_reset,                      // ENETRESET
159     network_unreachable,                // ENETUNREACH
160     no_buffer_space,                    // ENOBUFS
161     no_child_process,                   // ECHILD
162     no_link,                            // ENOLINK
163     no_lock_available,                  // ENOLCK
164     no_message_available,               // ENODATA
165     no_message,                         // ENOMSG
166     no_protocol_option,                 // ENOPROTOOPT
167     no_space_on_device,                 // ENOSPC
168     no_stream_resources,                // ENOSR
169     no_such_device_or_address,          // ENXIO
170     no_such_device,                     // ENODEV
171     no_such_file_or_directory,          // ENOENT
172     no_such_process,                    // ESRCH
173     not_a_directory,                    // ENOTDIR
174     not_a_socket,                       // ENOTSOCK
175     not_a_stream,                       // ENOSTR
176     not_connected,                      // ENOTCONN
177     not_enough_memory,                  // ENOMEM
178     not_supported,                      // ENOTSUP
179     operation_canceled,                 // ECANCELED
180     operation_in_progress,              // EINPROGRESS
181     operation_not_permitted,            // EPERM
182     operation_not_supported,            // EOPNOTSUPP
183     operation_would_block,              // EWOULDBLOCK
184     owner_dead,                         // EOWNERDEAD
185     permission_denied,                  // EACCES
186     protocol_error,                     // EPROTO
187     protocol_not_supported,             // EPROTONOSUPPORT
188     read_only_file_system,              // EROFS
189     resource_deadlock_would_occur,      // EDEADLK
190     resource_unavailable_try_again,     // EAGAIN
191     result_out_of_range,                // ERANGE
192     state_not_recoverable,              // ENOTRECOVERABLE
193     stream_timeout,                     // ETIME
194     text_file_busy,                     // ETXTBSY
195     timed_out,                          // ETIMEDOUT
196     too_many_files_open_in_system,      // ENFILE
197     too_many_files_open,                // EMFILE
198     too_many_links,                     // EMLINK
199     too_many_symbolic_link_levels,      // ELOOP
200     value_too_large,                    // EOVERFLOW
201     wrong_protocol_type                 // EPROTOTYPE
202 };
203 
204 template <> struct is_error_condition_enum<errc> : true_type { }
205 
206 error_code make_error_code(errc e);
207 error_condition make_error_condition(errc e);
208 
209 // Comparison operators:
210 bool operator==(const error_code& lhs, const error_code& rhs);
211 bool operator==(const error_code& lhs, const error_condition& rhs);
212 bool operator==(const error_condition& lhs, const error_code& rhs);
213 bool operator==(const error_condition& lhs, const error_condition& rhs);
214 bool operator!=(const error_code& lhs, const error_code& rhs);
215 bool operator!=(const error_code& lhs, const error_condition& rhs);
216 bool operator!=(const error_condition& lhs, const error_code& rhs);
217 bool operator!=(const error_condition& lhs, const error_condition& rhs);
218 
219 template <> struct hash<std::error_code>;
220 
221 }  // std
222 
223 */
224 
225 #include "llvm/Config/llvm-config.h"
226 #include "llvm/Support/type_traits.h"
227 #include <cerrno>
228 #include <string>
229 
230 // This must be here instead of a .inc file because it is used in the definition
231 // of the enum values below.
232 #ifdef LLVM_ON_WIN32
233 
234   // The following numbers were taken from VS2010.
235 # ifndef EAFNOSUPPORT
236 #   define EAFNOSUPPORT 102
237 # endif
238 # ifndef EADDRINUSE
239 #   define EADDRINUSE 100
240 # endif
241 # ifndef EADDRNOTAVAIL
242 #   define EADDRNOTAVAIL 101
243 # endif
244 # ifndef EISCONN
245 #   define EISCONN 113
246 # endif
247 # ifndef E2BIG
248 #   define E2BIG 7
249 # endif
250 # ifndef EDOM
251 #   define EDOM 33
252 # endif
253 # ifndef EFAULT
254 #   define EFAULT 14
255 # endif
256 # ifndef EBADF
257 #   define EBADF 9
258 # endif
259 # ifndef EBADMSG
260 #   define EBADMSG 104
261 # endif
262 # ifndef EPIPE
263 #   define EPIPE 32
264 # endif
265 # ifndef ECONNABORTED
266 #   define ECONNABORTED 106
267 # endif
268 # ifndef EALREADY
269 #   define EALREADY 103
270 # endif
271 # ifndef ECONNREFUSED
272 #   define ECONNREFUSED 107
273 # endif
274 # ifndef ECONNRESET
275 #   define ECONNRESET 108
276 # endif
277 # ifndef EXDEV
278 #   define EXDEV 18
279 # endif
280 # ifndef EDESTADDRREQ
281 #   define EDESTADDRREQ 109
282 # endif
283 # ifndef EBUSY
284 #   define EBUSY 16
285 # endif
286 # ifndef ENOTEMPTY
287 #   define ENOTEMPTY 41
288 # endif
289 # ifndef ENOEXEC
290 #   define ENOEXEC 8
291 # endif
292 # ifndef EEXIST
293 #   define EEXIST 17
294 # endif
295 # ifndef EFBIG
296 #   define EFBIG 27
297 # endif
298 # ifndef ENAMETOOLONG
299 #   define ENAMETOOLONG 38
300 # endif
301 # ifndef ENOSYS
302 #   define ENOSYS 40
303 # endif
304 # ifndef EHOSTUNREACH
305 #   define EHOSTUNREACH 110
306 # endif
307 # ifndef EIDRM
308 #   define EIDRM 111
309 # endif
310 # ifndef EILSEQ
311 #   define EILSEQ 42
312 # endif
313 # ifndef ENOTTY
314 #   define ENOTTY 25
315 # endif
316 # ifndef EINTR
317 #   define EINTR 4
318 # endif
319 # ifndef EINVAL
320 #   define EINVAL 22
321 # endif
322 # ifndef ESPIPE
323 #   define ESPIPE 29
324 # endif
325 # ifndef EIO
326 #   define EIO 5
327 # endif
328 # ifndef EISDIR
329 #   define EISDIR 21
330 # endif
331 # ifndef EMSGSIZE
332 #   define EMSGSIZE 115
333 # endif
334 # ifndef ENETDOWN
335 #   define ENETDOWN 116
336 # endif
337 # ifndef ENETRESET
338 #   define ENETRESET 117
339 # endif
340 # ifndef ENETUNREACH
341 #   define ENETUNREACH 118
342 # endif
343 # ifndef ENOBUFS
344 #   define ENOBUFS 119
345 # endif
346 # ifndef ECHILD
347 #   define ECHILD 10
348 # endif
349 # ifndef ENOLINK
350 #   define ENOLINK 121
351 # endif
352 # ifndef ENOLCK
353 #   define ENOLCK 39
354 # endif
355 # ifndef ENODATA
356 #   define ENODATA 120
357 # endif
358 # ifndef ENOMSG
359 #   define ENOMSG 122
360 # endif
361 # ifndef ENOPROTOOPT
362 #   define ENOPROTOOPT 123
363 # endif
364 # ifndef ENOSPC
365 #   define ENOSPC 28
366 # endif
367 # ifndef ENOSR
368 #   define ENOSR 124
369 # endif
370 # ifndef ENXIO
371 #   define ENXIO 6
372 # endif
373 # ifndef ENODEV
374 #   define ENODEV 19
375 # endif
376 # ifndef ENOENT
377 #   define ENOENT 2
378 # endif
379 # ifndef ESRCH
380 #   define ESRCH 3
381 # endif
382 # ifndef ENOTDIR
383 #   define ENOTDIR 20
384 # endif
385 # ifndef ENOTSOCK
386 #   define ENOTSOCK 128
387 # endif
388 # ifndef ENOSTR
389 #   define ENOSTR 125
390 # endif
391 # ifndef ENOTCONN
392 #   define ENOTCONN 126
393 # endif
394 # ifndef ENOMEM
395 #   define ENOMEM 12
396 # endif
397 # ifndef ENOTSUP
398 #   define ENOTSUP 129
399 # endif
400 # ifndef ECANCELED
401 #   define ECANCELED 105
402 # endif
403 # ifndef EINPROGRESS
404 #   define EINPROGRESS 112
405 # endif
406 # ifndef EPERM
407 #   define EPERM 1
408 # endif
409 # ifndef EOPNOTSUPP
410 #   define EOPNOTSUPP 130
411 # endif
412 # ifndef EWOULDBLOCK
413 #   define EWOULDBLOCK 140
414 # endif
415 # ifndef EOWNERDEAD
416 #   define EOWNERDEAD 133
417 # endif
418 # ifndef EACCES
419 #   define EACCES 13
420 # endif
421 # ifndef EPROTO
422 #   define EPROTO 134
423 # endif
424 # ifndef EPROTONOSUPPORT
425 #   define EPROTONOSUPPORT 135
426 # endif
427 # ifndef EROFS
428 #   define EROFS 30
429 # endif
430 # ifndef EDEADLK
431 #   define EDEADLK 36
432 # endif
433 # ifndef EAGAIN
434 #   define EAGAIN 11
435 # endif
436 # ifndef ERANGE
437 #   define ERANGE 34
438 # endif
439 # ifndef ENOTRECOVERABLE
440 #   define ENOTRECOVERABLE 127
441 # endif
442 # ifndef ETIME
443 #   define ETIME 137
444 # endif
445 # ifndef ETXTBSY
446 #   define ETXTBSY 139
447 # endif
448 # ifndef ETIMEDOUT
449 #   define ETIMEDOUT 138
450 # endif
451 # ifndef ENFILE
452 #   define ENFILE 23
453 # endif
454 # ifndef EMFILE
455 #   define EMFILE 24
456 # endif
457 # ifndef EMLINK
458 #   define EMLINK 31
459 # endif
460 # ifndef ELOOP
461 #   define ELOOP 114
462 # endif
463 # ifndef EOVERFLOW
464 #   define EOVERFLOW 132
465 # endif
466 # ifndef EPROTOTYPE
467 #   define EPROTOTYPE 136
468 # endif
469 #endif
470 
471 namespace llvm {
472 
473 template <class T, T v>
474 struct integral_constant {
475   typedef T value_type;
476   static const value_type value = v;
477   typedef integral_constant<T,v> type;
value_typeintegral_constant478   operator value_type() { return value; }
479 };
480 
481 typedef integral_constant<bool, true> true_type;
482 typedef integral_constant<bool, false> false_type;
483 
484 // is_error_code_enum
485 
486 template <class Tp> struct is_error_code_enum : public false_type {};
487 
488 // is_error_condition_enum
489 
490 template <class Tp> struct is_error_condition_enum : public false_type {};
491 
492 // Some error codes are not present on all platforms, so we provide equivalents
493 // for them:
494 
495 //enum class errc
496 struct errc {
497 enum _ {
498   success                             = 0,
499   address_family_not_supported        = EAFNOSUPPORT,
500   address_in_use                      = EADDRINUSE,
501   address_not_available               = EADDRNOTAVAIL,
502   already_connected                   = EISCONN,
503   argument_list_too_long              = E2BIG,
504   argument_out_of_domain              = EDOM,
505   bad_address                         = EFAULT,
506   bad_file_descriptor                 = EBADF,
507 #ifdef EBADMSG
508   bad_message                         = EBADMSG,
509 #else
510   bad_message                         = EINVAL,
511 #endif
512   broken_pipe                         = EPIPE,
513   connection_aborted                  = ECONNABORTED,
514   connection_already_in_progress      = EALREADY,
515   connection_refused                  = ECONNREFUSED,
516   connection_reset                    = ECONNRESET,
517   cross_device_link                   = EXDEV,
518   destination_address_required        = EDESTADDRREQ,
519   device_or_resource_busy             = EBUSY,
520   directory_not_empty                 = ENOTEMPTY,
521   executable_format_error             = ENOEXEC,
522   file_exists                         = EEXIST,
523   file_too_large                      = EFBIG,
524   filename_too_long                   = ENAMETOOLONG,
525   function_not_supported              = ENOSYS,
526   host_unreachable                    = EHOSTUNREACH,
527   identifier_removed                  = EIDRM,
528   illegal_byte_sequence               = EILSEQ,
529   inappropriate_io_control_operation  = ENOTTY,
530   interrupted                         = EINTR,
531   invalid_argument                    = EINVAL,
532   invalid_seek                        = ESPIPE,
533   io_error                            = EIO,
534   is_a_directory                      = EISDIR,
535   message_size                        = EMSGSIZE,
536   network_down                        = ENETDOWN,
537   network_reset                       = ENETRESET,
538   network_unreachable                 = ENETUNREACH,
539   no_buffer_space                     = ENOBUFS,
540   no_child_process                    = ECHILD,
541 #ifdef ENOLINK
542   no_link                             = ENOLINK,
543 #else
544   no_link                             = EINVAL,
545 #endif
546   no_lock_available                   = ENOLCK,
547 #ifdef ENODATA
548   no_message_available                = ENODATA,
549 #else
550   no_message_available                = ENOMSG,
551 #endif
552   no_message                          = ENOMSG,
553   no_protocol_option                  = ENOPROTOOPT,
554   no_space_on_device                  = ENOSPC,
555 #ifdef ENOSR
556   no_stream_resources                 = ENOSR,
557 #else
558   no_stream_resources                 = ENOMEM,
559 #endif
560   no_such_device_or_address           = ENXIO,
561   no_such_device                      = ENODEV,
562   no_such_file_or_directory           = ENOENT,
563   no_such_process                     = ESRCH,
564   not_a_directory                     = ENOTDIR,
565   not_a_socket                        = ENOTSOCK,
566 #ifdef ENOSTR
567   not_a_stream                        = ENOSTR,
568 #else
569   not_a_stream                        = EINVAL,
570 #endif
571   not_connected                       = ENOTCONN,
572   not_enough_memory                   = ENOMEM,
573   not_supported                       = ENOTSUP,
574 #ifdef ECANCELED
575   operation_canceled                  = ECANCELED,
576 #else
577   operation_canceled                  = EINVAL,
578 #endif
579   operation_in_progress               = EINPROGRESS,
580   operation_not_permitted             = EPERM,
581   operation_not_supported             = EOPNOTSUPP,
582   operation_would_block               = EWOULDBLOCK,
583 #ifdef EOWNERDEAD
584   owner_dead                          = EOWNERDEAD,
585 #else
586   owner_dead                          = EINVAL,
587 #endif
588   permission_denied                   = EACCES,
589 #ifdef EPROTO
590   protocol_error                      = EPROTO,
591 #else
592   protocol_error                      = EINVAL,
593 #endif
594   protocol_not_supported              = EPROTONOSUPPORT,
595   read_only_file_system               = EROFS,
596   resource_deadlock_would_occur       = EDEADLK,
597   resource_unavailable_try_again      = EAGAIN,
598   result_out_of_range                 = ERANGE,
599 #ifdef ENOTRECOVERABLE
600   state_not_recoverable               = ENOTRECOVERABLE,
601 #else
602   state_not_recoverable               = EINVAL,
603 #endif
604 #ifdef ETIME
605   stream_timeout                      = ETIME,
606 #else
607   stream_timeout                      = ETIMEDOUT,
608 #endif
609   text_file_busy                      = ETXTBSY,
610   timed_out                           = ETIMEDOUT,
611   too_many_files_open_in_system       = ENFILE,
612   too_many_files_open                 = EMFILE,
613   too_many_links                      = EMLINK,
614   too_many_symbolic_link_levels       = ELOOP,
615   value_too_large                     = EOVERFLOW,
616   wrong_protocol_type                 = EPROTOTYPE
617 };
618 
619   _ v_;
620 
errcerrc621   errc(_ v) : v_(v) {}
622   operator int() const {return v_;}
623 };
624 
625 template <> struct is_error_condition_enum<errc> : true_type { };
626 
627 template <> struct is_error_condition_enum<errc::_> : true_type { };
628 
629 class error_condition;
630 class error_code;
631 
632 // class error_category
633 
634 class _do_message;
635 
636 class error_category
637 {
638 public:
639   virtual ~error_category();
640 
641 private:
642   error_category();
643   error_category(const error_category&);// = delete;
644   error_category& operator=(const error_category&);// = delete;
645 
646 public:
647   virtual const char* name() const = 0;
648   virtual error_condition default_error_condition(int _ev) const;
649   virtual bool equivalent(int _code, const error_condition& _condition) const;
650   virtual bool equivalent(const error_code& _code, int _condition) const;
651   virtual std::string message(int _ev) const = 0;
652 
653   bool operator==(const error_category& _rhs) const {return this == &_rhs;}
654 
655   bool operator!=(const error_category& _rhs) const {return !(*this == _rhs);}
656 
657   bool operator< (const error_category& _rhs) const {return this < &_rhs;}
658 
659   friend class _do_message;
660 };
661 
662 class _do_message : public error_category
663 {
664 public:
665   virtual std::string message(int ev) const;
666 };
667 
668 const error_category& generic_category();
669 const error_category& system_category();
670 
671 /// Get the error_category used for errno values from POSIX functions. This is
672 /// the same as the system_category on POSIX systems, but is the same as the
673 /// generic_category on Windows.
674 const error_category& posix_category();
675 
676 class error_condition
677 {
678   int _val_;
679   const error_category* _cat_;
680 public:
681   error_condition() : _val_(0), _cat_(&generic_category()) {}
682 
683   error_condition(int _val, const error_category& _cat)
684     : _val_(_val), _cat_(&_cat) {}
685 
686   template <class E>
687   error_condition(E _e, typename enable_if_c<
688                           is_error_condition_enum<E>::value
689                         >::type* = 0)
690     {*this = make_error_condition(_e);}
691 
692   void assign(int _val, const error_category& _cat) {
693     _val_ = _val;
694     _cat_ = &_cat;
695   }
696 
697   template <class E>
698     typename enable_if_c
699     <
700       is_error_condition_enum<E>::value,
701       error_condition&
702     >::type
703     operator=(E _e)
704       {*this = make_error_condition(_e); return *this;}
705 
706   void clear() {
707     _val_ = 0;
708     _cat_ = &generic_category();
709   }
710 
711   int value() const {return _val_;}
712 
713   const error_category& category() const {return *_cat_;}
714   std::string message() const;
715 
716   typedef void (*unspecified_bool_type)();
717   static void unspecified_bool_true() {}
718 
719   operator unspecified_bool_type() const { // true if error
720     return _val_ == 0 ? 0 : unspecified_bool_true;
721   }
722 };
723 
724 inline error_condition make_error_condition(errc _e) {
725   return error_condition(static_cast<int>(_e), generic_category());
726 }
727 
728 inline bool operator<(const error_condition& _x, const error_condition& _y) {
729   return _x.category() < _y.category()
730       || (_x.category() == _y.category() && _x.value() < _y.value());
731 }
732 
733 // error_code
734 
735 class error_code {
736   int _val_;
737   const error_category* _cat_;
738 public:
739   error_code() : _val_(0), _cat_(&system_category()) {}
740 
741   error_code(int _val, const error_category& _cat)
742     : _val_(_val), _cat_(&_cat) {}
743 
744   template <class E>
745   error_code(E _e, typename enable_if_c<
746                      is_error_code_enum<E>::value
747                    >::type* = 0) {
748     *this = make_error_code(_e);
749   }
750 
751   void assign(int _val, const error_category& _cat) {
752       _val_ = _val;
753       _cat_ = &_cat;
754   }
755 
756   template <class E>
757     typename enable_if_c
758     <
759       is_error_code_enum<E>::value,
760       error_code&
761     >::type
762     operator=(E _e)
763       {*this = make_error_code(_e); return *this;}
764 
765   void clear() {
766     _val_ = 0;
767     _cat_ = &system_category();
768   }
769 
770   int value() const {return _val_;}
771 
772   const error_category& category() const {return *_cat_;}
773 
774   error_condition default_error_condition() const
775     {return _cat_->default_error_condition(_val_);}
776 
777   std::string message() const;
778 
779   typedef void (*unspecified_bool_type)();
780   static void unspecified_bool_true() {}
781 
782   operator unspecified_bool_type() const { // true if error
783     return _val_ == 0 ? 0 : unspecified_bool_true;
784   }
785 };
786 
787 inline error_code make_error_code(errc _e) {
788   return error_code(static_cast<int>(_e), generic_category());
789 }
790 
791 inline bool operator<(const error_code& _x, const error_code& _y) {
792   return _x.category() < _y.category()
793       || (_x.category() == _y.category() && _x.value() < _y.value());
794 }
795 
796 inline bool operator==(const error_code& _x, const error_code& _y) {
797   return _x.category() == _y.category() && _x.value() == _y.value();
798 }
799 
800 inline bool operator==(const error_code& _x, const error_condition& _y) {
801   return _x.category().equivalent(_x.value(), _y)
802       || _y.category().equivalent(_x, _y.value());
803 }
804 
805 inline bool operator==(const error_condition& _x, const error_code& _y) {
806   return _y == _x;
807 }
808 
809 inline bool operator==(const error_condition& _x, const error_condition& _y) {
810    return _x.category() == _y.category() && _x.value() == _y.value();
811 }
812 
813 inline bool operator!=(const error_code& _x, const error_code& _y) {
814   return !(_x == _y);
815 }
816 
817 inline bool operator!=(const error_code& _x, const error_condition& _y) {
818   return !(_x == _y);
819 }
820 
821 inline bool operator!=(const error_condition& _x, const error_code& _y) {
822   return !(_x == _y);
823 }
824 
825 inline bool operator!=(const error_condition& _x, const error_condition& _y) {
826   return !(_x == _y);
827 }
828 
829 // Windows errors.
830 
831 //  To construct an error_code after an API error:
832 //
833 //      error_code( ::GetLastError(), system_category() )
834 struct windows_error {
835 enum _ {
836   success = 0,
837   // These names and values are based on Windows WinError.h
838   // This is not a complete list. Add to this list if you need to explicitly
839   // check for it.
840   invalid_function        = 1, // ERROR_INVALID_FUNCTION,
841   file_not_found          = 2, // ERROR_FILE_NOT_FOUND,
842   path_not_found          = 3, // ERROR_PATH_NOT_FOUND,
843   too_many_open_files     = 4, // ERROR_TOO_MANY_OPEN_FILES,
844   access_denied           = 5, // ERROR_ACCESS_DENIED,
845   invalid_handle          = 6, // ERROR_INVALID_HANDLE,
846   arena_trashed           = 7, // ERROR_ARENA_TRASHED,
847   not_enough_memory       = 8, // ERROR_NOT_ENOUGH_MEMORY,
848   invalid_block           = 9, // ERROR_INVALID_BLOCK,
849   bad_environment         = 10, // ERROR_BAD_ENVIRONMENT,
850   bad_format              = 11, // ERROR_BAD_FORMAT,
851   invalid_access          = 12, // ERROR_INVALID_ACCESS,
852   outofmemory             = 14, // ERROR_OUTOFMEMORY,
853   invalid_drive           = 15, // ERROR_INVALID_DRIVE,
854   current_directory       = 16, // ERROR_CURRENT_DIRECTORY,
855   not_same_device         = 17, // ERROR_NOT_SAME_DEVICE,
856   no_more_files           = 18, // ERROR_NO_MORE_FILES,
857   write_protect           = 19, // ERROR_WRITE_PROTECT,
858   bad_unit                = 20, // ERROR_BAD_UNIT,
859   not_ready               = 21, // ERROR_NOT_READY,
860   bad_command             = 22, // ERROR_BAD_COMMAND,
861   crc                     = 23, // ERROR_CRC,
862   bad_length              = 24, // ERROR_BAD_LENGTH,
863   seek                    = 25, // ERROR_SEEK,
864   not_dos_disk            = 26, // ERROR_NOT_DOS_DISK,
865   sector_not_found        = 27, // ERROR_SECTOR_NOT_FOUND,
866   out_of_paper            = 28, // ERROR_OUT_OF_PAPER,
867   write_fault             = 29, // ERROR_WRITE_FAULT,
868   read_fault              = 30, // ERROR_READ_FAULT,
869   gen_failure             = 31, // ERROR_GEN_FAILURE,
870   sharing_violation       = 32, // ERROR_SHARING_VIOLATION,
871   lock_violation          = 33, // ERROR_LOCK_VIOLATION,
872   wrong_disk              = 34, // ERROR_WRONG_DISK,
873   sharing_buffer_exceeded = 36, // ERROR_SHARING_BUFFER_EXCEEDED,
874   handle_eof              = 38, // ERROR_HANDLE_EOF,
875   handle_disk_full        = 39, // ERROR_HANDLE_DISK_FULL,
876   rem_not_list            = 51, // ERROR_REM_NOT_LIST,
877   dup_name                = 52, // ERROR_DUP_NAME,
878   bad_net_path            = 53, // ERROR_BAD_NETPATH,
879   network_busy            = 54, // ERROR_NETWORK_BUSY,
880   file_exists             = 80, // ERROR_FILE_EXISTS,
881   cannot_make             = 82, // ERROR_CANNOT_MAKE,
882   broken_pipe             = 109, // ERROR_BROKEN_PIPE,
883   open_failed             = 110, // ERROR_OPEN_FAILED,
884   buffer_overflow         = 111, // ERROR_BUFFER_OVERFLOW,
885   disk_full               = 112, // ERROR_DISK_FULL,
886   insufficient_buffer     = 122, // ERROR_INSUFFICIENT_BUFFER,
887   lock_failed             = 167, // ERROR_LOCK_FAILED,
888   busy                    = 170, // ERROR_BUSY,
889   cancel_violation        = 173, // ERROR_CANCEL_VIOLATION,
890   already_exists          = 183  // ERROR_ALREADY_EXISTS
891 };
892   _ v_;
893 
894   windows_error(_ v) : v_(v) {}
895   explicit windows_error(int v) : v_(_(v)) {}
896   operator int() const {return v_;}
897 };
898 
899 
900 template <> struct is_error_code_enum<windows_error> : true_type { };
901 
902 template <> struct is_error_code_enum<windows_error::_> : true_type { };
903 
904 inline error_code make_error_code(windows_error e) {
905   return error_code(static_cast<int>(e), system_category());
906 }
907 
908 } // end namespace llvm
909 
910 #endif
911