[PATCH] [libc++] Linux: Correctly identify valid error codes
Justin Bogner
mail at justinbogner.com
Fri May 23 11:30:01 PDT 2014
David Majnemer <david.majnemer at gmail.com> writes:
> [syserr.errcat.objects]p4 specifies that system_category
> ().default_error_condition(ev) map to error_condition(posv, generic_category
> ()) if ev could map to a POSIX errno.
>
> Linux reserves up to and including 4095 for errno values, use this as a bound.
>
> This fixes syserr.errcat.objects/system_category.pass.cpp on Linux.
Would it be simpler to do something like
#if !defined(ELAST) && defined(__linux__)
#define ELAST 4095
#endif
at the top of the file and avoid having to change every #ifdef?
>
> diff --git a/src/ios.cpp b/src/ios.cpp
> index 03af978..e241394 100644
> --- a/src/ios.cpp
> +++ b/src/ios.cpp
> @@ -56,7 +56,9 @@ __iostream_category::message(int ev) const
> if (ev != static_cast<int>(io_errc::stream)
> #ifdef ELAST
> && ev <= ELAST
> -#endif
> +#elif defined(__linux__)
> + && ev <= 4095
> +#endif // ELAST
> )
> return __do_message::message(ev);
> return string("unspecified iostream_category error");
> diff --git a/src/system_error.cpp b/src/system_error.cpp
> index 00920ff..d5cb2d4 100644
> --- a/src/system_error.cpp
> +++ b/src/system_error.cpp
> @@ -68,6 +68,9 @@ __generic_error_category::message(int ev) const
> #ifdef ELAST
> if (ev > ELAST)
> return string("unspecified generic_category error");
> +#elif defined(__linux__)
> + if (ev > 4095)
> + return string("unspecified generic_category error");
> #endif // ELAST
> return __do_message::message(ev);
> }
> @@ -100,6 +103,9 @@ __system_error_category::message(int ev) const
> #ifdef ELAST
> if (ev > ELAST)
> return string("unspecified system_category error");
> +#elif defined(__linux__)
> + if (ev > 4095)
> + return string("unspecified system_category error");
> #endif // ELAST
> return __do_message::message(ev);
> }
> @@ -110,6 +116,9 @@ __system_error_category::default_error_condition(int ev) const _NOEXCEPT
> #ifdef ELAST
> if (ev > ELAST)
> return error_condition(ev, system_category());
> +#elif defined(__linux__)
> + if (ev > 4095)
> + return error_condition(ev, system_category());
> #endif // ELAST
> return error_condition(ev, generic_category());
> }
> diff --git a/test/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp b/test/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
> index ddcb725..b5cb18a 100644
> --- a/test/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
> +++ b/test/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
> @@ -23,7 +23,7 @@ int main()
> std::error_condition e_cond = e_cat1.default_error_condition(5);
> assert(e_cond.value() == 5);
> assert(e_cond.category() == std::generic_category());
> - e_cond = e_cat1.default_error_condition(500);
> - assert(e_cond.value() == 500);
> + e_cond = e_cat1.default_error_condition(5000);
> + assert(e_cond.value() == 5000);
> assert(e_cond.category() == std::system_category());
> }
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list