Quash a whole bunch of warnings

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@145624 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__bit_reference b/include/__bit_reference
index 2688b5e..906b9da 100644
--- a/include/__bit_reference
+++ b/include/__bit_reference
@@ -637,7 +637,7 @@
         {
             __m = ~__storage_type(0) << (__bits_per_word - __n);
             __storage_type __b = *--__last.__seg_ & __m;
-            unsigned __clz_r = __bits_per_word - __result.__ctz_;
+            __clz_r = __bits_per_word - __result.__ctz_;
             __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__result.__ctz_));
             __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
             *__result.__seg_ &= ~__m;
@@ -881,7 +881,6 @@
     typedef __bit_iterator<_Cp, false> _I1;
     typedef  typename _I1::difference_type difference_type;
     typedef typename _I1::__storage_type __storage_type;
-    static const unsigned __bits_per_word = _I1::__bits_per_word;
     difference_type __d1 = __middle - __first;
     difference_type __d2 = __last - __middle;
     _I1 __r = __first + __d2;
diff --git a/include/__functional_base b/include/__functional_base
index 2ec3e49..ed7d21b 100644
--- a/include/__functional_base
+++ b/include/__functional_base
@@ -411,13 +411,13 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 
-template <class _Tp> void ref(const _Tp&& __t) = delete;
-template <class _Tp> void cref(const _Tp&& __t) = delete;
+template <class _Tp> void ref(const _Tp&&) = delete;
+template <class _Tp> void cref(const _Tp&&) = delete;
 
 #else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 
-template <class _Tp> void ref(const _Tp&& __t);// = delete;
-template <class _Tp> void cref(const _Tp&& __t);// = delete;
+template <class _Tp> void ref(const _Tp&&);// = delete;
+template <class _Tp> void cref(const _Tp&&);// = delete;
 
 #endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 
diff --git a/include/__hash_table b/include/__hash_table
index 23f4bd3..a4c29f1 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -723,7 +723,7 @@
              __node_traits::propagate_on_container_copy_assignment::value>());}
     void __copy_assign_alloc(const __hash_table& __u, true_type);
     _LIBCPP_INLINE_VISIBILITY
-        void __copy_assign_alloc(const __hash_table& __u, false_type) {}
+        void __copy_assign_alloc(const __hash_table&, false_type) {}
 
     void __move_assign(__hash_table& __u, false_type);
     void __move_assign(__hash_table& __u, true_type)
@@ -782,7 +782,7 @@
     _LIBCPP_INLINE_VISIBILITY
     static
     void
-    __swap_alloc(_Ap& __x, _Ap& __y, false_type) _NOEXCEPT {}
+    __swap_alloc(_Ap&, _Ap&, false_type) _NOEXCEPT {}
 
     void __deallocate(__node_pointer __np) _NOEXCEPT;
     __node_pointer __detach() _NOEXCEPT;
diff --git a/include/__locale b/include/__locale
index bb1fb1b..54afdf9 100644
--- a/include/__locale
+++ b/include/__locale
@@ -240,7 +240,7 @@
     const size_t __mask = size_t(0xF) << (__sr + 4);
     for(const char_type* __p = __lo; __p != __hi; ++__p)
     {
-        __h = (__h << 4) + *__p;
+        __h = (__h << 4) + static_cast<size_t>(*__p);
         size_t __g = __h & __mask;
         __h ^= __g | (__g >> __sr);
     }
@@ -485,14 +485,14 @@
     _LIBCPP_ALWAYS_INLINE
     bool is(mask __m, char_type __c) const
     {
-        return isascii(__c) ? __tab_[__c] & __m : false;
+        return isascii(__c) ? __tab_[static_cast<int>(__c)] & __m : false;
     }
 
     _LIBCPP_ALWAYS_INLINE
     const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
     {
         for (; __low != __high; ++__low, ++__vec)
-            *__vec = isascii(*__low) ? __tab_[*__low] : 0;
+            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
         return __low;
     }
 
@@ -500,7 +500,7 @@
     const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
     {
         for (; __low != __high; ++__low)
-            if (isascii(*__low) && (__tab_[*__low] & __m))
+            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
                 break;
         return __low;
     }
@@ -509,7 +509,7 @@
     const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
     {
         for (; __low != __high; ++__low)
-            if (!(isascii(*__low) && (__tab_[*__low] & __m)))
+            if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
                 break;
         return __low;
     }
diff --git a/include/__split_buffer b/include/__split_buffer
index b63a6c7..f28a6e5 100644
--- a/include/__split_buffer
+++ b/include/__split_buffer
@@ -152,7 +152,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__split_buffer& __c, false_type) _NOEXCEPT
+    void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
         {}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -171,7 +171,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, false_type) _NOEXCEPT
+    static void __swap_alloc(__alloc_rr&, __alloc_rr&, false_type) _NOEXCEPT
         {}
 };
 
