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