Add explicit casts to unsigned char before calling ctype functions.
Fixes the value range on platforms with signed char.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@180940 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/locale.cpp b/src/locale.cpp
index 49c1cf2..c740a51 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -1068,28 +1068,28 @@
 char
 ctype_byname<char>::do_toupper(char_type c) const
 {
-    return static_cast<char>(toupper_l(c, __l));
+    return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
 }
 
 const char*
 ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
 {
     for (; low != high; ++low)
-        *low = static_cast<char>(toupper_l(*low, __l));
+        *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
     return low;
 }
 
 char
 ctype_byname<char>::do_tolower(char_type c) const
 {
-    return static_cast<char>(tolower_l(c, __l));
+    return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
 }
 
 const char*
 ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
 {
     for (; low != high; ++low)
-        *low = static_cast<char>(tolower_l(*low, __l));
+        *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
     return low;
 }
 
diff --git a/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp b/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp
index f97944e..9714979 100644
--- a/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp
+++ b/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_1.pass.cpp
@@ -32,7 +32,7 @@
             assert(f.tolower('.') == '.');
             assert(f.tolower('a') == 'a');
             assert(f.tolower('1') == '1');
-            assert(f.tolower('\xDA') == '\xDA');
+            assert(f.tolower('\xDA') == '\xFA');
             assert(f.tolower('\xFA') == '\xFA');
         }
     }
diff --git a/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp b/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
index 4543c93..aa2736d 100644
--- a/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
+++ b/test/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
@@ -29,7 +29,7 @@
             std::string in("\xDA A\x07.a1");
 
             assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
-            assert(in[0] == '\xDA');
+            assert(in[0] == '\xFA');
             assert(in[1] == ' ');
             assert(in[2] == 'a');
             assert(in[3] == '\x07');
diff --git a/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp b/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp
index 7548b33..e7503ae 100644
--- a/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp
+++ b/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_1.pass.cpp
@@ -33,7 +33,7 @@
             assert(f.toupper('a') == 'A');
             assert(f.toupper('1') == '1');
             assert(f.toupper('\xDA') == '\xDA');
-            assert(f.toupper('\xFA') == '\xFA');
+            assert(f.toupper('\xFA') == '\xDA');
         }
     }
     {
diff --git a/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp b/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp
index 95ec1ff..1aedec6 100644
--- a/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp
+++ b/test/localization/locale.categories/category.ctype/locale.ctype.byname/toupper_many.pass.cpp
@@ -29,7 +29,7 @@
             std::string in("\xFA A\x07.a1");
 
             assert(f.toupper(&in[0], in.data() + in.size()) == in.data() + in.size());
-            assert(in[0] == '\xFA');
+            assert(in[0] == '\xDA');
             assert(in[1] == ' ');
             assert(in[2] == 'A');
             assert(in[3] == '\x07');
diff --git a/test/re/re.traits/translate_nocase.pass.cpp b/test/re/re.traits/translate_nocase.pass.cpp
index 3afc336..06e987d 100644
--- a/test/re/re.traits/translate_nocase.pass.cpp
+++ b/test/re/re.traits/translate_nocase.pass.cpp
@@ -38,7 +38,7 @@
         assert(t.translate_nocase('.') == '.');
         assert(t.translate_nocase('a') == 'a');
         assert(t.translate_nocase('1') == '1');
-        assert(t.translate_nocase('\xDA') == '\xDA');
+        assert(t.translate_nocase('\xDA') == '\xFA');
         assert(t.translate_nocase('\xFA') == '\xFA');
     }
     {