[cfe-commits] [PATCH] [libc++] make errno saving more resilient to types
Howard Hinnant
hhinnant at apple.com
Tue Jan 22 09:28:04 PST 2013
On Jan 22, 2013, at 10:46 AM, Saleem Abdulrasool <compnerd at compnerd.org> wrote:
> Updated to use the remove_reference. decltype(errno) is a reference to an int (int&) [with possible qualifiers e.g. volatile]. Use std::remove_reference when using decltype to ensure that the variable is able to actually hold the value rather than a reference to the value.
>
> http://llvm-reviews.chandlerc.com/D318
>
> CHANGE SINCE LAST DIFF
> http://llvm-reviews.chandlerc.com/D318?vs=739&id=744#toc
>
> Files:
> include/locale
> src/string.cpp
>
> Index: include/locale
> ===================================================================
> --- include/locale
> +++ include/locale
> @@ -830,11 +830,11 @@
> {
> if (__a != __a_end)
> {
> - int __save_errno = errno;
> + typename _VSTD::remove_reference<decltype(errno)>::type __save_errno = errno;
> errno = 0;
> char *__p2;
> long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
> - int __current_errno = errno;
> + typename _VSTD::remove_reference<decltype(errno)>::type __current_errno = errno;
> if (__current_errno == 0)
> errno = __save_errno;
> if (__p2 != __a_end)
> @@ -870,11 +870,11 @@
> __err = ios_base::failbit;
> return 0;
> }
> - int __save_errno = errno;
> + typename _VSTD::remove_reference<decltype(errno)>::type __save_errno = errno;
> errno = 0;
> char *__p2;
> unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
> - int __current_errno = errno;
> + typename _VSTD::remove_reference<decltype(errno)>::type __current_errno = errno;
> if (__current_errno == 0)
> errno = __save_errno;
> if (__p2 != __a_end)
> Index: src/string.cpp
> ===================================================================
> --- src/string.cpp
> +++ src/string.cpp
> @@ -31,7 +31,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long r = strtol(p, &ptr, base);
> swap(errno, errno_save);
> @@ -52,7 +52,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long r = wcstol(p, &ptr, base);
> swap(errno, errno_save);
> @@ -73,7 +73,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long r = strtol(p, &ptr, base);
> swap(errno, errno_save);
> @@ -93,7 +93,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long r = wcstol(p, &ptr, base);
> swap(errno, errno_save);
> @@ -113,7 +113,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> unsigned long r = strtoul(p, &ptr, base);
> swap(errno, errno_save);
> @@ -133,7 +133,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> unsigned long r = wcstoul(p, &ptr, base);
> swap(errno, errno_save);
> @@ -153,7 +153,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long long r = strtoll(p, &ptr, base);
> swap(errno, errno_save);
> @@ -173,7 +173,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long long r = wcstoll(p, &ptr, base);
> swap(errno, errno_save);
> @@ -193,7 +193,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> unsigned long long r = strtoull(p, &ptr, base);
> swap(errno, errno_save);
> @@ -213,7 +213,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> unsigned long long r = wcstoull(p, &ptr, base);
> swap(errno, errno_save);
> @@ -233,7 +233,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> float r = strtof(p, &ptr);
> swap(errno, errno_save);
> @@ -253,7 +253,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> float r = wcstof(p, &ptr);
> swap(errno, errno_save);
> @@ -273,7 +273,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> double r = strtod(p, &ptr);
> swap(errno, errno_save);
> @@ -293,7 +293,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> double r = wcstod(p, &ptr);
> swap(errno, errno_save);
> @@ -313,7 +313,7 @@
> {
> char* ptr;
> const char* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long double r = strtold(p, &ptr);
> swap(errno, errno_save);
> @@ -333,7 +333,7 @@
> {
> wchar_t* ptr;
> const wchar_t* const p = str.c_str();
> - int errno_save = errno;
> + typename remove_reference<decltype(errno)>::type errno_save = errno;
> errno = 0;
> long double r = wcstold(p, &ptr);
> swap(errno, errno_save);
> <D318.2.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
Committed revision 173172.
Howard
More information about the cfe-commits
mailing list