[cfe-commits] [libcxx] r173172 - in /libcxx/trunk: include/locale src/string.cpp

Howard Hinnant hhinnant at apple.com
Tue Jan 22 09:26:09 PST 2013


Author: hhinnant
Date: Tue Jan 22 11:26:08 2013
New Revision: 173172

URL: http://llvm.org/viewvc/llvm-project?rev=173172&view=rev
Log:
Saleem Abdulrasool: If errno is defined as volatile int, the qualifier differences can cause
template typename deductions on swap<> (used in string.cpp).  Use
decltype(errno) to replicate the type and qualifier information for holding the
errno value.  Because errno is expected to be assignable, there is no need to
use typename std::remove_const<decltype(errno)>::type to hold the value.

Modified:
    libcxx/trunk/include/locale
    libcxx/trunk/src/string.cpp

Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=173172&r1=173171&r2=173172&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Tue Jan 22 11:26:08 2013
@@ -830,11 +830,11 @@
 {
     if (__a != __a_end)
     {
-        int __save_errno = errno;
+        typename 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 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 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 remove_reference<decltype(errno)>::type __current_errno = errno;
         if (__current_errno == 0)
             errno = __save_errno;
         if (__p2 != __a_end)

Modified: libcxx/trunk/src/string.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/string.cpp?rev=173172&r1=173171&r2=173172&view=diff
==============================================================================
--- libcxx/trunk/src/string.cpp (original)
+++ libcxx/trunk/src/string.cpp Tue Jan 22 11:26:08 2013
@@ -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);





More information about the cfe-commits mailing list