@@ -490,7 +490,7 @@
         }
         else
         {
-            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
             __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
             __t.__construct_at_end(move_iterator<pointer>(__begin_),
                                    move_iterator<pointer>(__end_));
@@ -521,7 +521,7 @@
         }
         else
         {
-            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
             __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
             __t.__construct_at_end(move_iterator<pointer>(__begin_),
                                    move_iterator<pointer>(__end_));
@@ -554,7 +554,7 @@
         }
         else
         {
-            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
             __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
             __t.__construct_at_end(move_iterator<pointer>(__begin_),
                                    move_iterator<pointer>(__end_));
@@ -585,7 +585,7 @@
         }
         else
         {
-            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
             __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
             __t.__construct_at_end(move_iterator<pointer>(__begin_),
                                    move_iterator<pointer>(__end_));
@@ -618,7 +618,7 @@
         }
         else
         {
-            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
             __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
             __t.__construct_at_end(move_iterator<pointer>(__begin_),
                                    move_iterator<pointer>(__end_));
diff --git a/include/__std_stream b/include/__std_stream
index 7fe34d4..e562e2c 100644
--- a/include/__std_stream
+++ b/include/__std_stream
@@ -25,7 +25,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-static const unsigned __limit = 8;
+static const int __limit = 8;
 
 // __stdinbuf
 
@@ -104,7 +104,7 @@
     int __nread = _VSTD::max(1, __encoding_);
     for (int __i = 0; __i < __nread; ++__i)
     {
-        char __c = getc(__file_);
+        int __c = getc(__file_);
         if (__c == EOF)
             return traits_type::eof();
         __extbuf[__i] = static_cast<char>(__c);
@@ -131,7 +131,7 @@
                 if (__nread == sizeof(__extbuf))
                     return traits_type::eof();
                 {
-                    char __c = getc(__file_);
+                    int __c = getc(__file_);
                     if (__c == EOF)
                         return traits_type::eof();
                     __extbuf[__nread] = static_cast<char>(__c);
@@ -268,7 +268,7 @@
                     if (__r == codecvt_base::partial)
                     {
                         this->setp((char_type*)__e, this->pptr());
-                        this->pbump(this->epptr() - this->pbase());
+                        this->pbump(static_cast<int>(this->epptr() - this->pbase()));
                     }
                 }
                 else
diff --git a/include/__tuple b/include/__tuple
index 15193b4..3b2be1c 100644
--- a/include/__tuple
+++ b/include/__tuple
@@ -65,7 +65,7 @@
 };
 
 template <class ..._Tp> class _LIBCPP_VISIBLE tuple;
-template <class _T1, class _T2> class _LIBCPP_VISIBLE pair;
+template <class _T1, class _T2> struct _LIBCPP_VISIBLE pair;
 template <class _Tp, size_t _Size> struct _LIBCPP_VISIBLE array;
 
 template <class _Tp> struct __tuple_like : false_type {};
diff --git a/include/algorithm b/include/algorithm
index 7c250a9..4679845 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -697,14 +697,48 @@
 #endif  // _LIBCPP_DEBUG2
 
 // Precondition:  __x != 0
-inline _LIBCPP_INLINE_VISIBILITY unsigned           __ctz(unsigned           __x) {return __builtin_ctz  (__x);}
-inline _LIBCPP_INLINE_VISIBILITY unsigned      long __ctz(unsigned      long __x) {return __builtin_ctzl (__x);}
-inline _LIBCPP_INLINE_VISIBILITY unsigned long long __ctz(unsigned long long __x) {return __builtin_ctzll(__x);}
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned
+__ctz(unsigned __x)
+{
+    return static_cast<unsigned>(__builtin_ctz(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__ctz(unsigned long __x)
+{
+    return static_cast<unsigned long>(__builtin_ctzl(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+__ctz(unsigned long long __x)
+{
+    return static_cast<unsigned long long>(__builtin_ctzll(__x));
+}
 
 // Precondition:  __x != 0
-inline _LIBCPP_INLINE_VISIBILITY unsigned           __clz(unsigned           __x) {return __builtin_clz  (__x);}
-inline _LIBCPP_INLINE_VISIBILITY unsigned      long __clz(unsigned      long __x) {return __builtin_clzl (__x);}
-inline _LIBCPP_INLINE_VISIBILITY unsigned long long __clz(unsigned long long __x) {return __builtin_clzll(__x);}
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned
+__clz(unsigned __x)
+{
+    return static_cast<unsigned>(__builtin_clz(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__clz(unsigned long __x)
+{
+    return static_cast<unsigned long>(__builtin_clzl (__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+__clz(unsigned long long __x)
+{
+    return static_cast<unsigned long long>(__builtin_clzll(__x));
+}
 
 inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned           __x) {return __builtin_popcount  (__x);}
 inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned      long __x) {return __builtin_popcountl (__x);}
@@ -2678,8 +2712,8 @@
 
     result_type operator()();
 
-    static const/*expr*/ result_type min() {return _Min;}
-    static const/*expr*/ result_type max() {return _Max;}
+    static constexpr result_type min() {return _Min;}
+    static constexpr result_type max() {return _Max;}
 
     friend __rs_default __rs_get();
 };
@@ -3721,7 +3755,7 @@
 extern template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
 #ifdef _MSC_VER
 #pragma warning( pop )
-#endif _MSC_VER
+#endif  // _MSC_VER
 
 // lower_bound
 
diff --git a/include/bitset b/include/bitset
index 37f9fee..6e12e5c 100644
--- a/include/bitset
+++ b/include/bitset
@@ -213,7 +213,7 @@
 
 template <size_t _N_words, size_t _Size>
 void
-__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type)
+__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
 {
     __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
     for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word)
@@ -226,7 +226,7 @@
 template <size_t _N_words, size_t _Size>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type)
+__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
 {
     __first_[0] = __v;
     _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
@@ -560,7 +560,7 @@
     friend class __bit_const_reference<__bitset>;
     friend class __bit_iterator<__bitset, false>;
     friend class __bit_iterator<__bitset, true>;
-    friend class __bit_array<__bitset>;
+    friend struct __bit_array<__bitset>;
 
     typedef __bit_reference<__bitset>                  reference;
     typedef __bit_const_reference<__bitset>            const_reference;
@@ -574,9 +574,9 @@
         {return reference(0, 1);}
     _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t) const _NOEXCEPT
         {return const_reference(0, 1);}
-    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
         {return iterator(0, 0);}
-    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
         {return const_iterator(0, 0);}
 
     _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
diff --git a/include/cmath b/include/cmath
index ab67112..f0b985c 100644
--- a/include/cmath
+++ b/include/cmath
@@ -1600,7 +1600,7 @@
 using ::asinhl;
 using ::atanhl;
 using ::cbrtl;
-#endif !_MSC_VER
+#endif  // !_MSC_VER
 using ::copysignl;
 #ifndef _MSC_VER
 using ::erfl;
diff --git a/include/deque b/include/deque
index 27bc33e..e65acfc 100644
--- a/include/deque
+++ b/include/deque
@@ -988,7 +988,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__deque_base& __c, false_type) _NOEXCEPT
+    void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
         {}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1007,7 +1007,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
+    static void __swap_alloc(allocator_type&, allocator_type&, false_type)
         _NOEXCEPT
         {}
 };
@@ -1403,7 +1403,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const deque& __c, false_type)
+    void __copy_assign_alloc(const deque&, false_type)
         {}
 
     void __move_assign(deque& __c, true_type)
diff --git a/include/exception b/include/exception
index ae78f89..dcef3e5 100644
--- a/include/exception
+++ b/include/exception
@@ -239,7 +239,7 @@
 template <class _Ep>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-rethrow_if_nested(const _Ep& __e, typename enable_if<
+rethrow_if_nested(const _Ep&, typename enable_if<
                                    !is_polymorphic<_Ep>::value
                                                    >::type* = 0)
 {
diff --git a/include/functional b/include/functional
index 1ade26f..17a36cc 100644
--- a/include/functional
+++ b/include/functional
@@ -1573,7 +1573,7 @@
     !__is_reference_wrapper<_Ti>::value,
     _Ti&
 >::type
-__mu(_Ti& __ti, _Uj& __uj)
+__mu(_Ti& __ti, _Uj&)
 {
     return __ti;
 }
diff --git a/include/istream b/include/istream
index 7b37e34..c220532 100644
--- a/include/istream
+++ b/include/istream
@@ -1145,7 +1145,7 @@
                     }
                     ++__gc_;
                     char_type __ch = traits_type::to_char_type(__i);
-                    if (traits_type::eq(__ch, __dlm))
+                    if (traits_type::eq(__ch, static_cast<char_type>(__dlm)))
                         break;
                 }
             }
@@ -1161,7 +1161,7 @@
                     }
                     ++__gc_;
                     char_type __ch = traits_type::to_char_type(__i);
-                    if (traits_type::eq(__ch, __dlm))
+                    if (traits_type::eq(__ch, static_cast<char_type>(__dlm)))
                         break;
                 }
             }
@@ -1212,7 +1212,6 @@
         sentry __sen(*this, true);
         if (__sen)
         {
-            ios_base::iostate __err = ios_base::goodbit;
             for (; __gc_ < __n; ++__gc_)
             {
                 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
diff --git a/include/iterator b/include/iterator
index e17137f..75fee4b 100644
--- a/include/iterator
+++ b/include/iterator
@@ -823,7 +823,8 @@
     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) throw()
         : __sbuf_(__p.__sbuf_) {}
 
-    _LIBCPP_INLINE_VISIBILITY _CharT     operator*() const {return __sbuf_->sgetc();}
+    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
+        {return static_cast<char_type>(__sbuf_->sgetc());}
     _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
         {
diff --git a/include/locale b/include/locale
index 5dc3ff2..a81a63a 100644
--- a/include/locale
+++ b/include/locale
@@ -433,7 +433,7 @@
                bool __case_sensitive = true)
 {
     typedef typename iterator_traits<_InputIterator>::value_type _CharT;
-    size_t __nkw = _VSTD::distance(__kb, __ke);
+    size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke));
     const unsigned char __doesnt_match = '\0';
     const unsigned char __might_match = '\1';
     const unsigned char __does_match = '\2';
@@ -598,7 +598,7 @@
         __dc = 0;
         return 0;
     }
-    if (__ct == __thousands_sep && __grouping.size() != 0)
+    if (__grouping.size() != 0 && __ct == __thousands_sep)
     {
         if (__g_end-__g < __num_get_buf_sz)
         {
@@ -681,8 +681,8 @@
     return 0;
 }
 
-extern template class __num_get<char>;
-extern template class __num_get<wchar_t>;
+extern template struct __num_get<char>;
+extern template struct __num_get<wchar_t>;
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
 class _LIBCPP_VISIBLE num_get
@@ -1275,7 +1275,7 @@
     int __base = 16;
     // Stage 2
     char_type __atoms[26];
-    char_type __thousands_sep;
+    char_type __thousands_sep = 0;
     string __grouping;
     use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
                                                     __num_get_base::__src + 26, __atoms);
@@ -1453,8 +1453,8 @@
         __op = __ob + (__np - __nb);
 }
 
-extern template class __num_put<char>;
-extern template class __num_put<wchar_t>;
+extern template struct __num_put<char>;
+extern template struct __num_put<wchar_t>;
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
 class _LIBCPP_VISIBLE num_put
@@ -1766,7 +1766,7 @@
     unique_ptr<char_type, void(*)(void*)> __obh(0, free);
     if (__nb != __nar)
     {
-        __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+        __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
         if (__ob == 0)
             __throw_bad_alloc();
         __obh.reset(__ob);
@@ -1835,7 +1835,7 @@
     unique_ptr<char_type, void(*)(void*)> __obh(0, free);
     if (__nb != __nar)
     {
-        __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+        __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
         if (__ob == 0)
             __throw_bad_alloc();
         __obh.reset(__ob);
@@ -2102,7 +2102,7 @@
 {
     // Note:  ignoring case comes from the POSIX strptime spec
     const string_type* __wk = this->__weeks();
-    int __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
+    ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
     if (__i < 14)
         __w = __i % 7;
 }
@@ -2116,7 +2116,7 @@
 {
     // Note:  ignoring case comes from the POSIX strptime spec
     const string_type* __month = this->__months();
-    int __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
+    ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
     if (__i < 24)
         __m = __i % 12;
 }
@@ -2288,7 +2288,7 @@
         __err |= ios_base::failbit;
         return;
     }
-    int __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
+    ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
     if (__i == 0 && __h == 12)
         __h = 0;
     else if (__i == 1 && __h < 12)
@@ -2397,7 +2397,6 @@
                                               ios_base::iostate& __err,
                                               tm* __tm) const
 {
-    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
     const string_type& __fmt = this->__x();
     return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
 }
@@ -2460,8 +2459,8 @@
         break;
     case 'c':
         {
-        const string_type& __fmt = this->__c();
-        __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+        const string_type& __fm = this->__c();
+        __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
         }
         break;
     case 'd':
@@ -2470,14 +2469,14 @@
         break;
     case 'D':
         {
-        const char_type __fmt[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
-        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
+        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
         }
         break;
     case 'F':
         {
-        const char_type __fmt[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
-        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
+        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
         }
         break;
     case 'H':
@@ -2504,14 +2503,14 @@
         break;
     case 'r':
         {
-        const char_type __fmt[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
-        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
+        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
         }
         break;
     case 'R':
         {
-        const char_type __fmt[] = {'%', 'H', ':', '%', 'M'};
-        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
+        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
         }
         break;
     case 'S':
@@ -2519,8 +2518,8 @@
         break;
     case 'T':
         {
-        const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
-        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
+        __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
         }
         break;
     case 'w':
@@ -2530,8 +2529,8 @@
         return do_get_date(__b, __e, __iob, __err, __tm);
     case 'X':
         {
-        const string_type& __fmt = this->__X();
-        __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+        const string_type& __fm = this->__X();
+        __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
         }
         break;
     case 'y':
@@ -2734,7 +2733,7 @@
 
 template <class _CharT, class _OutputIterator>
 _OutputIterator
-time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
                                           char_type, const tm* __tm,
                                           char __fmt, char __mod) const
 {
@@ -3011,10 +3010,10 @@
 __double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
 {
     bool __owns = __b.get_deleter() != __do_nothing;
-    size_t __cur_cap = (__e-__b.get()) * sizeof(_Tp);
+    size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp);
     size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
                        2 * __cur_cap : numeric_limits<size_t>::max();
-    size_t __n_off = __n - __b.get();
+    size_t __n_off = static_cast<size_t>(__n - __b.get());
     _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap);
     if (__t == 0)
         __throw_bad_alloc();
@@ -3232,7 +3231,7 @@
                                           ios_base::iostate& __err,
                                           long double& __v) const
 {
-    const unsigned __bz = 100;
+    const int __bz = 100;
     char_type __wbuf[__bz];
     unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
     char_type* __wn;
@@ -3251,7 +3250,7 @@
         unique_ptr<char, void(*)(void*)> __h(0, free);
         if (__wn - __wb.get() > __bz-2)
         {
-            __h.reset((char*)malloc(__wn - __wb.get() + 2));
+            __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
             if (__h.get() == 0)
                 __throw_bad_alloc();
             __nc = __h.get();
@@ -3276,7 +3275,7 @@
                                           ios_base::iostate& __err,
                                           string_type& __v) const
 {
-    const unsigned __bz = 100;
+    const int __bz = 100;
     char_type __wbuf[__bz];
     unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
     char_type* __wn;
@@ -3536,14 +3535,14 @@
     char* __bb = __buf;
     char_type __digits[__bs];
     char_type* __db = __digits;
-    size_t __n = snprintf(__bb, __bs, "%.0Lf", __units);
+    size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units));
     unique_ptr<char, void(*)(void*)> __hn(0, free);
     unique_ptr<char_type, void(*)(void*)> __hd(0, free);
     // secure memory for digit storage
     if (__n > __bs-1)
     {
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        __n = asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
+        __n = static_cast<size_t>(asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
 #else
         __n = __asprintf_l(&__bb, __cloc(), "%.0Lf", __units);
 #endif
@@ -3573,8 +3572,9 @@
     char_type* __mb = __mbuf;
     unique_ptr<char_type, void(*)(void*)> __hw(0, free);
     size_t __exn = static_cast<int>(__n) > __fd ?
-                   (__n - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
-                 : __sn.size() + __sym.size() + __fd + 2;
+                   (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() +
+                    __sym.size() + static_cast<size_t>(__fd) + 1
+                 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
     if (__exn > __bs)
     {
         __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
@@ -3613,9 +3613,10 @@
     char_type __mbuf[100];
     char_type* __mb = __mbuf;
     unique_ptr<char_type, void(*)(void*)> __h(0, free);
-    size_t __exn = __digits.size() > __fd ?
-                   (__digits.size() - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
-                 : __sn.size() + __sym.size() + __fd + 2;
+    size_t __exn = static_cast<int>(__digits.size()) > __fd ?
+                   (__digits.size() - static_cast<size_t>(__fd)) * 2 +
+                    __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
+                 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
     if (__exn > 100)
     {
         __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
@@ -4005,9 +4006,9 @@
                 }
                 else if (__r == codecvt_base::partial)
                 {
-                    ptrdiff_t __s = __to_nxt - &__bs[0];
-                    __bs.resize(2 * __s);
-                    __to = &__bs[0] + __s;
+                    ptrdiff_t __sp = __to_nxt - &__bs[0];
+                    __bs.resize(2 * __sp);
+                    __to = &__bs[0] + __sp;
                     __to_end = &__bs[0] + __bs.size();
                 }
             } while (__r == codecvt_base::partial);
diff --git a/include/memory b/include/memory
index 7177549..e8abdbe 100644
--- a/include/memory
+++ b/include/memory
@@ -1526,7 +1526,7 @@
         {return __a.allocate(__n, __hint);}
     _LIBCPP_INLINE_VISIBILITY
     static pointer allocate(allocator_type& __a, size_type __n,
-        const_void_pointer __hint, false_type)
+        const_void_pointer, false_type)
         {return __a.allocate(__n);}
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -2181,7 +2181,7 @@
     _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
     _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
 
-    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
                    __is_nothrow_swappable<_T1>::value)
     {
@@ -3099,7 +3099,7 @@
 
     void swap(shared_ptr& __r) _NOEXCEPT;
     void reset() _NOEXCEPT;
-    template<class _Yp> void reset(_Yp* __p) _NOEXCEPT;
+    template<class _Yp> void reset(_Yp* __p);
     template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d);
     template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a);
 
diff --git a/include/mutex b/include/mutex
index 8bc6b80..62b733f 100644
--- a/include/mutex
+++ b/include/mutex
@@ -534,7 +534,7 @@
 void
 call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
 {
-    if (__builtin_expect(__flag.__state_ , ~0ul) != ~0ul)
+    if (__flag.__state_ != ~0ul)
     {
         typedef tuple<typename decay<_Callable>::type, typename decay<_Args>::type...> _Gp;
         __call_once_param<_Gp> __p(_Gp(__decay_copy(_VSTD::forward<_Callable>(__func)),
diff --git a/include/random b/include/random
index 4d83a9d..02ea9b6 100644
--- a/include/random
+++ b/include/random
@@ -1860,8 +1860,9 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit linear_congruential_engine(result_type __s = default_seed)
         {seed(__s);}
-    template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q,
+    template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
+        explicit linear_congruential_engine(_Sseq& __q,
         typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
         {seed(__q);}
     _LIBCPP_INLINE_VISIBILITY
@@ -2116,8 +2117,9 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit mersenne_twister_engine(result_type __sd = default_seed)
         {seed(__sd);}
-    template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q,
+    template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
+        explicit mersenne_twister_engine(_Sseq& __q,
         typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
         {seed(__q);}
     void seed(result_type __sd = default_seed);
@@ -2200,7 +2202,7 @@
             (__count >= __w),
             result_type
         >::type
-        __lshift(result_type __x) {return result_type(0);}
+        __lshift(result_type) {return result_type(0);}
 
     template <size_t __count>
         _LIBCPP_INLINE_VISIBILITY
@@ -2220,7 +2222,7 @@
             (__count >= _Dt),
             result_type
         >::type
-        __rshift(result_type __x) {return result_type(0);}
+        __rshift(result_type) {return result_type(0);}
 };
 
 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
@@ -2485,8 +2487,9 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit subtract_with_carry_engine(result_type __sd = default_seed)
         {seed(__sd);}
-    template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q,
+    template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
+        explicit subtract_with_carry_engine(_Sseq& __q,
         typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
         {seed(__q);}
     _LIBCPP_INLINE_VISIBILITY
@@ -2955,8 +2958,9 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
-    template<class _Sseq> explicit independent_bits_engine(_Sseq& __q,
+    template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
+        explicit independent_bits_engine(_Sseq& __q,
         typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
          : __e_(__q) {}
@@ -3033,7 +3037,7 @@
             (__count >= _Dt),
             result_type
         >::type
-        __lshift(result_type __x) {return result_type(0);}
+        __lshift(result_type) {return result_type(0);}
 };
 
 template<class _Engine, size_t __w, class _UIntType>
@@ -3178,8 +3182,9 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
-    template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q,
+    template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
+        explicit shuffle_order_engine(_Sseq& __q,
         typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
          : __e_(__q) {__init();}
@@ -3369,9 +3374,9 @@
     static const result_type _Max = 0xFFFFFFFFu;
 
     _LIBCPP_INLINE_VISIBILITY
-    static const/*expr*/ result_type min() { return _Min;}
+    static constexpr result_type min() { return _Min;}
     _LIBCPP_INLINE_VISIBILITY
-    static const/*expr*/ result_type max() { return _Max;}
+    static constexpr result_type max() { return _Max;}
 
     // constructors
     explicit random_device(const string& __token = "/dev/urandom");
diff --git a/include/regex b/include/regex
index 0774eee..2ebb0f1 100644
--- a/include/regex
+++ b/include/regex
@@ -4404,7 +4404,7 @@
             if (__hd == -1)
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
-            __sum = 16 * __sum + __hd;
+            __sum = 16 * __sum + static_cast<unsigned>(__hd);
             ++__first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
             if (__first == __last)
@@ -4415,7 +4415,7 @@
             if (__hd == -1)
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
-            __sum = 16 * __sum + __hd;
+            __sum = 16 * __sum + static_cast<unsigned>(__hd);
             // drop through
         case 'x':
             ++__first;
@@ -4428,7 +4428,7 @@
             if (__hd == -1)
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
-            __sum = 16 * __sum + __hd;
+            __sum = 16 * __sum + static_cast<unsigned>(__hd);
             ++__first;
 #ifndef _LIBCPP_NO_EXCEPTIONS
             if (__first == __last)
@@ -4439,7 +4439,7 @@
             if (__hd == -1)
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
-            __sum = 16 * __sum + __hd;
+            __sum = 16 * __sum + static_cast<unsigned>(__hd);
             if (__str)
                 *__str = _CharT(__sum);
             else
@@ -5496,8 +5496,6 @@
         regex_constants::match_flag_type __flags, bool __at_first) const
 {
     vector<__state> __states;
-    ptrdiff_t __j = 0;
-    ptrdiff_t _Np = _VSTD::distance(__first, __last);
     __node* __st = __start_.get();
     if (__st)
     {
@@ -5511,7 +5509,6 @@
         __states.back().__node_ = __st;
         __states.back().__flags_ = __flags;
         __states.back().__at_first_ = __at_first;
-        bool __matched = false;
         do
         {
             __state& __s = __states.back();
diff --git a/include/streambuf b/include/streambuf
index 5dcb597..e128be5 100644
--- a/include/streambuf
+++ b/include/streambuf
@@ -461,15 +461,15 @@
 
 template <class _CharT, class _Traits>
 typename basic_streambuf<_CharT, _Traits>::pos_type
-basic_streambuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
-                                          ios_base::openmode __which)
+basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
+                                          ios_base::openmode)
 {
     return pos_type(off_type(-1));
 }
 
 template <class _CharT, class _Traits>
 typename basic_streambuf<_CharT, _Traits>::pos_type
-basic_streambuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode __which)
+basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
 {
     return pos_type(off_type(-1));
 }
@@ -548,7 +548,7 @@
 
 template <class _CharT, class _Traits>
 typename basic_streambuf<_CharT, _Traits>::int_type
-basic_streambuf<_CharT, _Traits>::overflow(int_type __c)
+basic_streambuf<_CharT, _Traits>::overflow(int_type)
 {
     return traits_type::eof();
 }
diff --git a/include/string b/include/string
index 344bb55..575b9e1 100644
--- a/include/string
+++ b/include/string
@@ -1079,7 +1079,7 @@
     enum {__long_mask  = ~(size_type(~0) >> 1)};
 #else  // _LIBCPP_BIG_ENDIAN
     enum {__short_mask = 0x01};
-    enum {__long_mask  = 0x1};
+    enum {__long_mask  = 0x1ul};
 #endif  // _LIBCPP_BIG_ENDIAN
 
     enum {__mask = size_type(~0) >> 1};
@@ -1501,7 +1501,7 @@
         {__r_.first().__l.__cap_  = __long_mask | __s;}
     _LIBCPP_INLINE_VISIBILITY
     size_type __get_long_cap() const _NOEXCEPT
-        {return __r_.first().__l.__cap_ & ~__long_mask;}
+        {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_long_pointer(pointer __p) _NOEXCEPT
@@ -1591,7 +1591,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const basic_string& __str, false_type) _NOEXCEPT
+    void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
         {}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1619,7 +1619,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(basic_string& __c, false_type)
+    void __move_assign_alloc(basic_string&, false_type)
         _NOEXCEPT
         {}
 
@@ -1638,7 +1638,7 @@
             swap(__x, __y);
         }
     _LIBCPP_INLINE_VISIBILITY
-    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type) _NOEXCEPT
+    static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
         {}
 
     _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
@@ -1669,7 +1669,11 @@
 _LIBCPP_INLINE_VISIBILITY inline
 #endif
 void
-basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
+basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
+#ifdef _LIBCPP_DEBUG
+                                                                        __pos
+#endif
+                                                                      )
 {
 #ifdef _LIBCPP_DEBUG
     const_iterator __beg = begin();
@@ -2785,7 +2789,7 @@
     iterator __b = begin();
     size_type __r = static_cast<size_type>(__pos - __b);
     erase(__r, 1);
-    return __b + __r;
+    return __b + static_cast<difference_type>(__r);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2796,7 +2800,7 @@
     iterator __b = begin();
     size_type __r = static_cast<size_type>(__first - __b);
     erase(__r, static_cast<size_type>(__last - __first));
-    return __b + __r;
+    return __b + static_cast<difference_type>(__r);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3483,7 +3487,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 int
-basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const
+basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
diff --git a/include/system_error b/include/system_error
index d65b29b..c9a8097 100644
--- a/include/system_error
+++ b/include/system_error
@@ -474,7 +474,7 @@
 operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
 {
     return __x.category() < __y.category()
-        || __x.category() == __y.category() && __x.value() < __y.value();
+        || (__x.category() == __y.category() && __x.value() < __y.value());
 }
 
 // error_code
@@ -551,7 +551,7 @@
 operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
 {
     return __x.category() < __y.category()
-        || __x.category() == __y.category() && __x.value() < __y.value();
+        || (__x.category() == __y.category() && __x.value() < __y.value());
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
diff --git a/include/tuple b/include/tuple
index 190567d..d0f832e 100644
--- a/include/tuple
+++ b/include/tuple
@@ -195,13 +195,13 @@
         explicit __tuple_leaf(_Tp&& __t)
             : value(_VSTD::forward<_Tp>(__t))
         {static_assert(!is_reference<_Hp>::value ||
-                        is_lvalue_reference<_Hp>::value &&
+                       (is_lvalue_reference<_Hp>::value &&
                         (is_lvalue_reference<_Tp>::value ||
                          is_same<typename remove_reference<_Tp>::type,
                                  reference_wrapper<
                                     typename remove_reference<_Hp>::type
                                  >
-                                >::value) ||
+                                >::value)) ||
                         (is_rvalue_reference<_Hp>::value &&
                          !is_lvalue_reference<_Tp>::value),
        "Attempted to construct a reference element in a tuple with an rvalue");}
@@ -211,13 +211,13 @@
         explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
             : value(_VSTD::forward<_Tp>(__t))
         {static_assert(!is_lvalue_reference<_Hp>::value ||
-                        is_lvalue_reference<_Hp>::value &&
+                       (is_lvalue_reference<_Hp>::value &&
                         (is_lvalue_reference<_Tp>::value ||
                          is_same<typename remove_reference<_Tp>::type,
                                  reference_wrapper<
                                     typename remove_reference<_Hp>::type
                                  >
-                                >::value),
+                                >::value)),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
     template <class _Tp, class _Alloc>
@@ -225,13 +225,13 @@
         explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
             : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
         {static_assert(!is_lvalue_reference<_Hp>::value ||
-                        is_lvalue_reference<_Hp>::value &&
+                       (is_lvalue_reference<_Hp>::value &&
                         (is_lvalue_reference<_Tp>::value ||
                          is_same<typename remove_reference<_Tp>::type,
                                  reference_wrapper<
                                     typename remove_reference<_Hp>::type
                                  >
-                                >::value),
+                                >::value)),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
     template <class _Tp, class _Alloc>
@@ -239,13 +239,13 @@
         explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
             : value(_VSTD::forward<_Tp>(__t), __a)
         {static_assert(!is_lvalue_reference<_Hp>::value ||
-                        is_lvalue_reference<_Hp>::value &&
+                       (is_lvalue_reference<_Hp>::value &&
                         (is_lvalue_reference<_Tp>::value ||
                          is_same<typename remove_reference<_Tp>::type,
                                  reference_wrapper<
                                     typename remove_reference<_Hp>::type
                                  >
-                                >::value),
+                                >::value)),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
     __tuple_leaf(const __tuple_leaf& __t)
@@ -453,11 +453,11 @@
     base base_;
 
     template <size_t _Jp, class ..._Up> friend
-        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&);
+        typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
     template <size_t _Jp, class ..._Up> friend
-        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&);
+        const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
     template <size_t _Jp, class ..._Up> friend
-        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&);
+        typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
 public:
 
     _LIBCPP_INLINE_VISIBILITY
@@ -603,7 +603,7 @@
 template <size_t _Ip, class ..._Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, tuple<_Tp...> >::type&
-get(tuple<_Tp...>& __t)
+get(tuple<_Tp...>& __t) _NOEXCEPT
 {
     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
@@ -612,7 +612,7 @@
 template <size_t _Ip, class ..._Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
-get(const tuple<_Tp...>& __t)
+get(const tuple<_Tp...>& __t) _NOEXCEPT
 {
     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
@@ -621,7 +621,7 @@
 template <size_t _Ip, class ..._Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
-get(tuple<_Tp...>&& __t)
+get(tuple<_Tp...>&& __t) _NOEXCEPT
 {
     typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
     return static_cast<type&&>(
diff --git a/include/valarray b/include/valarray
index fff3ce1..3c0422a 100644
--- a/include/valarray
+++ b/include/valarray
@@ -708,7 +708,7 @@
     _LIBCPP_INLINE_VISIBILITY
     result_type operator[](size_t __j) const
         {
-            ptrdiff_t __i = static_cast<size_t>(__j);
+            ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
             ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
             return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
         }
@@ -959,7 +959,7 @@
     void swap(valarray& __v);
 
     _LIBCPP_INLINE_VISIBILITY
-    size_t size() const {return __end_ - __begin_;}
+    size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
 
     value_type sum() const;
     value_type min() const;
@@ -1897,7 +1897,7 @@
     _LIBCPP_INLINE_VISIBILITY
     mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
         : __vp_(const_cast<value_type*>(__v.__begin_)),
-          __1d_(count(__vb.__begin_, __vb.__end_, true))
+          __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
           {
               size_t __j = 0;
               for (size_t __i = 0; __i < __vb.size(); ++__i)
@@ -2108,7 +2108,7 @@
     _LIBCPP_INLINE_VISIBILITY
     __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
         : __expr_(__e),
-          __1d_(count(__vb.__begin_, __vb.__end_, true))
+          __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
           {
               size_t __j = 0;
               for (size_t __i = 0; __i < __vb.size(); ++__i)
diff --git a/include/vector b/include/vector
index 1fb6f59..9d5c23c 100644
--- a/include/vector
+++ b/include/vector
@@ -406,7 +406,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const __vector_base& __c, false_type)
+    void __copy_assign_alloc(const __vector_base&, false_type)
         {}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -417,7 +417,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(__vector_base& __c, false_type)
+    void __move_assign_alloc(__vector_base&, false_type)
         _NOEXCEPT
         {}
 
@@ -429,7 +429,7 @@
             swap(__x, __y);
         }
     _LIBCPP_INLINE_VISIBILITY
-    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
+    static void __swap_alloc(allocator_type&, allocator_type&, false_type)
         _NOEXCEPT
         {}
 };
@@ -2241,7 +2241,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __copy_assign_alloc(const vector& __c, false_type)
+    void __copy_assign_alloc(const vector&, false_type)
         {}
 
     void __move_assign(vector& __c, false_type);
@@ -2262,7 +2262,7 @@
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign_alloc(vector& __c, false_type)
+    void __move_assign_alloc(vector&, false_type)
         _NOEXCEPT
         {}
 
@@ -2282,7 +2282,7 @@
             swap(__x, __y);
         }
     _LIBCPP_INLINE_VISIBILITY
-    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
+    static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
         _NOEXCEPT
         {}