diff --git a/emscripten-version.txt b/emscripten-version.txt
index cf1b8301402c6..28442b1906f79 100644
--- a/emscripten-version.txt
+++ b/emscripten-version.txt
@@ -1,2 +1,2 @@
-1.25.0
+1.25.1
 
diff --git a/emscripten.py b/emscripten.py
index 0ea37f706bbfc..54ea66357438c 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -1177,6 +1177,8 @@ def access_quote(prop):
       # calculate exports
       exported_implemented_functions = list(exported_implemented_functions) + metadata['initializers']
       exported_implemented_functions.append('runPostSets')
+      if settings['ALLOW_MEMORY_GROWTH']:
+        exported_implemented_functions.append('_emscripten_replace_memory')
       exports = []
       for export in exported_implemented_functions + asm_runtime_funcs + function_tables:
         exports.append(quote(export) + ": " + export)
@@ -1287,7 +1289,21 @@ def math_fix(g):
     var nan = +env.NaN, inf = +env.Infinity;
     var tempInt = 0, tempBigInt = 0, tempBigIntP = 0, tempBigIntS = 0, tempBigIntR = 0.0, tempBigIntI = 0, tempBigIntD = 0, tempValue = 0, tempDouble = 0.0;
   ''' + ''.join(['''
-    var tempRet%d = 0;''' % i for i in range(10)]) + '\n' + asm_global_funcs] + ['  var tempFloat = %s;\n' % ('Math_fround(0)' if settings.get('PRECISE_F32') else '0.0')] + (['  const f0 = Math_fround(0);\n'] if settings.get('PRECISE_F32') else []) + ['''
+    var tempRet%d = 0;''' % i for i in range(10)]) + '\n' + asm_global_funcs] + ['  var tempFloat = %s;\n' % ('Math_fround(0)' if settings.get('PRECISE_F32') else '0.0')] + (['  const f0 = Math_fround(0);\n'] if settings.get('PRECISE_F32') else []) + ['' if not settings['ALLOW_MEMORY_GROWTH'] else '''
+  function _emscripten_replace_memory(newBuffer) {
+    if ((byteLength(newBuffer) & 0xffffff || byteLength(newBuffer) <= 0xffffff)) return false;
+    HEAP8 = new Int8View(newBuffer);
+    HEAP16 = new Int16View(newBuffer);
+    HEAP32 = new Int32View(newBuffer);
+    HEAPU8 = new Uint8View(newBuffer);
+    HEAPU16 = new Uint16View(newBuffer);
+    HEAPU32 = new Uint32View(newBuffer);
+    HEAPF32 = new Float32View(newBuffer);
+    HEAPF64 = new Float64View(newBuffer);
+    buffer = newBuffer;
+    return true;
+  }
+'''] + ['''
   // EMSCRIPTEN_START_FUNCS
   function stackAlloc(size) {
     size = size|0;
diff --git a/src/library.js b/src/library.js
index 2f84b144ab40b..7b24fc98798dc 100644
--- a/src/library.js
+++ b/src/library.js
@@ -8766,6 +8766,7 @@ LibraryManager.library = {
     return cache[fullname] = allocate(intArrayFromString(ret + ''), 'i8', ALLOC_NORMAL);
   },
 
+#if RUNNING_FASTCOMP == 0
 #if ASM_JS
 #if ALLOW_MEMORY_GROWTH
   emscripten_replace_memory__asm: true, // this is used inside the asm module
@@ -8788,6 +8789,7 @@ LibraryManager.library = {
   // but should not declare itself as validating (which is prevented in ASM_JS == 2).
   {{{ (assert(ASM_JS === 2), DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('emscripten_replace_memory'), '') }}}
 #endif
+#endif
 #endif
 
   emscripten_debugger: function() {
diff --git a/system/include/libcxx/CREDITS.TXT b/system/include/libcxx/CREDITS.TXT
index 368b526fcc1b5..7a28adae09659 100644
--- a/system/include/libcxx/CREDITS.TXT
+++ b/system/include/libcxx/CREDITS.TXT
@@ -33,6 +33,10 @@ E: mclow.lists@gmail.com
 E: marshall@idio.com
 D: C++14 support, patches and bug fixes.
 
+N: Eric Fiselier
+E: eric@efcs.ca
+D: LFTS support, patches and bug fixes.
+
 N: Bill Fisher
 E: william.w.fisher@gmail.com
 D: Regex bug fixes.
diff --git a/system/include/libcxx/LICENSE.txt b/system/include/libcxx/LICENSE.TXT
similarity index 96%
rename from system/include/libcxx/LICENSE.txt
rename to system/include/libcxx/LICENSE.TXT
index 5ed8ec2248352..41ca5d19cc658 100644
--- a/system/include/libcxx/LICENSE.txt
+++ b/system/include/libcxx/LICENSE.TXT
@@ -14,7 +14,7 @@ Full text of the relevant licenses is included below.
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 
@@ -55,7 +55,7 @@ SOFTWARE.
 
 ==============================================================================
 
-Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/system/include/libcxx/__bit_reference b/system/include/libcxx/__bit_reference
index 37b7923712806..d9ebfbe5e610b 100644
--- a/system/include/libcxx/__bit_reference
+++ b/system/include/libcxx/__bit_reference
@@ -174,7 +174,7 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         if (__n == __dn)
-            return _It(__first.__seg_, __first.__ctz_ + __n);
+            return __first + __n;
         __n -= __dn;
         ++__first.__seg_;
     }
@@ -210,7 +210,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         if (__n == __dn)
-            return _It(__first.__seg_, __first.__ctz_ + __n);
+            return __first + __n;
         __n -= __dn;
         ++__first.__seg_;
     }
diff --git a/system/include/libcxx/__config b/system/include/libcxx/__config
index 45207392d0cbc..fcf82c80d2c26 100644
--- a/system/include/libcxx/__config
+++ b/system/include/libcxx/__config
@@ -19,6 +19,11 @@
 #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
 #endif
 
+#if !_WIN32
+#include <unistd.h>
+#include <errno.h>  // for ELAST on FreeBSD
+#endif
+
 #define _LIBCPP_VERSION 1101
 
 #define _LIBCPP_ABI_VERSION 1
@@ -194,7 +199,7 @@
 #endif
 
 #ifndef _LIBCPP_EXCEPTION_ABI
-#define _LIBCPP_EXCEPTION_ABI _LIBCPP_TYPE_VIS
+#define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE
@@ -203,6 +208,11 @@
 
 #if defined(__clang__)
 
+#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&        \
+    !defined(__arm__)
+#define _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif
+
 #if __has_feature(cxx_alignas)
 #  define _ALIGNAS_TYPE(x) alignas(x)
 #  define _ALIGNAS(x) alignas(x)
@@ -215,7 +225,7 @@
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 #endif
 
-#ifndef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus < 201103L
 #ifdef __linux__
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #else
@@ -308,10 +318,16 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #endif
 
+#if !(__has_feature(cxx_relaxed_constexpr))
+#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
+#endif
+
 #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
 #if defined(__FreeBSD__)
 #define _LIBCPP_HAS_QUICK_EXIT
 #define _LIBCPP_HAS_C11_FEATURES
+#elif defined(__ANDROID__)
+#define _LIBCPP_HAS_QUICK_EXIT
 #elif defined(__linux__)
 #include <features.h>
 #if __GLIBC_PREREQ(2, 15)
@@ -326,13 +342,19 @@ typedef __char32_t char32_t;
 #if (__has_feature(cxx_noexcept))
 #  define _NOEXCEPT noexcept
 #  define _NOEXCEPT_(x) noexcept(x)
+#  define _NOEXCEPT_OR_FALSE(x) noexcept(x)
 #else
 #  define _NOEXCEPT throw()
 #  define _NOEXCEPT_(x)
+#  define _NOEXCEPT_OR_FALSE(x) false
 #endif
 
 #if __has_feature(underlying_type)
-#  define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T)
+#  define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T)
+#endif
+
+#if __has_feature(is_literal)
+#  define _LIBCPP_IS_LITERAL(T) __is_literal(T)
 #endif
 
 // Inline namespaces are available in Clang regardless of C++ dialect.
@@ -345,6 +367,10 @@ namespace std {
   }
 }
 
+#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer)
+#define _LIBCPP_HAS_NO_ASAN
+#endif
+
 #elif defined(__GNUC__)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
@@ -352,15 +378,31 @@ namespace std {
 
 #define _LIBCPP_NORETURN __attribute__((noreturn))
 
+#if _GNUC_VER >= 407
+#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T)
+#define _LIBCPP_IS_LITERAL(T) __is_literal_type(T)
+#endif
+
 #if !__EXCEPTIONS
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+
+// constexpr was added to GCC in 4.6.
+#if _GNUC_VER < 406
+#define _LIBCPP_HAS_NO_CONSTEXPR
+// Can only use constexpr in c++11 mode.
+#elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
 #define _LIBCPP_HAS_NO_CONSTEXPR
+#endif
+
+// No version of GCC supports relaxed constexpr rules
+#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 
 #define _NOEXCEPT throw()
 #define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
 
 #ifndef __GXX_EXPERIMENTAL_CXX0X__
 
@@ -374,6 +416,7 @@ namespace std {
 #define _LIBCPP_HAS_NO_VARIADICS
 #define _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
+#define _LIBCPP_HAS_NO_STRONG_ENUMS
 
 #else  // __GXX_EXPERIMENTAL_CXX0X__
 
@@ -417,11 +460,16 @@ namespace _LIBCPP_NAMESPACE {
 using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
 }
 
+#if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__)
+#define _LIBCPP_HAS_NO_ASAN
+#endif
+
 #elif defined(_LIBCPP_MSVC)
 
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 #define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 #define _LIBCPP_HAS_NO_CONSTEXPR
+#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -430,8 +478,9 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
 #define _ALIGNAS(x) __declspec(align(x))
 #define _LIBCPP_HAS_NO_VARIADICS
 
-#define _NOEXCEPT throw()
+#define _NOEXCEPT throw ()
 #define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
 
 #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {
 #define _LIBCPP_END_NAMESPACE_STD  }
@@ -441,6 +490,8 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
 namespace std {
 }
 
+#define _LIBCPP_HAS_NO_ASAN
+
 #elif defined(__IBMCPP__)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
@@ -450,6 +501,7 @@ namespace std {
 
 #define _NOEXCEPT throw()
 #define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
 
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 #define _LIBCPP_HAS_NO_ADVANCED_SFINAE
@@ -472,13 +524,19 @@ namespace std {
   }
 }
 
-#endif // __clang__ || __GNUC___ || _MSC_VER || __IBMCPP__
+#define _LIBCPP_HAS_NO_ASAN
+
+#endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__
 
 #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
 typedef unsigned short char16_t;
 typedef unsigned int   char32_t;
 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
 
+#ifndef __SIZEOF_INT128__
+#define _LIBCPP_HAS_NO_INT128
+#endif
+
 #ifdef _LIBCPP_HAS_NO_STATIC_ASSERT
 
 template <bool> struct __static_assert_test;
@@ -516,12 +574,20 @@ template <unsigned> struct __static_assert_check {};
 #define __has_feature(__x) 0
 #endif
 
+#ifndef __has_builtin
+#define __has_builtin(__x) 0
+#endif
+
 #if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
 #   define _LIBCPP_EXPLICIT explicit
 #else
 #   define _LIBCPP_EXPLICIT
 #endif
 
+#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
+#   define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
+#endif
+
 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
 #define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
 #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
@@ -547,16 +613,21 @@ template <unsigned> struct __static_assert_check {};
 #endif
 
 #ifndef _LIBCPP_EXTERN_TEMPLATE
-#define _LIBCPP_EXTERN_TEMPLATE(...)
+#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
 #endif
 
 #ifndef _LIBCPP_EXTERN_TEMPLATE2
 #define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__;
 #endif
 
+#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
+#define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63)
+#endif
+
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) || defined(__NetBSD__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
+
 #ifdef __FreeBSD__
 #define _DECLARE_C99_LDBL_MATH 1
 #endif
@@ -569,10 +640,19 @@ template <unsigned> struct __static_assert_check {};
 #define _LIBCPP_WCTYPE_IS_MASK
 #endif
 
-#if defined(__APPLE__)
-#ifndef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
-#  define _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 0
-#endif
+#if defined(ELAST)
+#define _LIBCPP_ELAST ELAST
+#elif defined(__linux__)
+#define _LIBCPP_ELAST 4095
+#elif defined(_NEWLIB_VERSION)
+#define _LIBCPP_ELAST __ELASTERROR
+#elif defined(__APPLE__)
+// Not _LIBCPP_ELAST needed on Apple
+#elif defined(__EMSCRIPTEN__)
+#define _LIBCPP_ELAST 256
+#else
+// Warn here so that the person doing the libcxx port has an easier time:
+#warning This platform's ELAST hasn't been ported yet
 #endif
 
 #ifndef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
@@ -582,8 +662,10 @@ template <unsigned> struct __static_assert_check {};
 #ifndef _LIBCPP_STD_VER
 #  if  __cplusplus <= 201103L
 #    define _LIBCPP_STD_VER 11
+#  elif __cplusplus <= 201402L
+#    define _LIBCPP_STD_VER 14
 #  else
-#    define _LIBCPP_STD_VER 13  // current year, or date of c++14 ratification
+#    define _LIBCPP_STD_VER 15  // current year, or date of c++17 ratification
 #  endif
 #endif  // _LIBCPP_STD_VER
 
@@ -594,21 +676,30 @@ template <unsigned> struct __static_assert_check {};
 #endif
 
 #if _LIBCPP_STD_VER <= 11
-#define _LIBCPP_CONSTEXPR_AFTER_CXX11
 #define _LIBCPP_EXPLICIT_AFTER_CXX11
 #define _LIBCPP_DEPRECATED_AFTER_CXX11
 #else
-#define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
 #define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
 #define _LIBCPP_DEPRECATED_AFTER_CXX11 [[deprecated]]
 #endif
 
+#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
+#define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
+#else
+#define _LIBCPP_CONSTEXPR_AFTER_CXX11
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ASAN
+extern "C" void __sanitizer_annotate_contiguous_container(
+  const void *, const void *, const void *, const void *);
+#endif
+
 // Try to find out if RTTI is disabled.
 // g++ and cl.exe have RTTI on by default and define a macro when it is.
 // g++ only defines the macro in 4.3.2 and onwards.
 #if !defined(_LIBCPP_NO_RTTI)
-#  if defined(__GNUG__) && (__GNUC__ >= 4 && \
-   (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2)) && !defined(__GXX_RTTI)
+#  if defined(__GNUG__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \
+   (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI)
 #    define _LIBCPP_NO_RTTI
 #  elif (defined(_MSC_VER) && !defined(__clang__)) && !defined(_CPPRTTI)
 #    define _LIBCPP_NO_RTTI
diff --git a/system/include/libcxx/__debug b/system/include/libcxx/__debug
index f1805adcfe4cd..c1512246bfcf2 100644
--- a/system/include/libcxx/__debug
+++ b/system/include/libcxx/__debug
@@ -11,19 +11,23 @@
 #ifndef _LIBCPP_DEBUG_H
 #define _LIBCPP_DEBUG_H
 
+#include <__config>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
 #if _LIBCPP_DEBUG_LEVEL >= 1
-
 #   include <cstdlib>
 #   include <cstdio>
 #   include <cstddef>
 #   ifndef _LIBCPP_ASSERT
 #      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
 #   endif
+#endif
 
+#ifndef _LIBCPP_ASSERT
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
 #endif
 
 #if _LIBCPP_DEBUG_LEVEL >= 2
diff --git a/system/include/libcxx/__functional_03 b/system/include/libcxx/__functional_03
index f9a3d9766255e..d8a9f05fa124b 100644
--- a/system/include/libcxx/__functional_03
+++ b/system/include/libcxx/__functional_03
@@ -33,28 +33,28 @@ public:
     // invoke
 
     typename __invoke_return<type>::type
-       operator() ()
+       operator() () const
        {
            return __invoke(__f_);
        }
 
     template <class _A0>
        typename __invoke_return0<type, _A0>::type
-          operator() (_A0& __a0)
+          operator() (_A0& __a0) const
           {
               return __invoke(__f_, __a0);
           }
 
     template <class _A0, class _A1>
        typename __invoke_return1<type, _A0, _A1>::type
-          operator() (_A0& __a0, _A1& __a1)
+          operator() (_A0& __a0, _A1& __a1) const
           {
               return __invoke(__f_, __a0, __a1);
           }
 
     template <class _A0, class _A1, class _A2>
        typename __invoke_return2<type, _A0, _A1, _A2>::type
-          operator() (_A0& __a0, _A1& __a1, _A2& __a2)
+          operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
           {
               return __invoke(__f_, __a0, __a1, __a2);
           }
@@ -651,9 +651,14 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp()>
     __base* __f_;
 
     template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
         static bool __not_null(const _Fp&) {return true;}
     template <class _R2>
-        static bool __not_null(const function<_Rp()>& __p) {return __p;}
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)()) {return __p;}
+    template <class _R2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2()>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -955,7 +960,7 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)>
         static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;}
     template <class _R2, class _B0>
         _LIBCPP_INLINE_VISIBILITY
-        static bool __not_null(const function<_Rp(_B0)>& __p) {return __p;}
+        static bool __not_null(const function<_R2(_B0)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -1257,7 +1262,7 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)>
         static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;}
     template <class _R2, class _B0, class _B1>
         _LIBCPP_INLINE_VISIBILITY
-        static bool __not_null(const function<_Rp(_B0, _B1)>& __p) {return __p;}
+        static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -1558,7 +1563,7 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)>
         static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;}
     template <class _R2, class _B0, class _B1, class _B2>
         _LIBCPP_INLINE_VISIBILITY
-        static bool __not_null(const function<_Rp(_B0, _B1, _B2)>& __p) {return __p;}
+        static bool __not_null(const function<_R2(_B0, _B1, _B2)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -1911,7 +1916,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 typename __mu_return1<true, _Ti, _Uj...>::type
 __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
 {
-    __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...);
+    __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...);
 }
 
 template <class _Ti, class ..._Uj>
@@ -1947,9 +1952,9 @@ __mu(_Ti&, _Uj& __uj)
 {
     const size_t _Indx = is_placeholder<_Ti>::value - 1;
     // compiler bug workaround
-    typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj);
+    typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj);
     return __t;
-//    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
+//    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
 }
 
 template <class _Ti, class _Uj>
@@ -2040,7 +2045,7 @@ typename __bind_return<_Fp, _BoundArgs, _Args>::type
 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
                 _Args&& __args)
 {
-    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
+    return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
 }
 
 template<class _Fp, class ..._BoundArgs>
diff --git a/system/include/libcxx/__functional_base b/system/include/libcxx/__functional_base
index 1c337d8b4bf79..6766793d7c8ae 100644
--- a/system/include/libcxx/__functional_base
+++ b/system/include/libcxx/__functional_base
@@ -451,10 +451,10 @@ public:
           }
 };
 
-template <class _Tp> struct ____is_reference_wrapper : public false_type {};
-template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
+template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
+template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
 template <class _Tp> struct __is_reference_wrapper
-    : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {};
+    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
diff --git a/system/include/libcxx/__functional_base_03 b/system/include/libcxx/__functional_base_03
index 296dd8db30728..22c06add90f4f 100644
--- a/system/include/libcxx/__functional_base_03
+++ b/system/include/libcxx/__functional_base_03
@@ -1027,7 +1027,7 @@ public:
        typename __invoke_return0<type&, _A0>::type
           operator() (_A0& __a0) const
           {
-              return __invoke(get(), __a0);
+              return __invoke<type&, _A0>(get(), __a0);
           }
 
     template <class _A0, class _A1>
@@ -1035,7 +1035,7 @@ public:
        typename __invoke_return1<type&, _A0, _A1>::type
           operator() (_A0& __a0, _A1& __a1) const
           {
-              return __invoke(get(), __a0, __a1);
+              return __invoke<type&, _A0, _A1>(get(), __a0, __a1);
           }
 
     template <class _A0, class _A1, class _A2>
@@ -1043,14 +1043,14 @@ public:
        typename __invoke_return2<type&, _A0, _A1, _A2>::type
           operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
           {
-              return __invoke(get(), __a0, __a1, __a2);
+              return __invoke<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2);
           }
 };
 
-template <class _Tp> struct ____is_reference_wrapper : public false_type {};
-template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
+template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
+template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
 template <class _Tp> struct __is_reference_wrapper
-    : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {};
+    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
diff --git a/system/include/libcxx/__hash_table b/system/include/libcxx/__hash_table
index 4c4feb03eabfb..7c954b68011dd 100644
--- a/system/include/libcxx/__hash_table
+++ b/system/include/libcxx/__hash_table
@@ -20,11 +20,7 @@
 
 #include <__undef_min_max>
 
-#ifdef _LIBCPP_DEBUG
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
+#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
diff --git a/system/include/libcxx/__locale b/system/include/libcxx/__locale
index 6d75162a99aa8..5ccd795b8774a 100644
--- a/system/include/libcxx/__locale
+++ b/system/include/libcxx/__locale
@@ -21,11 +21,18 @@
 #include <locale.h>
 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
 # include <support/win32/locale_win32.h>
-#elif _AIX
+#elif defined(_AIX)
 # include <support/ibm/xlocale.h>
-#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)
+#elif defined(__ANDROID__)
+// Android gained the locale aware functions in L (API level 21)
+# include <android/api-level.h>
+# if __ANDROID_API__ <= 20
+#  include <support/android/locale_bionic.h>
+# endif
+#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
+    || defined(__sun__)   || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
 # include <xlocale.h>
-#endif  // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -341,13 +348,15 @@ public:
     static const mask punct  = _PUNCT;
     static const mask xdigit = _HEX;
     static const mask blank  = _BLANK;
-#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__ANDROID__)
 #ifdef __APPLE__
     typedef __uint32_t mask;
 #elif defined(__FreeBSD__)
     typedef unsigned long mask;
 #elif defined(__EMSCRIPTEN__) ||  defined(__NetBSD__)
     typedef unsigned short mask;
+#elif defined(__ANDROID__)
+    typedef unsigned char mask;
 #endif
     static const mask space  = _CTYPE_S;
     static const mask print  = _CTYPE_R;
@@ -357,7 +366,12 @@ public:
     static const mask alpha  = _CTYPE_A;
     static const mask digit  = _CTYPE_D;
     static const mask punct  = _CTYPE_P;
+# if defined(__ANDROID__)
+    static const mask xdigit = _CTYPE_X | _CTYPE_D;
+# else
     static const mask xdigit = _CTYPE_X;
+# endif
+
 # if defined(__NetBSD__)
     static const mask blank  = _CTYPE_BL;
 # else
diff --git a/system/include/libcxx/__mutex_base b/system/include/libcxx/__mutex_base
index d4023a64f9faf..d5ece7c1454c8 100644
--- a/system/include/libcxx/__mutex_base
+++ b/system/include/libcxx/__mutex_base
@@ -22,6 +22,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 class _LIBCPP_TYPE_VIS mutex
 {
     pthread_mutex_t __m_;
@@ -254,19 +256,13 @@ void
 swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT
     {__x.swap(__y);}
 
-struct _LIBCPP_TYPE_VIS cv_status
+//enum class cv_status
+_LIBCPP_DECLARE_STRONG_ENUM(cv_status)
 {
-    enum __lx {
-        no_timeout,
-        timeout
-    };
-
-    __lx __v_;
-
-    _LIBCPP_INLINE_VISIBILITY cv_status(__lx __v) : __v_(__v) {}
-    _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;}
-
+    no_timeout,
+    timeout
 };
+_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status)
 
 class _LIBCPP_TYPE_VIS condition_variable
 {
@@ -288,7 +284,7 @@ public:
     void notify_one() _NOEXCEPT;
     void notify_all() _NOEXCEPT;
 
-    void wait(unique_lock<mutex>& __lk);
+    void wait(unique_lock<mutex>& __lk) _NOEXCEPT;
     template <class _Predicate>
         void wait(unique_lock<mutex>& __lk, _Predicate __pred);
 
@@ -319,8 +315,9 @@ public:
 
 private:
     void __do_timed_wait(unique_lock<mutex>& __lk,
-                 chrono::time_point<chrono::system_clock, chrono::nanoseconds>);
+       chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
 };
+#endif // !_LIBCPP_HAS_NO_THREADS
 
 template <class _To, class _Rep, class _Period>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -338,6 +335,7 @@ __ceil(chrono::duration<_Rep, _Period> __d)
     return __r;
 }
 
+#ifndef _LIBCPP_HAS_NO_THREADS
 template <class _Predicate>
 void
 condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred)
@@ -402,6 +400,8 @@ condition_variable::wait_for(unique_lock<mutex>& __lk,
                       _VSTD::move(__pred));
 }
 
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP___MUTEX_BASE
diff --git a/system/include/libcxx/__refstring b/system/include/libcxx/__refstring
new file mode 100644
index 0000000000000..6866bf1b9736e
--- /dev/null
+++ b/system/include/libcxx/__refstring
@@ -0,0 +1,139 @@
+//===------------------------ __refstring ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___REFSTRING
+#define _LIBCPP___REFSTRING
+
+#include <__config>
+#include <cstddef>
+#include <cstring>
+#if __APPLE__
+#include <dlfcn.h>
+#include <mach-o/dyld.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_HIDDEN __libcpp_refstring
+{
+private:
+    const char* str_;
+
+    typedef int count_t;
+
+    struct _Rep_base
+    {
+        std::size_t len;
+        std::size_t cap;
+        count_t     count;
+    };
+
+    static
+    _Rep_base*
+    rep_from_data(const char *data_) _NOEXCEPT
+    {
+        char *data = const_cast<char *>(data_);
+        return reinterpret_cast<_Rep_base *>(data - sizeof(_Rep_base));
+    }
+    static
+    char *
+    data_from_rep(_Rep_base *rep) _NOEXCEPT
+    {
+        char *data = reinterpret_cast<char *>(rep);
+        return data + sizeof(*rep);
+    }
+
+#if __APPLE__
+    static
+    const char*
+    compute_gcc_empty_string_storage() _NOEXCEPT
+    {
+        void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
+        if (handle == nullptr)
+            return nullptr;
+        void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
+        if (sym == nullptr)
+            return nullptr;
+        return data_from_rep(reinterpret_cast<_Rep_base *>(sym));
+    }
+
+    static
+    const char*
+    get_gcc_empty_string_storage() _NOEXCEPT
+    {
+        static const char* p = compute_gcc_empty_string_storage();
+        return p;
+    }
+
+    bool
+    uses_refcount() const
+    {
+        return str_ != get_gcc_empty_string_storage();
+    }
+#else
+    bool
+    uses_refcount() const
+    {
+        return true;
+    }
+#endif
+
+public:
+    explicit __libcpp_refstring(const char* msg) {
+        std::size_t len = strlen(msg);
+        _Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1));
+        rep->len = len;
+        rep->cap = len;
+        rep->count = 0;
+        char *data = data_from_rep(rep);
+        std::memcpy(data, msg, len + 1);
+        str_ = data;
+    }
+
+    __libcpp_refstring(const __libcpp_refstring& s) _NOEXCEPT : str_(s.str_)
+    {
+        if (uses_refcount())
+            __sync_add_and_fetch(&rep_from_data(str_)->count, 1);
+    }
+
+    __libcpp_refstring& operator=(const __libcpp_refstring& s) _NOEXCEPT
+    {
+        bool adjust_old_count = uses_refcount();
+        struct _Rep_base *old_rep = rep_from_data(str_);
+        str_ = s.str_;
+        if (uses_refcount())
+            __sync_add_and_fetch(&rep_from_data(str_)->count, 1);
+        if (adjust_old_count)
+        {
+            if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+            {
+                ::operator delete(old_rep);
+            }
+        }
+        return *this;
+    }
+
+    ~__libcpp_refstring()
+    {
+        if (uses_refcount())
+        {
+            _Rep_base* rep = rep_from_data(str_);
+            if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0)
+            {
+                ::operator delete(rep);
+            }
+        }
+    }
+
+    const char* c_str() const _NOEXCEPT {return str_;}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif //_LIBCPP___REFSTRING
diff --git a/system/include/libcxx/__sso_allocator b/system/include/libcxx/__sso_allocator
index 7240072cafdf6..645f2ba174598 100644
--- a/system/include/libcxx/__sso_allocator
+++ b/system/include/libcxx/__sso_allocator
@@ -55,14 +55,14 @@ public:
             __allocated_ = true;
             return (pointer)&buf_;
         }
-        return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));
+        return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
     }
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
     {
         if (__p == (pointer)&buf_)
             __allocated_ = false;
         else
-            ::operator delete(__p);
+            _VSTD::__deallocate(__p);
     }
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
 
diff --git a/system/include/libcxx/__tree b/system/include/libcxx/__tree
index acf87593a9700..8e5447a2ffb58 100644
--- a/system/include/libcxx/__tree
+++ b/system/include/libcxx/__tree
@@ -1980,9 +1980,9 @@ __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p)
         __begin_node() = __r.__ptr_;
     --size();
     __node_allocator& __na = __node_alloc();
-    __node_traits::destroy(__na, const_cast<value_type*>(_VSTD::addressof(*__p)));
     __tree_remove(__end_node()->__left_,
                   static_cast<__node_base_pointer>(__np));
+    __node_traits::destroy(__na, const_cast<value_type*>(_VSTD::addressof(*__p)));
     __node_traits::deallocate(__na, __np, 1);
     return __r;
 }
diff --git a/system/include/libcxx/__tuple b/system/include/libcxx/__tuple
index de35cb87e8de0..ee5b916fa52a9 100644
--- a/system/include/libcxx/__tuple
+++ b/system/include/libcxx/__tuple
@@ -27,6 +27,32 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+// __lazy_and
+
+template <bool _Last, class ..._Preds>
+struct __lazy_and_impl;
+
+template <class ..._Preds>
+struct __lazy_and_impl<false, _Preds...> : false_type {};
+
+template <>
+struct __lazy_and_impl<true> : true_type {};
+
+template <class _Pred>
+struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {};
+
+template <class _Hp, class ..._Tp>
+struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {};
+
+template <class _P1, class ..._Pr>
+struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {};
+
+// __lazy_not
+
+template <class _Pred>
+struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
+
+
 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_size;
 
 template <class _Tp>
diff --git a/system/include/libcxx/algorithm b/system/include/libcxx/algorithm
index 367489fbb83c3..dbe888f78ddf3 100644
--- a/system/include/libcxx/algorithm
+++ b/system/include/libcxx/algorithm
@@ -281,11 +281,12 @@ template <class ForwardIterator, class OutputIterator>
 
 template <class RandomAccessIterator>
     void
-    random_shuffle(RandomAccessIterator first, RandomAccessIterator last);
+    random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14
 
 template <class RandomAccessIterator, class RandomNumberGenerator>
     void
-    random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand);
+    random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
+                   RandomNumberGenerator& rand);  // deprecated in C++14
 
 template<class RandomAccessIterator, class UniformRandomNumberGenerator>
     void shuffle(RandomAccessIterator first, RandomAccessIterator last,
@@ -528,19 +529,19 @@ template <class ForwardIterator, class Compare>
 
 template <class T>
     const T&
-    min(const T& a, const T& b);
+    min(const T& a, const T& b);  // constexpr in C++14
 
 template <class T, class Compare>
     const T&
-    min(const T& a, const T& b, Compare comp);
+    min(const T& a, const T& b, Compare comp);  // constexpr in C++14
 
 template<class T>
     T
-    min(initializer_list<T> t);
+    min(initializer_list<T> t);  // constexpr in C++14
 
 template<class T, class Compare>
     T
-    min(initializer_list<T> t, Compare comp);
+    min(initializer_list<T> t, Compare comp);  // constexpr in C++14
 
 template <class ForwardIterator>
     ForwardIterator
@@ -552,19 +553,19 @@ template <class ForwardIterator, class Compare>
 
 template <class T>
     const T&
-    max(const T& a, const T& b);
+    max(const T& a, const T& b); // constexpr in C++14
 
 template <class T, class Compare>
     const T&
-    max(const T& a, const T& b, Compare comp);
+    max(const T& a, const T& b, Compare comp);  // constexpr in C++14
 
 template<class T>
     T
-    max(initializer_list<T> t);
+    max(initializer_list<T> t);  // constexpr in C++14
 
 template<class T, class Compare>
     T
-    max(initializer_list<T> t, Compare comp);
+    max(initializer_list<T> t, Compare comp);  // constexpr in C++14
 
 template<class ForwardIterator>
     pair<ForwardIterator, ForwardIterator>
@@ -576,19 +577,19 @@ template<class ForwardIterator, class Compare>
 
 template<class T>
     pair<const T&, const T&>
-    minmax(const T& a, const T& b);
+    minmax(const T& a, const T& b);  // constexpr in C++14
 
 template<class T, class Compare>
     pair<const T&, const T&>
-    minmax(const T& a, const T& b, Compare comp);
+    minmax(const T& a, const T& b, Compare comp);  // constexpr in C++14
 
 template<class T>
     pair<T, T>
-    minmax(initializer_list<T> t);
+    minmax(initializer_list<T> t);  // constexpr in C++14
 
 template<class T, class Compare>
     pair<T, T>
-    minmax(initializer_list<T> t, Compare comp);
+    minmax(initializer_list<T> t, Compare comp);  // constexpr in C++14
 
 template <class InputIterator1, class InputIterator2>
     bool
@@ -637,12 +638,17 @@ template <class BidirectionalIterator, class Compare>
 
 #include <__undef_min_max>
 
+#include <__debug>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+// I'd like to replace these with _VSTD::equal_to<void>, but can't because:
+//   * That only works with C++14 and later, and
+//   * We haven't included <functional> here.
 template <class _T1, class _T2 = _T1>
 struct __equal_to
 {
@@ -655,46 +661,59 @@ struct __equal_to
 template <class _T1>
 struct __equal_to<_T1, _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
 };
 
 template <class _T1>
 struct __equal_to<const _T1, _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
 };
 
 template <class _T1>
 struct __equal_to<_T1, const _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
 };
 
 template <class _T1, class _T2 = _T1>
 struct __less
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
 };
 
 template <class _T1>
 struct __less<_T1, _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
 };
 
 template <class _T1>
 struct __less<const _T1, _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
 };
 
 template <class _T1>
 struct __less<_T1, const _T1>
 {
-    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
 };
 
 template <class _Predicate>
@@ -958,7 +977,7 @@ __find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1,
 }
 
 template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
 __find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
            _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
            random_access_iterator_tag, random_access_iterator_tag)
@@ -1024,8 +1043,8 @@ find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
 // find_first_of
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_ForwardIterator1
-find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1
+__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
               _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
 {
     for (; __first1 != __last1; ++__first1)
@@ -1035,6 +1054,16 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
     return __last1;
 }
 
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+              _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
+{
+    return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
+}
+
 template <class _ForwardIterator1, class _ForwardIterator2>
 inline _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator1
@@ -1043,7 +1072,7 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
 {
     typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
     typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
-    return _VSTD::find_first_of(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+    return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
 }
 
 // adjacent_find
@@ -1111,7 +1140,7 @@ pair<_InputIterator1, _InputIterator2>
 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
          _InputIterator2 __first2, _BinaryPredicate __pred)
 {
-    for (; __first1 != __last1; ++__first1, ++__first2)
+    for (; __first1 != __last1; ++__first1, (void) ++__first2)
         if (!__pred(*__first1, *__first2))
             break;
     return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
@@ -1135,7 +1164,7 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
          _InputIterator2 __first2, _InputIterator2 __last2,
          _BinaryPredicate __pred)
 {
-    for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+    for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
         if (!__pred(*__first1, *__first2))
             break;
     return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
@@ -1423,7 +1452,7 @@ __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
 }
 
 template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
 __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
            _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
            random_access_iterator_tag, random_access_iterator_tag)
@@ -2505,9 +2534,9 @@ rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterato
 // min_element
 
 template <class _ForwardIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
     if (__first != __last)
     {
@@ -2519,19 +2548,27 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
     return __first;
 }
 
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    return __min_element(__first, __last, __comp);
+}
+
 template <class _ForwardIterator>
 inline _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator
 min_element(_ForwardIterator __first, _ForwardIterator __last)
 {
-    return _VSTD::min_element(__first, __last,
+    return __min_element(__first, __last,
               __less<typename iterator_traits<_ForwardIterator>::value_type>());
 }
 
 // min
 
 template <class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const _Tp&
 min(const _Tp& __a, const _Tp& __b, _Compare __comp)
 {
@@ -2539,7 +2576,7 @@ min(const _Tp& __a, const _Tp& __b, _Compare __comp)
 }
 
 template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const _Tp&
 min(const _Tp& __a, const _Tp& __b)
 {
@@ -2549,19 +2586,19 @@ min(const _Tp& __a, const _Tp& __b)
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 min(initializer_list<_Tp> __t, _Compare __comp)
 {
-    return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
+    return *__min_element(__t.begin(), __t.end(), __comp);
 }
 
 template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 min(initializer_list<_Tp> __t)
 {
-    return *_VSTD::min_element(__t.begin(), __t.end());
+    return *__min_element(__t.begin(), __t.end(), __less<_Tp>());
 }
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -2569,9 +2606,9 @@ min(initializer_list<_Tp> __t)
 // max_element
 
 template <class _ForwardIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
     if (__first != __last)
     {
@@ -2583,19 +2620,28 @@ max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
     return __first;
 }
 
+
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    return __max_element(__first, __last, __comp);
+}
+
 template <class _ForwardIterator>
 inline _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator
 max_element(_ForwardIterator __first, _ForwardIterator __last)
 {
-    return _VSTD::max_element(__first, __last,
+    return __max_element(__first, __last,
               __less<typename iterator_traits<_ForwardIterator>::value_type>());
 }
 
 // max
 
 template <class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const _Tp&
 max(const _Tp& __a, const _Tp& __b, _Compare __comp)
 {
@@ -2603,7 +2649,7 @@ max(const _Tp& __a, const _Tp& __b, _Compare __comp)
 }
 
 template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 const _Tp&
 max(const _Tp& __a, const _Tp& __b)
 {
@@ -2613,19 +2659,19 @@ max(const _Tp& __a, const _Tp& __b)
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 max(initializer_list<_Tp> __t, _Compare __comp)
 {
-    return *_VSTD::max_element(__t.begin(), __t.end(), __comp);
+    return *__max_element(__t.begin(), __t.end(), __comp);
 }
 
 template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp
 max(initializer_list<_Tp> __t)
 {
-    return *_VSTD::max_element(__t.begin(), __t.end());
+    return *__max_element(__t.begin(), __t.end(), __less<_Tp>());
 }
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -2684,13 +2730,14 @@ inline _LIBCPP_INLINE_VISIBILITY
 std::pair<_ForwardIterator, _ForwardIterator>
 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
 {
-    return _VSTD::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+    return _VSTD::minmax_element(__first, __last,
+              __less<typename iterator_traits<_ForwardIterator>::value_type>());
 }
 
 // minmax
 
 template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 pair<const _Tp&, const _Tp&>
 minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
 {
@@ -2699,7 +2746,7 @@ minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
 }
 
 template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 pair<const _Tp&, const _Tp&>
 minmax(const _Tp& __a, const _Tp& __b)
 {
@@ -2708,24 +2755,49 @@ minmax(const _Tp& __a, const _Tp& __b)
 
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+template<class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 pair<_Tp, _Tp>
-minmax(initializer_list<_Tp> __t)
+minmax(initializer_list<_Tp> __t, _Compare __comp)
 {
-    pair<const _Tp*, const _Tp*> __p =
-                                   _VSTD::minmax_element(__t.begin(), __t.end());
-    return pair<_Tp, _Tp>(*__p.first, *__p.second);
+    typedef typename initializer_list<_Tp>::const_iterator _Iter;
+    _Iter __first = __t.begin();
+    _Iter __last  = __t.end();
+    std::pair<_Tp, _Tp> __result ( *__first, *__first );
+
+    ++__first;
+    if (__t.size() % 2 == 0)
+    {
+        if (__comp(*__first,  __result.first))
+            __result.first  = *__first;
+        else
+            __result.second = *__first;
+        ++__first;
+    }
+    
+    while (__first != __last)
+    {
+        _Tp __prev = *__first++;
+        if (__comp(__prev, *__first)) {
+            if (__comp(__prev, __result.first))    __result.first  = __prev;
+            if (__comp(__result.second, *__first)) __result.second = *__first;
+            }
+        else {
+            if (__comp(*__first, __result.first)) __result.first  = *__first;
+            if (__comp(__result.second, __prev))  __result.second = __prev;
+            }
+                
+        __first++;
+    }
+    return __result;
 }
 
-template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 pair<_Tp, _Tp>
-minmax(initializer_list<_Tp> __t, _Compare __comp)
+minmax(initializer_list<_Tp> __t)
 {
-    pair<const _Tp*, const _Tp*> __p =
-                           _VSTD::minmax_element(__t.begin(), __t.end(), __comp);
-    return pair<_Tp, _Tp>(*__p.first, *__p.second);
+    return _VSTD::minmax(__t, __less<_Tp>());
 }
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -4724,49 +4796,8 @@ is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 template <class _Compare, class _RandomAccessIterator>
 void
-__push_heap_front(_RandomAccessIterator __first, _RandomAccessIterator, _Compare __comp,
-                  typename iterator_traits<_RandomAccessIterator>::difference_type __len)
-{
-    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
-    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
-    if (__len > 1)
-    {
-        difference_type __p = 0;
-        _RandomAccessIterator __pp = __first;
-        difference_type __c = 2;
-        _RandomAccessIterator __cp = __first + __c;
-        if (__c == __len || __comp(*__cp, *(__cp - 1)))
-        {
-            --__c;
-            --__cp;
-        }
-        if (__comp(*__pp, *__cp))
-        {
-            value_type __t(_VSTD::move(*__pp));
-            do
-            {
-                *__pp = _VSTD::move(*__cp);
-                __pp = __cp;
-                __p = __c;
-                __c = (__p + 1) * 2;
-                if (__c > __len)
-                    break;
-                __cp = __first + __c;
-                if (__c == __len || __comp(*__cp, *(__cp - 1)))
-                {
-                    --__c;
-                    --__cp;
-                }
-            } while (__comp(__t, *__cp));
-            *__pp = _VSTD::move(__t);
-        }
-    }
-}
-
-template <class _Compare, class _RandomAccessIterator>
-void
-__push_heap_back(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-                 typename iterator_traits<_RandomAccessIterator>::difference_type __len)
+__sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+          typename iterator_traits<_RandomAccessIterator>::difference_type __len)
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
@@ -4799,10 +4830,10 @@ push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare
 #ifdef _LIBCPP_DEBUG
     typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
     __debug_less<_Compare> __c(__comp);
-    __push_heap_back<_Comp_ref>(__first, __last, __c, __last - __first);
+    __sift_up<_Comp_ref>(__first, __last, __c, __last - __first);
 #else  // _LIBCPP_DEBUG
     typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
-    __push_heap_back<_Comp_ref>(__first, __last, __comp, __last - __first);
+    __sift_up<_Comp_ref>(__first, __last, __comp, __last - __first);
 #endif  // _LIBCPP_DEBUG
 }
 
@@ -4816,6 +4847,60 @@ push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
 
 // pop_heap
 
+template <class _Compare, class _RandomAccessIterator>
+void
+__sift_down(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+            typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+            _RandomAccessIterator __start)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    // left-child of __start is at 2 * __start + 1
+    // right-child of __start is at 2 * __start + 2
+    difference_type __child = __start - __first;
+
+    if (__len < 2 || (__len - 2) / 2 < __child)
+        return;
+
+    __child = 2 * __child + 1;
+    _RandomAccessIterator __child_i = __first + __child;
+
+    if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
+        // right-child exists and is greater than left-child
+        ++__child_i;
+        ++__child;
+    }
+
+    // check if we are in heap-order
+    if (__comp(*__child_i, *__start))
+        // we are, __start is larger than it's largest child
+        return;
+
+    value_type __top(_VSTD::move(*__start));
+    do
+    {
+        // we are not in heap-order, swap the parent with it's largest child
+        *__start = _VSTD::move(*__child_i);
+        __start = __child_i;
+
+        if ((__len - 2) / 2 < __child)
+            break;
+
+        // recompute the child based off of the updated parent
+        __child = 2 * __child + 1;
+        __child_i = __first + __child;
+
+        if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
+            // right-child exists and is greater than left-child
+            ++__child_i;
+            ++__child;
+        }
+
+        // check if we are in heap-order
+    } while (!__comp(*__child_i, __top));
+    *__start = _VSTD::move(__top);
+}
+
 template <class _Compare, class _RandomAccessIterator>
 inline _LIBCPP_INLINE_VISIBILITY
 void
@@ -4825,7 +4910,7 @@ __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare
     if (__len > 1)
     {
         swap(*__first, *--__last);
-        __push_heap_front<_Compare>(__first, __last, __comp, __len-1);
+        __sift_down<_Compare>(__first, __last, __comp, __len - 1, __first);
     }
 }
 
@@ -4862,10 +4947,11 @@ __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compar
     difference_type __n = __last - __first;
     if (__n > 1)
     {
-        __last = __first;
-        ++__last;
-        for (difference_type __i = 1; __i < __n;)
-            __push_heap_back<_Compare>(__first, ++__last, __comp, ++__i);
+        // start from the first parent, there is no need to consider children
+        for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
+        {
+            __sift_down<_Compare>(__first, __last, __comp, __n, __first + __start);
+        }
     }
 }
 
@@ -4940,7 +5026,7 @@ __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _R
         if (__comp(*__i, *__first))
         {
             swap(*__i, *__first);
-            __push_heap_front<_Compare>(__first, __middle, __comp, __len);
+            __sift_down<_Compare>(__first, __middle, __comp, __len, __first);
         }
     }
     __sort_heap<_Compare>(__first, __middle, __comp);
@@ -4981,15 +5067,15 @@ __partial_sort_copy(_InputIterator __first, _InputIterator __last,
     _RandomAccessIterator __r = __result_first;
     if (__r != __result_last)
     {
-        typename iterator_traits<_RandomAccessIterator>::difference_type __len = 0;
-        for (; __first != __last && __r != __result_last; ++__first, ++__r, ++__len)
+        for (; __first != __last && __r != __result_last; ++__first, ++__r)
             *__r = *__first;
         __make_heap<_Compare>(__result_first, __r, __comp);
+        typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
         for (; __first != __last; ++__first)
             if (__comp(*__first, *__result_first))
             {
                 *__result_first = *__first;
-                __push_heap_front<_Compare>(__result_first, __r, __comp, __len);
+                __sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first);
             }
         __sort_heap<_Compare>(__result_first, __r, __comp);
     }
diff --git a/system/include/libcxx/atomic b/system/include/libcxx/atomic
index f6ab1cbaf49fb..b01a59f5f96f0 100644
--- a/system/include/libcxx/atomic
+++ b/system/include/libcxx/atomic
@@ -533,9 +533,13 @@ void atomic_signal_fence(memory_order m) noexcept;
 #pragma GCC system_header
 #endif
 
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <atomic> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !__has_feature(cxx_atomic)
+#if !__has_feature(cxx_atomic) && _GNUC_VER < 407
 #error <atomic> is not implemented
 #else
 
@@ -545,6 +549,257 @@ typedef enum memory_order
     memory_order_release, memory_order_acq_rel, memory_order_seq_cst
 } memory_order;
 
+#if _GNUC_VER >= 407
+namespace __gcc_atomic {
+template <typename T>
+struct __gcc_atomic_t {
+  __gcc_atomic_t() _NOEXCEPT {}
+  explicit __gcc_atomic_t(T value) _NOEXCEPT : __a_value(value) {}
+  T __a_value;
+};
+#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
+
+template <typename T> T __create();
+
+template <typename __Tp, typename __Td>
+typename enable_if<sizeof(__Tp()->__a_value = __create<__Td>()), char>::type
+    __test_atomic_assignable(int);
+template <typename T, typename U>
+__two __test_atomic_assignable(...);
+
+template <typename __Tp, typename __Td>
+struct __can_assign {
+  static const bool value =
+      sizeof(__test_atomic_assignable<__Tp, __Td>(1)) == sizeof(char);
+};
+
+static inline constexpr int __to_gcc_order(memory_order __order) {
+  // Avoid switch statement to make this a constexpr.
+  return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
+         (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
+          (__order == memory_order_release ? __ATOMIC_RELEASE:
+           (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
+            (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
+              __ATOMIC_CONSUME))));
+}
+
+} // namespace __gcc_atomic
+
+template <typename _Tp>
+static inline
+typename enable_if<
+    __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+  __a->__a_value = __val;
+}
+
+template <typename _Tp>
+static inline
+typename enable_if<
+    !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
+     __gcc_atomic::__can_assign<         _Atomic(_Tp)*, _Tp>::value>::type
+__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
+  // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
+  // the default operator= in an object is not volatile, a byte-by-byte copy
+  // is required.
+  volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
+  volatile char* end = to + sizeof(_Tp);
+  char* from = reinterpret_cast<char*>(&__val);
+  while (to != end) {
+    *to++ = *from++;
+  }
+}
+
+template <typename _Tp>
+static inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val) {
+  __a->__a_value = __val;
+}
+
+static inline void __c11_atomic_thread_fence(memory_order __order) {
+  __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
+}
+
+static inline void __c11_atomic_signal_fence(memory_order __order) {
+  __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
+}
+
+static inline bool __c11_atomic_is_lock_free(size_t __size) {
+  return __atomic_is_lock_free(__size, 0);
+}
+
+template <typename _Tp>
+static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a,  _Tp __val,
+                                      memory_order __order) {
+  return __atomic_store(&__a->__a_value, &__val,
+                        __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline void __c11_atomic_store(_Atomic(_Tp)* __a,  _Tp __val,
+                                      memory_order __order) {
+  return __atomic_store(&__a->__a_value, &__val,
+                        __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
+                                    memory_order __order) {
+  _Tp __ret;
+  __atomic_load(&__a->__a_value, &__ret,
+                __gcc_atomic::__to_gcc_order(__order));
+  return __ret;
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
+  _Tp __ret;
+  __atomic_load(&__a->__a_value, &__ret,
+                __gcc_atomic::__to_gcc_order(__order));
+  return __ret;
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
+                                        _Tp __value, memory_order __order) {
+  _Tp __ret;
+  __atomic_exchange(&__a->__a_value, &__value, &__ret,
+                    __gcc_atomic::__to_gcc_order(__order));
+  return __ret;
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
+                                        memory_order __order) {
+  _Tp __ret;
+  __atomic_exchange(&__a->__a_value, &__value, &__ret,
+                    __gcc_atomic::__to_gcc_order(__order));
+  return __ret;
+}
+
+template <typename _Tp>
+static inline bool __c11_atomic_compare_exchange_strong(
+    volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
+    memory_order __success, memory_order __failure) {
+  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
+                                   false,
+                                   __gcc_atomic::__to_gcc_order(__success),
+                                   __gcc_atomic::__to_gcc_order(__failure));
+}
+
+template <typename _Tp>
+static inline bool __c11_atomic_compare_exchange_strong(
+    _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
+    memory_order __failure) {
+  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
+                                   false,
+                                   __gcc_atomic::__to_gcc_order(__success),
+                                   __gcc_atomic::__to_gcc_order(__failure));
+}
+
+template <typename _Tp>
+static inline bool __c11_atomic_compare_exchange_weak(
+    volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
+    memory_order __success, memory_order __failure) {
+  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
+                                   true,
+                                   __gcc_atomic::__to_gcc_order(__success),
+                                   __gcc_atomic::__to_gcc_order(__failure));
+}
+
+template <typename _Tp>
+static inline bool __c11_atomic_compare_exchange_weak(
+    _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
+    memory_order __failure) {
+  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
+                                   true,
+                                   __gcc_atomic::__to_gcc_order(__success),
+                                   __gcc_atomic::__to_gcc_order(__failure));
+}
+
+template <typename _Tp>
+struct __skip_amt { enum {value = 1}; };
+
+template <typename _Tp>
+struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
+
+// FIXME: Haven't figured out what the spec says about using arrays with
+// atomic_fetch_add. Force a failure rather than creating bad behavior.
+template <typename _Tp>
+struct __skip_amt<_Tp[]> { };
+template <typename _Tp, int n>
+struct __skip_amt<_Tp[n]> { };
+
+template <typename _Tp, typename _Td>
+static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
+                                         _Td __delta, memory_order __order) {
+  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp, typename _Td>
+static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
+                                         memory_order __order) {
+  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp, typename _Td>
+static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
+                                         _Td __delta, memory_order __order) {
+  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp, typename _Td>
+static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
+                                         memory_order __order) {
+  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
+                                         _Tp __pattern, memory_order __order) {
+  return __atomic_fetch_and(&__a->__a_value, __pattern,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
+                                         _Tp __pattern, memory_order __order) {
+  return __atomic_fetch_and(&__a->__a_value, __pattern,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
+                                        _Tp __pattern, memory_order __order) {
+  return __atomic_fetch_or(&__a->__a_value, __pattern,
+                           __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
+                                        memory_order __order) {
+  return __atomic_fetch_or(&__a->__a_value, __pattern,
+                           __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
+                                         _Tp __pattern, memory_order __order) {
+  return __atomic_fetch_xor(&__a->__a_value, __pattern,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+
+template <typename _Tp>
+static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
+                                         memory_order __order) {
+  return __atomic_fetch_xor(&__a->__a_value, __pattern,
+                            __gcc_atomic::__to_gcc_order(__order));
+}
+#endif // _GNUC_VER >= 407
+
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 _Tp
@@ -1528,4 +1783,6 @@ typedef atomic<uintmax_t> atomic_uintmax_t;
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif  // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_ATOMIC
diff --git a/system/include/libcxx/bitset b/system/include/libcxx/bitset
index 4cc7dbdaef953..8c278cc724f1f 100644
--- a/system/include/libcxx/bitset
+++ b/system/include/libcxx/bitset
@@ -249,9 +249,9 @@ inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-#if __SIZE_WIDTH__ == 64
+#if __SIZEOF_SIZE_T__ == 8
     : __first_{__v}
-#elif __SIZE_WIDTH__ == 32
+#elif __SIZEOF_SIZE_T__ == 4
     : __first_{__v, __v >> __bits_per_word}
 #else
 #error This constructor has not been ported to this platform
diff --git a/system/include/libcxx/chrono b/system/include/libcxx/chrono
index 2c65eee7d067e..9229234ce55a8 100644
--- a/system/include/libcxx/chrono
+++ b/system/include/libcxx/chrono
@@ -926,6 +926,7 @@ public:
     static time_point from_time_t(time_t __t) _NOEXCEPT;
 };
 
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
 class _LIBCPP_TYPE_VIS steady_clock
 {
 public:
@@ -939,6 +940,9 @@ public:
 };
 
 typedef steady_clock high_resolution_clock;
+#else
+typedef system_clock high_resolution_clock;
+#endif
 
 } // chrono
 
diff --git a/system/include/libcxx/cmath b/system/include/libcxx/cmath
index 75087ae78fb45..4719abad3ca4d 100644
--- a/system/include/libcxx/cmath
+++ b/system/include/libcxx/cmath
@@ -316,9 +316,9 @@ long double    truncl(long double x);
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_signbit(_A1 __x) _NOEXCEPT
+__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT
 {
-    return signbit(__x);
+    return signbit(__lcpp_x);
 }
 
 #undef signbit
@@ -326,9 +326,9 @@ __libcpp_signbit(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-signbit(_A1 __x) _NOEXCEPT
+signbit(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_signbit((typename std::__promote<_A1>::type)__x);
+    return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // signbit
@@ -340,9 +340,9 @@ signbit(_A1 __x) _NOEXCEPT
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 int
-__libcpp_fpclassify(_A1 __x) _NOEXCEPT
+__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT
 {
-    return fpclassify(__x);
+    return fpclassify(__lcpp_x);
 }
 
 #undef fpclassify
@@ -350,9 +350,9 @@ __libcpp_fpclassify(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
-fpclassify(_A1 __x) _NOEXCEPT
+fpclassify(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__x);
+    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // fpclassify
@@ -364,9 +364,9 @@ fpclassify(_A1 __x) _NOEXCEPT
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isfinite(_A1 __x) _NOEXCEPT
+__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
 {
-    return isfinite(__x);
+    return isfinite(__lcpp_x);
 }
 
 #undef isfinite
@@ -374,9 +374,9 @@ __libcpp_isfinite(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isfinite(_A1 __x) _NOEXCEPT
+isfinite(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_isfinite((typename std::__promote<_A1>::type)__x);
+    return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // isfinite
@@ -388,9 +388,9 @@ isfinite(_A1 __x) _NOEXCEPT
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isinf(_A1 __x) _NOEXCEPT
+__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
 {
-    return isinf(__x);
+    return isinf(__lcpp_x);
 }
 
 #undef isinf
@@ -398,9 +398,9 @@ __libcpp_isinf(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isinf(_A1 __x) _NOEXCEPT
+isinf(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_isinf((typename std::__promote<_A1>::type)__x);
+    return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // isinf
@@ -412,9 +412,9 @@ isinf(_A1 __x) _NOEXCEPT
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isnan(_A1 __x) _NOEXCEPT
+__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
 {
-    return isnan(__x);
+    return isnan(__lcpp_x);
 }
 
 #undef isnan
@@ -422,9 +422,9 @@ __libcpp_isnan(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isnan(_A1 __x) _NOEXCEPT
+isnan(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_isnan((typename std::__promote<_A1>::type)__x);
+    return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // isnan
@@ -436,9 +436,9 @@ isnan(_A1 __x) _NOEXCEPT
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isnormal(_A1 __x) _NOEXCEPT
+__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT
 {
-    return isnormal(__x);
+    return isnormal(__lcpp_x);
 }
 
 #undef isnormal
@@ -446,9 +446,9 @@ __libcpp_isnormal(_A1 __x) _NOEXCEPT
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isnormal(_A1 __x) _NOEXCEPT
+isnormal(_A1 __lcpp_x) _NOEXCEPT
 {
-    return __libcpp_isnormal((typename std::__promote<_A1>::type)__x);
+    return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x);
 }
 
 #endif  // isnormal
@@ -460,9 +460,9 @@ isnormal(_A1 __x) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isgreater(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return isgreater(__x, __y);
+    return isgreater(__lcpp_x, __lcpp_y);
 }
 
 #undef isgreater
@@ -475,10 +475,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-isgreater(_A1 __x, _A2 __y) _NOEXCEPT
+isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isgreater((type)__x, (type)__y);
+    return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // isgreater
@@ -490,9 +490,9 @@ isgreater(_A1 __x, _A2 __y) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return isgreaterequal(__x, __y);
+    return isgreaterequal(__lcpp_x, __lcpp_y);
 }
 
 #undef isgreaterequal
@@ -505,10 +505,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
+isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isgreaterequal((type)__x, (type)__y);
+    return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // isgreaterequal
@@ -520,9 +520,9 @@ isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isless(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return isless(__x, __y);
+    return isless(__lcpp_x, __lcpp_y);
 }
 
 #undef isless
@@ -535,10 +535,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-isless(_A1 __x, _A2 __y) _NOEXCEPT
+isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isless((type)__x, (type)__y);
+    return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // isless
@@ -550,9 +550,9 @@ isless(_A1 __x, _A2 __y) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_islessequal(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return islessequal(__x, __y);
+    return islessequal(__lcpp_x, __lcpp_y);
 }
 
 #undef islessequal
@@ -565,10 +565,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-islessequal(_A1 __x, _A2 __y) _NOEXCEPT
+islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_islessequal((type)__x, (type)__y);
+    return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // islessequal
@@ -580,9 +580,9 @@ islessequal(_A1 __x, _A2 __y) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return islessgreater(__x, __y);
+    return islessgreater(__lcpp_x, __lcpp_y);
 }
 
 #undef islessgreater
@@ -595,10 +595,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
+islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_islessgreater((type)__x, (type)__y);
+    return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // islessgreater
@@ -610,9 +610,9 @@ islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isunordered(_A1 __x, _A2 __y) _NOEXCEPT
+__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
-    return isunordered(__x, __y);
+    return isunordered(__lcpp_x, __lcpp_y);
 }
 
 #undef isunordered
@@ -625,10 +625,10 @@ typename std::enable_if
     std::is_arithmetic<_A2>::value,
     bool
 >::type
-isunordered(_A1 __x, _A2 __y) _NOEXCEPT
+isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isunordered((type)__x, (type)__y);
+    return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y);
 }
 
 #endif  // isunordered
@@ -657,15 +657,15 @@ using ::double_t;
 #if !defined(_AIX)
 inline _LIBCPP_INLINE_VISIBILITY
 float
-abs(float __x) _NOEXCEPT {return fabsf(__x);}
+abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);}
 
 inline _LIBCPP_INLINE_VISIBILITY
 double
-abs(double __x) _NOEXCEPT {return fabs(__x);}
+abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);}
 
 inline _LIBCPP_INLINE_VISIBILITY
 long double
-abs(long double __x) _NOEXCEPT {return fabsl(__x);}
+abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
 #endif // !defined(_AIX)
 
 #ifndef __sun__
@@ -676,14 +676,14 @@ using ::acos;
 using ::acosf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       acos(float __x) _NOEXCEPT       {return acosf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) _NOEXCEPT {return acosl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       acos(float __lcpp_x) _NOEXCEPT       {return acosf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-acos(_A1 __x) _NOEXCEPT {return acos((double)__x);}
+acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);}
 
 // asin
 
@@ -691,14 +691,14 @@ using ::asin;
 using ::asinf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       asin(float __x) _NOEXCEPT       {return asinf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) _NOEXCEPT {return asinl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       asin(float __lcpp_x) _NOEXCEPT       {return asinf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-asin(_A1 __x) _NOEXCEPT {return asin((double)__x);}
+asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);}
 
 // atan
 
@@ -706,14 +706,14 @@ using ::atan;
 using ::atanf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       atan(float __x) _NOEXCEPT       {return atanf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) _NOEXCEPT {return atanl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       atan(float __lcpp_x) _NOEXCEPT       {return atanf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-atan(_A1 __x) _NOEXCEPT {return atan((double)__x);}
+atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);}
 
 // atan2
 
@@ -721,8 +721,8 @@ using ::atan2;
 using ::atan2f;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __y, float __x) _NOEXCEPT             {return atan2f(__y, __x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) _NOEXCEPT {return atan2l(__y, __x);}
+inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT             {return atan2f(__lcpp_y, __lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);}
 #endif
 
 template <class _A1, class _A2>
@@ -733,12 +733,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-atan2(_A1 __y, _A2 __x) _NOEXCEPT
+atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return atan2((__result_type)__y, (__result_type)__x);
+    return atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x);
 }
 
 // ceil
@@ -747,14 +747,14 @@ using ::ceil;
 using ::ceilf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __x) _NOEXCEPT       {return ceilf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) _NOEXCEPT {return ceill(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __lcpp_x) _NOEXCEPT       {return ceilf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-ceil(_A1 __x) _NOEXCEPT {return ceil((double)__x);}
+ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);}
 
 // cos
 
@@ -762,14 +762,14 @@ using ::cos;
 using ::cosf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       cos(float __x) _NOEXCEPT       {return cosf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) _NOEXCEPT {return cosl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       cos(float __lcpp_x) _NOEXCEPT       {return cosf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return cosl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cos(_A1 __x) _NOEXCEPT {return cos((double)__x);}
+cos(_A1 __lcpp_x) _NOEXCEPT {return cos((double)__lcpp_x);}
 
 // cosh
 
@@ -777,14 +777,14 @@ using ::cosh;
 using ::coshf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __x) _NOEXCEPT       {return coshf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) _NOEXCEPT {return coshl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __lcpp_x) _NOEXCEPT       {return coshf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return coshl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cosh(_A1 __x) _NOEXCEPT {return cosh((double)__x);}
+cosh(_A1 __lcpp_x) _NOEXCEPT {return cosh((double)__lcpp_x);}
 
 #endif // __sun__
 // exp
@@ -795,15 +795,15 @@ using ::expf;
 #ifndef __sun__
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       exp(float __x) _NOEXCEPT       {return expf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) _NOEXCEPT {return expl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       exp(float __lcpp_x) _NOEXCEPT       {return expf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return expl(__lcpp_x);}
 #endif
 
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-exp(_A1 __x) _NOEXCEPT {return exp((double)__x);}
+exp(_A1 __lcpp_x) _NOEXCEPT {return exp((double)__lcpp_x);}
 
 // fabs
 
@@ -811,14 +811,14 @@ using ::fabs;
 using ::fabsf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __x) _NOEXCEPT       {return fabsf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) _NOEXCEPT {return fabsl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __lcpp_x) _NOEXCEPT       {return fabsf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-fabs(_A1 __x) _NOEXCEPT {return fabs((double)__x);}
+fabs(_A1 __lcpp_x) _NOEXCEPT {return fabs((double)__lcpp_x);}
 
 // floor
 
@@ -826,14 +826,14 @@ using ::floor;
 using ::floorf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       floor(float __x) _NOEXCEPT       {return floorf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) _NOEXCEPT {return floorl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       floor(float __lcpp_x) _NOEXCEPT       {return floorf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return floorl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-floor(_A1 __x) _NOEXCEPT {return floor((double)__x);}
+floor(_A1 __lcpp_x) _NOEXCEPT {return floor((double)__lcpp_x);}
 
 // fmod
 
@@ -843,8 +843,8 @@ using ::fmodf;
 #ifndef __sun__
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __x, float __y) _NOEXCEPT             {return fmodf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) _NOEXCEPT {return fmodl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmodf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmodl(__lcpp_x, __lcpp_y);}
 #endif
 
 template <class _A1, class _A2>
@@ -855,12 +855,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmod(_A1 __x, _A2 __y) _NOEXCEPT
+fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return fmod((__result_type)__x, (__result_type)__y);
+    return fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 
@@ -870,14 +870,14 @@ using ::frexp;
 using ::frexpf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __x, int* __e) _NOEXCEPT       {return frexpf(__x, __e);}
-inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) _NOEXCEPT {return frexpl(__x, __e);}
+inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT       {return frexpf(__lcpp_x, __lcpp_e);}
+inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpl(__lcpp_x, __lcpp_e);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-frexp(_A1 __x, int* __e) _NOEXCEPT {return frexp((double)__x, __e);}
+frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexp((double)__lcpp_x, __lcpp_e);}
 
 // ldexp
 
@@ -885,14 +885,14 @@ using ::ldexp;
 using ::ldexpf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __x, int __e) _NOEXCEPT       {return ldexpf(__x, __e);}
-inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) _NOEXCEPT {return ldexpl(__x, __e);}
+inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT       {return ldexpf(__lcpp_x, __lcpp_e);}
+inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpl(__lcpp_x, __lcpp_e);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-ldexp(_A1 __x, int __e) _NOEXCEPT {return ldexp((double)__x, __e);}
+ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexp((double)__lcpp_x, __lcpp_e);}
 
 // log
 
@@ -902,14 +902,14 @@ using ::logf;
 #ifndef __sun__
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       log(float __x) _NOEXCEPT       {return logf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) _NOEXCEPT {return logl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       log(float __lcpp_x) _NOEXCEPT       {return logf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return logl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log(_A1 __x) _NOEXCEPT {return log((double)__x);}
+log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x);}
 
 
 // log10
@@ -918,14 +918,14 @@ using ::log10;
 using ::log10f;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       log10(float __x) _NOEXCEPT       {return log10f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) _NOEXCEPT {return log10l(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       log10(float __lcpp_x) _NOEXCEPT       {return log10f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return log10l(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log10(_A1 __x) _NOEXCEPT {return log10((double)__x);}
+log10(_A1 __lcpp_x) _NOEXCEPT {return log10((double)__lcpp_x);}
 
 // modf
 
@@ -933,8 +933,8 @@ using ::modf;
 using ::modff;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       modf(float __x, float* __y) _NOEXCEPT             {return modff(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) _NOEXCEPT {return modfl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT             {return modff(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return modfl(__lcpp_x, __lcpp_y);}
 #endif
 
 // pow
@@ -946,8 +946,8 @@ using ::powf;
 #ifndef __sun__
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       pow(float __x, float __y) _NOEXCEPT             {return powf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) _NOEXCEPT {return powl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return powf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return powl(__lcpp_x, __lcpp_y);}
 #endif
 
 template <class _A1, class _A2>
@@ -958,29 +958,28 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-pow(_A1 __x, _A2 __y) _NOEXCEPT
+pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return pow((__result_type)__x, (__result_type)__y);
+    return pow((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
-
 // sin
 
 using ::sin;
 using ::sinf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sin(float __x) _NOEXCEPT       {return sinf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) _NOEXCEPT {return sinl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       sin(float __lcpp_x) _NOEXCEPT       {return sinf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return sinl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sin(_A1 __x) _NOEXCEPT {return sin((double)__x);}
+sin(_A1 __lcpp_x) _NOEXCEPT {return sin((double)__lcpp_x);}
 
 // sinh
 
@@ -988,14 +987,14 @@ using ::sinh;
 using ::sinhf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __x) _NOEXCEPT       {return sinhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) _NOEXCEPT {return sinhl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __lcpp_x) _NOEXCEPT       {return sinhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return sinhl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sinh(_A1 __x) _NOEXCEPT {return sinh((double)__x);}
+sinh(_A1 __lcpp_x) _NOEXCEPT {return sinh((double)__lcpp_x);}
 
 // sqrt
 
@@ -1005,14 +1004,14 @@ using ::sqrtf;
 
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(__sun__) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __x) _NOEXCEPT       {return sqrtf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) _NOEXCEPT {return sqrtl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __lcpp_x) _NOEXCEPT       {return sqrtf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return sqrtl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sqrt(_A1 __x) _NOEXCEPT {return sqrt((double)__x);}
+sqrt(_A1 __lcpp_x) _NOEXCEPT {return sqrt((double)__lcpp_x);}
 
 // tan
 
@@ -1021,14 +1020,14 @@ using ::tanf;
 #ifndef __sun__
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       tan(float __x) _NOEXCEPT       {return tanf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) _NOEXCEPT {return tanl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       tan(float __lcpp_x) _NOEXCEPT       {return tanf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return tanl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tan(_A1 __x) _NOEXCEPT {return tan((double)__x);}
+tan(_A1 __lcpp_x) _NOEXCEPT {return tan((double)__lcpp_x);}
 
 // tanh
 
@@ -1036,14 +1035,14 @@ using ::tanh;
 using ::tanhf;
 
 #if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __x) _NOEXCEPT       {return tanhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) _NOEXCEPT {return tanhl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __lcpp_x) _NOEXCEPT       {return tanhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return tanhl(__lcpp_x);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tanh(_A1 __x) _NOEXCEPT {return tanh((double)__x);}
+tanh(_A1 __lcpp_x) _NOEXCEPT {return tanh((double)__lcpp_x);}
 
 // acosh
 
@@ -1051,13 +1050,13 @@ tanh(_A1 __x) _NOEXCEPT {return tanh((double)__x);}
 using ::acosh;
 using ::acoshf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __x) _NOEXCEPT       {return acoshf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __x) _NOEXCEPT {return acoshl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __lcpp_x) _NOEXCEPT       {return acoshf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-acosh(_A1 __x) _NOEXCEPT {return acosh((double)__x);}
+acosh(_A1 __lcpp_x) _NOEXCEPT {return acosh((double)__lcpp_x);}
 #endif
 
 // asinh
@@ -1066,13 +1065,13 @@ acosh(_A1 __x) _NOEXCEPT {return acosh((double)__x);}
 using ::asinh;
 using ::asinhf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __x) _NOEXCEPT       {return asinhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __x) _NOEXCEPT {return asinhl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __lcpp_x) _NOEXCEPT       {return asinhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-asinh(_A1 __x) _NOEXCEPT {return asinh((double)__x);}
+asinh(_A1 __lcpp_x) _NOEXCEPT {return asinh((double)__lcpp_x);}
 #endif
 
 // atanh
@@ -1081,13 +1080,13 @@ asinh(_A1 __x) _NOEXCEPT {return asinh((double)__x);}
 using ::atanh;
 using ::atanhf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __x) _NOEXCEPT       {return atanhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __x) _NOEXCEPT {return atanhl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __lcpp_x) _NOEXCEPT       {return atanhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-atanh(_A1 __x) _NOEXCEPT {return atanh((double)__x);}
+atanh(_A1 __lcpp_x) _NOEXCEPT {return atanh((double)__lcpp_x);}
 #endif
 
 // cbrt
@@ -1096,13 +1095,13 @@ atanh(_A1 __x) _NOEXCEPT {return atanh((double)__x);}
 using ::cbrt;
 using ::cbrtf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __x) _NOEXCEPT       {return cbrtf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __x) _NOEXCEPT {return cbrtl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __lcpp_x) _NOEXCEPT       {return cbrtf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cbrt(_A1 __x) _NOEXCEPT {return cbrt((double)__x);}
+cbrt(_A1 __lcpp_x) _NOEXCEPT {return cbrt((double)__lcpp_x);}
 #endif
 
 // copysign
@@ -1110,8 +1109,8 @@ cbrt(_A1 __x) _NOEXCEPT {return cbrt((double)__x);}
 using ::copysign;
 using ::copysignf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       copysign(float __x, float __y) _NOEXCEPT             {return copysignf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __x, long double __y) _NOEXCEPT {return copysignl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       copysign(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return copysignf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return copysignl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1121,12 +1120,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-copysign(_A1 __x, _A2 __y) _NOEXCEPT
+copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return copysign((__result_type)__x, (__result_type)__y);
+    return copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 #ifndef _LIBCPP_MSVCRT
@@ -1136,60 +1135,60 @@ copysign(_A1 __x, _A2 __y) _NOEXCEPT
 using ::erf;
 using ::erff;
 
-inline _LIBCPP_INLINE_VISIBILITY float       erf(float __x) _NOEXCEPT       {return erff(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __x) _NOEXCEPT {return erfl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       erf(float __lcpp_x) _NOEXCEPT       {return erff(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return erfl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-erf(_A1 __x) _NOEXCEPT {return erf((double)__x);}
+erf(_A1 __lcpp_x) _NOEXCEPT {return erf((double)__lcpp_x);}
 
 // erfc
 
 using ::erfc;
 using ::erfcf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __x) _NOEXCEPT       {return erfcf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __x) _NOEXCEPT {return erfcl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __lcpp_x) _NOEXCEPT       {return erfcf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return erfcl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-erfc(_A1 __x) _NOEXCEPT {return erfc((double)__x);}
+erfc(_A1 __lcpp_x) _NOEXCEPT {return erfc((double)__lcpp_x);}
 
 // exp2
 
 using ::exp2;
 using ::exp2f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __x) _NOEXCEPT       {return exp2f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __x) _NOEXCEPT {return exp2l(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __lcpp_x) _NOEXCEPT       {return exp2f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return exp2l(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-exp2(_A1 __x) _NOEXCEPT {return exp2((double)__x);}
+exp2(_A1 __lcpp_x) _NOEXCEPT {return exp2((double)__lcpp_x);}
 
 // expm1
 
 using ::expm1;
 using ::expm1f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __x) _NOEXCEPT       {return expm1f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __x) _NOEXCEPT {return expm1l(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __lcpp_x) _NOEXCEPT       {return expm1f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return expm1l(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-expm1(_A1 __x) _NOEXCEPT {return expm1((double)__x);}
+expm1(_A1 __lcpp_x) _NOEXCEPT {return expm1((double)__lcpp_x);}
 
 // fdim
 
 using ::fdim;
 using ::fdimf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __x, float __y) _NOEXCEPT             {return fdimf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __x, long double __y) _NOEXCEPT {return fdiml(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fdimf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fdiml(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1199,25 +1198,21 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fdim(_A1 __x, _A2 __y) _NOEXCEPT
+fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return fdim((__result_type)__x, (__result_type)__y);
+    return fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // fma
 
-inline _LIBCPP_INLINE_VISIBILITY float fmaf(float __x, float __y, float __z) _NOEXCEPT {return (float)((double)__x*__y + __z);}
-#ifndef FP_FAST_FMAF
-#define FP_FAST_FMAF
-#endif
-
+using ::fmaf;
 using ::fma;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fma(float __x, float __y, float __z) _NOEXCEPT                   {return fmaf(__x, __y, __z);}
-inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __x, long double __y, long double __z) _NOEXCEPT {return fmal(__x, __y, __z);}
+inline _LIBCPP_INLINE_VISIBILITY float       fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT                   {return fmaf(__lcpp_x, __lcpp_y, __lcpp_z);}
+inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return fmal(__lcpp_x, __lcpp_y, __lcpp_z);}
 
 template <class _A1, class _A2, class _A3>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1228,13 +1223,13 @@ typename enable_if
     is_arithmetic<_A3>::value,
     typename __promote<_A1, _A2, _A3>::type
 >::type
-fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
+fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2, _A3>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value &&
                       is_same<_A3, __result_type>::value)), "");
-    return fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
+    return fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
 }
 
 // fmax
@@ -1242,8 +1237,8 @@ fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
 using ::fmax;
 using ::fmaxf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __x, float __y) _NOEXCEPT             {return fmaxf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __x, long double __y) _NOEXCEPT {return fmaxl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmaxf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmaxl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1253,12 +1248,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmax(_A1 __x, _A2 __y) _NOEXCEPT
+fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return fmax((__result_type)__x, (__result_type)__y);
+    return fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // fmin
@@ -1266,8 +1261,8 @@ fmax(_A1 __x, _A2 __y) _NOEXCEPT
 using ::fmin;
 using ::fminf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __x, float __y) _NOEXCEPT             {return fminf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __x, long double __y) _NOEXCEPT {return fminl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fminf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fminl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1277,12 +1272,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmin(_A1 __x, _A2 __y) _NOEXCEPT
+fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return fmin((__result_type)__x, (__result_type)__y);
+    return fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // hypot
@@ -1290,8 +1285,8 @@ fmin(_A1 __x, _A2 __y) _NOEXCEPT
 using ::hypot;
 using ::hypotf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __x, float __y) _NOEXCEPT             {return hypotf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __x, long double __y) _NOEXCEPT {return hypotl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return hypotf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return hypotl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1301,12 +1296,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-hypot(_A1 __x, _A2 __y) _NOEXCEPT
+hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return hypot((__result_type)__x, (__result_type)__y);
+    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // ilogb
@@ -1314,27 +1309,27 @@ hypot(_A1 __x, _A2 __y) _NOEXCEPT
 using ::ilogb;
 using ::ilogbf;
 
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __x) _NOEXCEPT       {return ilogbf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __x) _NOEXCEPT {return ilogbl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT       {return ilogbf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ilogbl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, int>::type
-ilogb(_A1 __x) _NOEXCEPT {return ilogb((double)__x);}
+ilogb(_A1 __lcpp_x) _NOEXCEPT {return ilogb((double)__lcpp_x);}
 
 // lgamma
 
 using ::lgamma;
 using ::lgammaf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __x) _NOEXCEPT       {return lgammaf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __x) _NOEXCEPT {return lgammal(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __lcpp_x) _NOEXCEPT       {return lgammaf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return lgammal(__lcpp_x);}
 
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-lgamma(_A1 __x) _NOEXCEPT {return lgamma((double)__x);}
+lgamma(_A1 __lcpp_x) _NOEXCEPT {return lgamma((double)__lcpp_x);}
 
 
 // llrint
@@ -1342,91 +1337,91 @@ lgamma(_A1 __x) _NOEXCEPT {return lgamma((double)__x);}
 using ::llrint;
 using ::llrintf;
 
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __x) _NOEXCEPT       {return llrintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __x) _NOEXCEPT {return llrintl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT       {return llrintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return llrintl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long long>::type
-llrint(_A1 __x) _NOEXCEPT {return llrint((double)__x);}
+llrint(_A1 __lcpp_x) _NOEXCEPT {return llrint((double)__lcpp_x);}
 
 // llround
 
 using ::llround;
 using ::llroundf;
 
-inline _LIBCPP_INLINE_VISIBILITY long long llround(float __x) _NOEXCEPT       {return llroundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __x) _NOEXCEPT {return llroundl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT       {return llroundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return llroundl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long long>::type
-llround(_A1 __x) _NOEXCEPT {return llround((double)__x);}
+llround(_A1 __lcpp_x) _NOEXCEPT {return llround((double)__lcpp_x);}
 
 // log1p
 
 using ::log1p;
 using ::log1pf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __x) _NOEXCEPT       {return log1pf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __x) _NOEXCEPT {return log1pl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __lcpp_x) _NOEXCEPT       {return log1pf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return log1pl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log1p(_A1 __x) _NOEXCEPT {return log1p((double)__x);}
+log1p(_A1 __lcpp_x) _NOEXCEPT {return log1p((double)__lcpp_x);}
 
 // log2
 
 using ::log2;
 using ::log2f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       log2(float __x) _NOEXCEPT       {return log2f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __x) _NOEXCEPT {return log2l(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       log2(float __lcpp_x) _NOEXCEPT       {return log2f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return log2l(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log2(_A1 __x) _NOEXCEPT {return log2((double)__x);}
+log2(_A1 __lcpp_x) _NOEXCEPT {return log2((double)__lcpp_x);}
 
 // logb
 
 using ::logb;
 using ::logbf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       logb(float __x) _NOEXCEPT       {return logbf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __x) _NOEXCEPT {return logbl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       logb(float __lcpp_x) _NOEXCEPT       {return logbf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return logbl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-logb(_A1 __x) _NOEXCEPT {return logb((double)__x);}
+logb(_A1 __lcpp_x) _NOEXCEPT {return logb((double)__lcpp_x);}
 
 // lrint
 
 using ::lrint;
 using ::lrintf;
 
-inline _LIBCPP_INLINE_VISIBILITY long lrint(float __x) _NOEXCEPT       {return lrintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __x) _NOEXCEPT {return lrintl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT       {return lrintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return lrintl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long>::type
-lrint(_A1 __x) _NOEXCEPT {return lrint((double)__x);}
+lrint(_A1 __lcpp_x) _NOEXCEPT {return lrint((double)__lcpp_x);}
 
 // lround
 
 using ::lround;
 using ::lroundf;
 
-inline _LIBCPP_INLINE_VISIBILITY long lround(float __x) _NOEXCEPT       {return lroundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long lround(long double __x) _NOEXCEPT {return lroundl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT       {return lroundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return lroundl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long>::type
-lround(_A1 __x) _NOEXCEPT {return lround((double)__x);}
+lround(_A1 __lcpp_x) _NOEXCEPT {return lround((double)__lcpp_x);}
 
 #endif // _LIBCPP_MSVCRT
 #endif // __sun__
@@ -1446,21 +1441,21 @@ using ::nanf;
 using ::nearbyint;
 using ::nearbyintf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __x) _NOEXCEPT       {return nearbyintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __x) _NOEXCEPT {return nearbyintl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __lcpp_x) _NOEXCEPT       {return nearbyintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return nearbyintl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-nearbyint(_A1 __x) _NOEXCEPT {return nearbyint((double)__x);}
+nearbyint(_A1 __lcpp_x) _NOEXCEPT {return nearbyint((double)__lcpp_x);}
 
 // nextafter
 
 using ::nextafter;
 using ::nextafterf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __x, float __y) _NOEXCEPT             {return nextafterf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __x, long double __y) _NOEXCEPT {return nextafterl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return nextafterf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nextafterl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1470,12 +1465,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-nextafter(_A1 __x, _A2 __y) _NOEXCEPT
+nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return nextafter((__result_type)__x, (__result_type)__y);
+    return nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // nexttoward
@@ -1483,21 +1478,21 @@ nextafter(_A1 __x, _A2 __y) _NOEXCEPT
 using ::nexttoward;
 using ::nexttowardf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __x, long double __y) _NOEXCEPT       {return nexttowardf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __x, long double __y) _NOEXCEPT {return nexttowardl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT       {return nexttowardf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardl(__lcpp_x, __lcpp_y);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-nexttoward(_A1 __x, long double __y) _NOEXCEPT {return nexttoward((double)__x, __y);}
+nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttoward((double)__lcpp_x, __lcpp_y);}
 
 // remainder
 
 using ::remainder;
 using ::remainderf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __x, float __y) _NOEXCEPT             {return remainderf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) _NOEXCEPT {return remainderl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return remainderf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return remainderl(__lcpp_x, __lcpp_y);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1507,12 +1502,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-remainder(_A1 __x, _A2 __y) _NOEXCEPT
+remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return remainder((__result_type)__x, (__result_type)__y);
+    return remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
 // remquo
@@ -1520,8 +1515,8 @@ remainder(_A1 __x, _A2 __y) _NOEXCEPT
 using ::remquo;
 using ::remquof;
 
-inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __x, float __y, int* __z) _NOEXCEPT             {return remquof(__x, __y, __z);}
-inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __x, long double __y, int* __z) _NOEXCEPT {return remquol(__x, __y, __z);}
+inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT             {return remquof(__lcpp_x, __lcpp_y, __lcpp_z);}
+inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquol(__lcpp_x, __lcpp_y, __lcpp_z);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1531,12 +1526,12 @@ typename enable_if
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
+remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
                       is_same<_A2, __result_type>::value)), "");
-    return remquo((__result_type)__x, (__result_type)__y, __z);
+    return remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z);
 }
 
 // rint
@@ -1544,78 +1539,78 @@ remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
 using ::rint;
 using ::rintf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       rint(float __x) _NOEXCEPT       {return rintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __x) _NOEXCEPT {return rintl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       rint(float __lcpp_x) _NOEXCEPT       {return rintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return rintl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-rint(_A1 __x) _NOEXCEPT {return rint((double)__x);}
+rint(_A1 __lcpp_x) _NOEXCEPT {return rint((double)__lcpp_x);}
 
 // round
 
 using ::round;
 using ::roundf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       round(float __x) _NOEXCEPT       {return roundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) _NOEXCEPT {return roundl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       round(float __lcpp_x) _NOEXCEPT       {return roundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return roundl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-round(_A1 __x) _NOEXCEPT {return round((double)__x);}
+round(_A1 __lcpp_x) _NOEXCEPT {return round((double)__lcpp_x);}
 
 // scalbln
 
 using ::scalbln;
 using ::scalblnf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __x, long __y) _NOEXCEPT       {return scalblnf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __x, long __y) _NOEXCEPT {return scalblnl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT       {return scalblnf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnl(__lcpp_x, __lcpp_y);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-scalbln(_A1 __x, long __y) _NOEXCEPT {return scalbln((double)__x, __y);}
+scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalbln((double)__lcpp_x, __lcpp_y);}
 
 // scalbn
 
 using ::scalbn;
 using ::scalbnf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __x, int __y) _NOEXCEPT       {return scalbnf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __x, int __y) _NOEXCEPT {return scalbnl(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT       {return scalbnf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnl(__lcpp_x, __lcpp_y);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-scalbn(_A1 __x, int __y) _NOEXCEPT {return scalbn((double)__x, __y);}
+scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbn((double)__lcpp_x, __lcpp_y);}
 
 // tgamma
 
 using ::tgamma;
 using ::tgammaf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __x) _NOEXCEPT       {return tgammaf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __x) _NOEXCEPT {return tgammal(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __lcpp_x) _NOEXCEPT       {return tgammaf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return tgammal(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tgamma(_A1 __x) _NOEXCEPT {return tgamma((double)__x);}
+tgamma(_A1 __lcpp_x) _NOEXCEPT {return tgamma((double)__lcpp_x);}
 
 // trunc
 
 using ::trunc;
 using ::truncf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __x) _NOEXCEPT       {return truncf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __x) _NOEXCEPT {return truncl(__x);}
+inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __lcpp_x) _NOEXCEPT       {return truncf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return truncl(__lcpp_x);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-trunc(_A1 __x) _NOEXCEPT {return trunc((double)__x);}
+trunc(_A1 __lcpp_x) _NOEXCEPT {return trunc((double)__lcpp_x);}
 
 #endif // !_LIBCPP_MSVCRT
 
diff --git a/system/include/libcxx/condition_variable b/system/include/libcxx/condition_variable
index dc67266a97b5b..1af2484abd7bc 100644
--- a/system/include/libcxx/condition_variable
+++ b/system/include/libcxx/condition_variable
@@ -115,6 +115,8 @@ public:
 #pragma GCC system_header
 #endif
 
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 class _LIBCPP_TYPE_VIS condition_variable_any
@@ -253,4 +255,6 @@ void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_CONDITION_VARIABLE
diff --git a/system/include/libcxx/cstddef b/system/include/libcxx/cstddef
index 7ef16ff2a367c..c3ca64a9c0149 100644
--- a/system/include/libcxx/cstddef
+++ b/system/include/libcxx/cstddef
@@ -35,12 +35,6 @@ Types:
 
 #include <__config>
 
-#ifdef __GLIBC__
-#define __need_NULL
-#define __need_ptrdiff_t
-#define __need_size_t
-#endif  // __GLIBC__
-
 #include <stddef.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -52,7 +46,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 using ::ptrdiff_t;
 using ::size_t;
 
+#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T)
+// Re-use the compiler's <stddef.h> max_align_t where possible.
+using ::max_align_t;
+#else
 typedef long double max_align_t;
+#endif
 
 #ifdef _LIBCPP_HAS_NO_NULLPTR
 
diff --git a/system/include/libcxx/deque b/system/include/libcxx/deque
index f099000b137c6..9b256b74d4f2c 100644
--- a/system/include/libcxx/deque
+++ b/system/include/libcxx/deque
@@ -1208,7 +1208,7 @@ public:
     deque()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
         {}
-    _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {}
+    _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {}
     explicit deque(size_type __n);
 #if _LIBCPP_STD_VER > 11
     explicit deque(size_type __n, const _Allocator& __a);
diff --git a/system/include/libcxx/experimental/__config b/system/include/libcxx/experimental/__config
new file mode 100644
index 0000000000000..684a3b4d83d86
--- /dev/null
+++ b/system/include/libcxx/experimental/__config
@@ -0,0 +1,24 @@
+// -*- C++ -*-
+//===--------------------------- __config ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL_CONFIG
+#define _LIBCPP_EXPERIMENTAL_CONFIG
+
+#include <__config>
+
+#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
+#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL  } }
+#define _VSTD_EXPERIMENTAL std::experimental
+
+#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
+#define _LIBCPP_END_NAMESPACE_LFTS  } } }
+#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1
+
+#endif
diff --git a/system/include/libcxx/experimental/dynarray b/system/include/libcxx/experimental/dynarray
index 7c5c9b3f1b7bd..0bc8dfe2cb7ba 100644
--- a/system/include/libcxx/experimental/dynarray
+++ b/system/include/libcxx/experimental/dynarray
@@ -38,18 +38,18 @@ class dynarray
 public:
     // construct/copy/destroy:
     explicit dynarray(size_type c);
-    template <typename Alloc>
-      dynarray(size_type c, const Alloc& alloc);
     dynarray(size_type c, const T& v);
-    template <typename Alloc>
-      dynarray(size_type c, const T& v, const Alloc& alloc);
     dynarray(const dynarray& d);
-    template <typename Alloc>
-      dynarray(const dynarray& d, const Alloc& alloc);
     dynarray(initializer_list<T>);
-    template <typename Alloc>
-      dynarray(initializer_list<T>, const Alloc& alloc);
 
+    template <class Alloc>
+      dynarray(allocator_arg_t, const Alloc& a, size_type c, const Alloc& alloc);
+    template <class Alloc>
+      dynarray(allocator_arg_t, const Alloc& a, size_type c, const T& v, const Alloc& alloc);
+    template <class Alloc>
+      dynarray(allocator_arg_t, const Alloc& a, const dynarray& d, const Alloc& alloc);
+    template <class Alloc>
+      dynarray(allocator_arg_t, const Alloc& a, initializer_list<T>, const Alloc& alloc);
     dynarray& operator=(const dynarray&) = delete;
     ~dynarray();
 
@@ -147,12 +147,12 @@ private:
             assert(!"dynarray::allocation");
 #endif
         }
-        return static_cast<value_type *> (::operator new (sizeof(value_type) * count));
+        return static_cast<value_type *> (_VSTD::__allocate (sizeof(value_type) * count));
     }
 
     static inline _LIBCPP_INLINE_VISIBILITY void __deallocate ( value_type* __ptr ) noexcept
     {
-        ::operator delete (static_cast<void *> (__ptr));
+        _VSTD::__deallocate (static_cast<void *> (__ptr));
     }
 
 public:
@@ -163,15 +163,15 @@ public:
     dynarray(initializer_list<value_type>);
 
 //  We're not implementing these right now.
-//  Waiting for the resolution of LWG issue #2235
+//  Updated with the resolution of LWG issue #2255
 //     template <typename _Alloc>
-//       dynarray(size_type __c, const _Alloc& __alloc);
+//       dynarray(allocator_arg_t, const _Alloc& __alloc, size_type __c);
 //     template <typename _Alloc>
-//       dynarray(size_type __c, const value_type& __v, const _Alloc& __alloc);
+//       dynarray(allocator_arg_t, const _Alloc& __alloc, size_type __c, const value_type& __v);
 //     template <typename _Alloc>
-//       dynarray(const dynarray& __d, const _Alloc& __alloc);
+//       dynarray(allocator_arg_t, const _Alloc& __alloc, const dynarray& __d);
 //     template <typename _Alloc>
-//       dynarray(initializer_list<value_type>, const _Alloc& __alloc);
+//       dynarray(allocator_arg_t, const _Alloc& __alloc, initializer_list<value_type>);
 
     dynarray& operator=(const dynarray&) = delete;
     ~dynarray();
diff --git a/system/include/libcxx/experimental/optional b/system/include/libcxx/experimental/optional
index 3848da872b8bc..41d86b4a16954 100644
--- a/system/include/libcxx/experimental/optional
+++ b/system/include/libcxx/experimental/optional
@@ -151,11 +151,7 @@ public:
 
 #include <__undef_min_max>
 
-#ifdef _LIBCPP_DEBUG
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
+#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
diff --git a/system/include/libcxx/experimental/string_view b/system/include/libcxx/experimental/string_view
new file mode 100644
index 0000000000000..b0382e5d2570f
--- /dev/null
+++ b/system/include/libcxx/experimental/string_view
@@ -0,0 +1,816 @@
+// -*- C++ -*-
+//===------------------------ string_view ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_LFTS_STRING_VIEW
+#define _LIBCPP_LFTS_STRING_VIEW
+
+/*
+string_view synopsis
+
+namespace std {
+ namespace experimental {
+  inline namespace library_fundamentals_v1 {
+
+    // 7.2, Class template basic_string_view
+    template<class charT, class traits = char_traits<charT>>
+        class basic_string_view;
+
+    // 7.9, basic_string_view non-member comparison functions
+    template<class charT, class traits>
+    constexpr bool operator==(basic_string_view<charT, traits> x,
+                              basic_string_view<charT, traits> y) noexcept;
+    template<class charT, class traits>
+    constexpr bool operator!=(basic_string_view<charT, traits> x,
+                              basic_string_view<charT, traits> y) noexcept;
+    template<class charT, class traits>
+    constexpr bool operator< (basic_string_view<charT, traits> x,
+                                 basic_string_view<charT, traits> y) noexcept;
+    template<class charT, class traits>
+    constexpr bool operator> (basic_string_view<charT, traits> x,
+                              basic_string_view<charT, traits> y) noexcept;
+    template<class charT, class traits>
+    constexpr bool operator<=(basic_string_view<charT, traits> x,
+                                 basic_string_view<charT, traits> y) noexcept;
+    template<class charT, class traits>
+    constexpr bool operator>=(basic_string_view<charT, traits> x,
+                              basic_string_view<charT, traits> y) noexcept;
+    // see below, sufficient additional overloads of comparison functions
+
+    // 7.10, Inserters and extractors
+    template<class charT, class traits>
+      basic_ostream<charT, traits>&
+        operator<<(basic_ostream<charT, traits>& os,
+                   basic_string_view<charT, traits> str);
+
+    // basic_string_view typedef names
+    typedef basic_string_view<char> string_view;
+    typedef basic_string_view<char16_t> u16string_view;
+    typedef basic_string_view<char32_t> u32string_view;
+    typedef basic_string_view<wchar_t> wstring_view;
+
+    template<class charT, class traits = char_traits<charT>>
+    class basic_string_view {
+      public:
+      // types
+      typedef traits traits_type;
+      typedef charT value_type;
+      typedef charT* pointer;
+      typedef const charT* const_pointer;
+      typedef charT& reference;
+      typedef const charT& const_reference;
+      typedef implementation-defined const_iterator;
+      typedef const_iterator iterator;
+      typedef reverse_iterator<const_iterator> const_reverse_iterator;
+      typedef const_reverse_iterator reverse_iterator;
+      typedef size_t size_type;
+      typedef ptrdiff_t difference_type;
+      static constexpr size_type npos = size_type(-1);
+
+      // 7.3, basic_string_view constructors and assignment operators
+      constexpr basic_string_view() noexcept;
+      constexpr basic_string_view(const basic_string_view&) noexcept = default;
+      basic_string_view& operator=(const basic_string_view&) noexcept = default;
+      template<class Allocator>
+      basic_string_view(const basic_string<charT, traits, Allocator>& str) noexcept;
+      constexpr basic_string_view(const charT* str);
+      constexpr basic_string_view(const charT* str, size_type len);
+
+      // 7.4, basic_string_view iterator support
+      constexpr const_iterator begin() const noexcept;
+      constexpr const_iterator end() const noexcept;
+      constexpr const_iterator cbegin() const noexcept;
+      constexpr const_iterator cend() const noexcept;
+      const_reverse_iterator rbegin() const noexcept;
+      const_reverse_iterator rend() const noexcept;
+      const_reverse_iterator crbegin() const noexcept;
+      const_reverse_iterator crend() const noexcept;
+
+      // 7.5, basic_string_view capacity
+      constexpr size_type size() const noexcept;
+      constexpr size_type length() const noexcept;
+      constexpr size_type max_size() const noexcept;
+      constexpr bool empty() const noexcept;
+
+      // 7.6, basic_string_view element access
+      constexpr const_reference operator[](size_type pos) const;
+      constexpr const_reference at(size_type pos) const;
+      constexpr const_reference front() const;
+      constexpr const_reference back() const;
+      constexpr const_pointer data() const noexcept;
+
+      // 7.7, basic_string_view modifiers
+      constexpr void clear() noexcept;
+      constexpr void remove_prefix(size_type n);
+      constexpr void remove_suffix(size_type n);
+      constexpr void swap(basic_string_view& s) noexcept;
+
+      // 7.8, basic_string_view string operations
+      template<class Allocator>
+      explicit operator basic_string<charT, traits, Allocator>() const;
+      template<class Allocator = allocator<charT>>
+      basic_string<charT, traits, Allocator> to_string(
+        const Allocator& a = Allocator()) const;
+
+      size_type copy(charT* s, size_type n, size_type pos = 0) const;
+
+      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
+      constexpr int compare(basic_string_view s) const noexcept;
+      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
+      constexpr int compare(size_type pos1, size_type n1,
+                            basic_string_view s, size_type pos2, size_type n2) const;
+      constexpr int compare(const charT* s) const;
+      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
+      constexpr int compare(size_type pos1, size_type n1,
+                            const charT* s, size_type n2) const;
+      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
+      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
+      constexpr size_type find(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type find(const charT* s, size_type pos = 0) const;
+      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
+      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
+      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type rfind(const charT* s, size_type pos = npos) const;
+      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
+      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
+      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
+      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
+      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
+      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
+      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
+      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
+      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
+      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
+      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
+      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
+      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
+
+     private:
+      const_pointer data_;  // exposition only
+      size_type     size_;  // exposition only
+    };
+
+  }  // namespace fundamentals_v1
+ }  // namespace experimental
+
+  // 7.11, Hash support
+  template <class T> struct hash;
+  template <> struct hash<experimental::string_view>;
+  template <> struct hash<experimental::u16string_view>;
+  template <> struct hash<experimental::u32string_view>;
+  template <> struct hash<experimental::wstring_view>;
+
+}  // namespace std
+
+
+*/
+
+#include <experimental/__config>
+
+#include <string>
+#include <algorithm>
+#include <iterator>
+#include <ostream>
+#include <iomanip>
+
+#include <__debug>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
+    template<class _CharT, class _Traits = _VSTD::char_traits<_CharT> >
+    class _LIBCPP_TYPE_VIS_ONLY basic_string_view {
+    public:
+        // types
+        typedef _Traits                                    traits_type;
+        typedef _CharT                                     value_type;
+        typedef const _CharT*                              pointer;
+        typedef const _CharT*                              const_pointer;
+        typedef const _CharT&                              reference;
+        typedef const _CharT&                              const_reference;
+        typedef const_pointer                              const_iterator; // See [string.view.iterators]
+        typedef const_iterator                             iterator;
+        typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
+        typedef const_reverse_iterator                     reverse_iterator;
+        typedef size_t                                     size_type;
+        typedef ptrdiff_t                                  difference_type;
+        static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
+
+        // [string.view.cons], construct/copy
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        basic_string_view(const basic_string_view&) _NOEXCEPT = default;
+
+        _LIBCPP_INLINE_VISIBILITY
+        basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
+
+        template<class _Allocator>
+        _LIBCPP_INLINE_VISIBILITY
+        basic_string_view(const basic_string<_CharT, _Traits, _Allocator>& __str) _NOEXCEPT
+            : __data (__str.data()), __size(__str.size()) {}
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        basic_string_view(const _CharT* __s, size_type __len)
+            : __data(__s), __size(__len)
+        {
+//             _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): recieved nullptr");
+        }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        basic_string_view(const _CharT* __s)
+            : __data(__s), __size(_Traits::length(__s)) {}
+
+        // [string.view.iterators], iterators
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_iterator begin()  const _NOEXCEPT { return cbegin(); }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_iterator end()    const _NOEXCEPT { return cend(); }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_iterator cbegin() const _NOEXCEPT { return __data; }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_iterator cend()   const _NOEXCEPT { return __data + __size; }
+
+        _LIBCPP_INLINE_VISIBILITY
+        const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
+
+        _LIBCPP_INLINE_VISIBILITY
+        const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
+
+        _LIBCPP_INLINE_VISIBILITY
+        const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
+
+        _LIBCPP_INLINE_VISIBILITY
+        const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
+
+        // [string.view.capacity], capacity
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        size_type size()     const _NOEXCEPT { return __size; }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        size_type length()   const _NOEXCEPT { return __size; }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        size_type max_size() const _NOEXCEPT { return _VSTD::numeric_limits<size_type>::max(); }
+
+        _LIBCPP_CONSTEXPR bool _LIBCPP_INLINE_VISIBILITY
+        empty()         const _NOEXCEPT { return __size == 0; }
+
+        // [string.view.access], element access
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_reference operator[](size_type __pos) const { return __data[__pos]; }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_reference at(size_type __pos) const
+        {
+            return __pos >= size()
+                ? throw out_of_range("string_view::at")
+                : __data[__pos];
+//             if (__pos >= size())
+//                 throw out_of_range("string_view::at");
+//             return __data[__pos]; 
+        }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_reference front() const
+        {
+            return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
+        }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_reference back() const
+        {
+            return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
+        }
+
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        const_pointer data() const _NOEXCEPT { return __data; }
+
+        // [string.view.modifiers], modifiers:
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        void clear() _NOEXCEPT
+        {
+            __data = nullptr;
+            __size = 0;
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        void remove_prefix(size_type __n) _NOEXCEPT
+        {
+            if (__n > __size)
+                __n = __size;
+            __data += __n;
+            __size -= __n;
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        void remove_suffix(size_type __n) _NOEXCEPT
+        {
+            if (__n > __size)
+                __n = __size;
+            __size -= __n;
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        void swap(basic_string_view& __other) _NOEXCEPT
+        {
+            const value_type *__p = __data;
+            __data = __other.__data;
+            __other.__data = __p;
+
+            size_type __sz = __size;
+            __size = __other.__size;
+            __other.__size = __sz;
+//             _VSTD::swap( __data, __other.__data );
+//             _VSTD::swap( __size, __other.__size );
+        }
+
+        // [string.view.ops], string operations:
+        template<class _Allocator>
+        _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_EXPLICIT operator basic_string<_CharT, _Traits, _Allocator>() const
+        { return basic_string<_CharT, _Traits, _Allocator>( begin(), end()); }
+
+        template<class _Allocator = allocator<_CharT> >
+        _LIBCPP_INLINE_VISIBILITY
+        basic_string<_CharT, _Traits, _Allocator> to_string( const _Allocator& __a = _Allocator())
+        { return basic_string<_CharT, _Traits, _Allocator> ( begin(), end(), __a ); }
+
+        size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
+        {
+            if ( __pos > size())
+                throw out_of_range("string_view::copy");
+            size_type __rlen = _VSTD::min( __n, size() - __pos );
+            _VSTD::copy_n(begin() + __pos, __rlen, __s );
+            return __rlen;
+        }
+
+        _LIBCPP_CONSTEXPR
+        basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
+        {
+//             if (__pos > size())
+//                 throw out_of_range("string_view::substr");
+//             size_type __rlen = _VSTD::min( __n, size() - __pos );
+//             return basic_string_view(data() + __pos, __rlen);
+            return __pos > size()
+                ? throw out_of_range("string_view::substr")
+                : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
+        {
+            size_type __rlen = _VSTD::min( size(), __sv.size());
+            int __retval = _Traits::compare(data(), __sv.data(), __rlen);
+            if ( __retval == 0 ) // first __rlen chars matched
+                __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
+            return __retval;
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
+        {
+            return substr(__pos1, __n1).compare(__sv);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        int compare(                       size_type __pos1, size_type __n1, 
+                    basic_string_view _sv, size_type __pos2, size_type __n2) const
+        {
+            return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2));
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        int compare(const _CharT* __s) const
+        {
+            return compare(basic_string_view(__s));
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
+        {
+            return substr(__pos1, __n1).compare(basic_string_view(__s));
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
+        {
+            return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
+        }
+
+        // find
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): recieved nullptr");
+            return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
+        {
+            return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+                (data(), size(), __c, __pos);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): recieved nullptr");
+            return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find(const _CharT* __s, size_type __pos = 0) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): recieved nullptr");
+            return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+        // rfind
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): recieved nullptr");
+            return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
+        {
+            return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+                (data(), size(), __c, __pos);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): recieved nullptr");
+            return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type rfind(const _CharT* __s, size_type __pos=npos) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): recieved nullptr");
+            return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+        // find_first_of
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): recieved nullptr");
+            return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
+        { return find(__c, __pos); }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): recieved nullptr");
+            return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_of(const _CharT* __s, size_type __pos=0) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): recieved nullptr");
+            return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+        // find_last_of
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): recieved nullptr");
+            return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
+        { return rfind(__c, __pos); }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): recieved nullptr");
+            return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): recieved nullptr");
+            return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+        // find_first_not_of
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): recieved nullptr");
+            return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
+        {
+            return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __c, __pos);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): recieved nullptr");
+            return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): recieved nullptr");
+            return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+        // find_last_not_of
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
+        {
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): recieved nullptr");
+            return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s.data(), __pos, __s.size());
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
+        {
+            return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __c, __pos);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+        {
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): recieved nullptr");
+            return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, __n);
+        }
+
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
+        {
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): recieved nullptr");
+            return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+                (data(), size(), __s, __pos, traits_type::length(__s));
+        }
+
+    private:
+        const   value_type* __data;
+        size_type           __size;
+    };
+
+
+    // [string.view.comparison]
+    // operator ==
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator==(basic_string_view<_CharT, _Traits> __lhs,
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size()) return false;
+        return __lhs.compare(__rhs) == 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator==(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size()) return false;
+        return __lhs.compare(__rhs) == 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator==(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size()) return false;
+        return __lhs.compare(__rhs) == 0;
+    }
+
+
+    // operator !=
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size())
+            return true;
+        return __lhs.compare(__rhs) != 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size())
+            return true;
+        return __lhs.compare(__rhs) != 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        if ( __lhs.size() != __rhs.size())
+            return true;
+        return __lhs.compare(__rhs) != 0;
+    }
+
+
+    // operator <
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) < 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) < 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) < 0;
+    }
+
+
+    // operator >
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) > 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator>(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) > 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator>(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) > 0;
+    }
+
+
+    // operator <=
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) <= 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) <= 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator<=(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) <= 0;
+    }
+
+
+    // operator >=
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) >= 0;
+    }
+
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
+                    typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) >= 0;
+    }
+
+    template<class _CharT, class _Traits>
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    bool operator>=(typename _VSTD::common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 
+                    basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
+    {
+        return __lhs.compare(__rhs) >= 0;
+    }
+
+
+    // [string.view.io]
+    template<class _CharT, class _Traits>
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv)
+    {
+        return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
+    }
+
+  typedef basic_string_view<char>     string_view;
+  typedef basic_string_view<char16_t> u16string_view;
+  typedef basic_string_view<char32_t> u32string_view;
+  typedef basic_string_view<wchar_t>  wstring_view;
+
+_LIBCPP_END_NAMESPACE_LFTS
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// [string.view.hash]
+// Shamelessly stolen from <string>
+template<class _CharT, class _Traits>
+struct _LIBCPP_TYPE_VIS_ONLY hash<std::experimental::basic_string_view<_CharT, _Traits> >
+    : public unary_function<std::experimental::basic_string_view<_CharT, _Traits>, size_t>
+{
+    size_t operator()(const std::experimental::basic_string_view<_CharT, _Traits>& __val) const _NOEXCEPT;
+};
+
+template<class _CharT, class _Traits>
+size_t
+hash<std::experimental::basic_string_view<_CharT, _Traits> >::operator()(
+        const std::experimental::basic_string_view<_CharT, _Traits>& __val) const _NOEXCEPT
+{
+    return __do_string_hash(__val.data(), __val.data() + __val.size());
+}
+
+#if _LIBCPP_STD_VER > 11
+template <class _CharT, class _Traits>
+__quoted_output_proxy<_CharT, const _CharT *, _Traits>
+quoted ( std::experimental::basic_string_view <_CharT, _Traits> __sv,
+             _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
+{
+    return __quoted_output_proxy<_CharT, const _CharT *, _Traits> 
+         ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
+}
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_LFTS_STRING_VIEW
diff --git a/system/include/libcxx/experimental/utility b/system/include/libcxx/experimental/utility
new file mode 100644
index 0000000000000..84e461af073f3
--- /dev/null
+++ b/system/include/libcxx/experimental/utility
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===-------------------------- utility ----------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL_UTILITY
+#define _LIBCPP_EXPERIMENTAL_UTILITY
+
+/*
+    experimental/utility synopsis
+
+// C++1y
+
+#include <utility>
+
+namespace std {
+namespace experimental {
+inline namespace fundamentals_v1 {
+
+  3.1.2, erased-type placeholder
+  struct erased_type { };
+
+} // namespace fundamentals_v1
+} // namespace experimental
+} // namespace std
+
+ */
+
+# include <experimental/__config>
+
+# include <utility>
+
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
+  struct _LIBCPP_TYPE_VIS_ONLY erased_type { };
+
+_LIBCPP_END_NAMESPACE_LFTS
+
+#endif /* _LIBCPP_EXPERIMENTAL_UTILITY */
diff --git a/system/include/libcxx/ext/__hash b/system/include/libcxx/ext/__hash
index c0523cce4a255..5675d54055e02 100644
--- a/system/include/libcxx/ext/__hash
+++ b/system/include/libcxx/ext/__hash
@@ -19,8 +19,7 @@
 namespace __gnu_cxx {
 using namespace std;
 
-template <typename _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash : public std::hash<_Tp>
-    { };
+template <typename _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash { };
 
 template <> struct _LIBCPP_TYPE_VIS_ONLY hash<const char*>
     : public unary_function<const char*, size_t>
@@ -41,6 +40,96 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char *>
         return __do_string_hash<const char *>(__c, __c + strlen(__c));
     }
 };
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char>
+    : public unary_function<char, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(char __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
+    : public unary_function<signed char, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(signed char __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
+    : public unary_function<unsigned char, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(unsigned char __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<short>
+    : public unary_function<short, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(short __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
+    : public unary_function<unsigned short, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(unsigned short __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<int>
+    : public unary_function<int, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(int __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
+    : public unary_function<unsigned int, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(unsigned int __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<long>
+    : public unary_function<long, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(long __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
+
+template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
+    : public unary_function<unsigned long, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(unsigned long __c) const _NOEXCEPT
+    {
+        return __c;
+    }
+};
 }
 
 #endif  // _LIBCPP_EXT_HASH
diff --git a/system/include/libcxx/ext/hash_map b/system/include/libcxx/ext/hash_map
index 225b72baa2c9c..36cd595e0343b 100644
--- a/system/include/libcxx/ext/hash_map
+++ b/system/include/libcxx/ext/hash_map
@@ -430,9 +430,9 @@ public:
     typedef const value_type&                                    reference;
     typedef typename __pointer_traits::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-            rebind<value_type>
+            rebind<const value_type>
 #else
-            rebind<value_type>::other
+            rebind<const value_type>::other
 #endif
                                                                  pointer;
 
diff --git a/system/include/libcxx/forward_list b/system/include/libcxx/forward_list
index 398226b8d42d2..a83b19520e284 100644
--- a/system/include/libcxx/forward_list
+++ b/system/include/libcxx/forward_list
@@ -188,7 +188,6 @@ template <class _Tp, class _VoidPtr> struct __forward_list_node;
 template <class _NodePtr>
 struct __forward_begin_node
 {
-    typedef __forward_begin_node __self;
     typedef _NodePtr pointer;
 
     pointer __next_;
@@ -197,16 +196,22 @@ struct __forward_begin_node
 };
 
 template <class _Tp, class _VoidPtr>
-struct __forward_list_node
-    : public __forward_begin_node
-             <
-                 typename pointer_traits<_VoidPtr>::template
+struct _LIBCPP_HIDDEN __begin_node_of
+{
+    typedef __forward_begin_node
+        <
+             typename pointer_traits<_VoidPtr>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-                     rebind<__forward_list_node<_Tp, _VoidPtr> >
+                 rebind<__forward_list_node<_Tp, _VoidPtr> >
 #else
-                     rebind<__forward_list_node<_Tp, _VoidPtr> >::other
+                 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
 #endif
-             >
+         > type;
+};
+
+template <class _Tp, class _VoidPtr>
+struct __forward_list_node
+    : public __begin_node_of<_Tp, _VoidPtr>::type
 {
     typedef _Tp value_type;
 
@@ -357,9 +362,9 @@ protected:
     typedef _Tp    value_type;
     typedef _Alloc allocator_type;
 
-    typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
-    typedef __forward_list_node<value_type, void_pointer>           __node;
-    typedef typename __node::__self                                 __begin_node;
+    typedef typename allocator_traits<allocator_type>::void_pointer  void_pointer;
+    typedef __forward_list_node<value_type, void_pointer>            __node;
+    typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
     typedef typename allocator_traits<allocator_type>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
                 rebind_alloc<__node>
@@ -1416,6 +1421,7 @@ template <class _Tp, class _Alloc>
 void
 forward_list<_Tp, _Alloc>::remove(const value_type& __v)
 {
+    forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
     iterator __e = end();
     for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
     {
@@ -1424,7 +1430,7 @@ forward_list<_Tp, _Alloc>::remove(const value_type& __v)
             iterator __j = _VSTD::next(__i, 2);
             for (; __j != __e && *__j == __v; ++__j)
                 ;
-            erase_after(__i, __j);
+			__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
             if (__j == __e)
                 break;
             __i = __j;
diff --git a/system/include/libcxx/functional b/system/include/libcxx/functional
index d40f70af40ba8..416a9a97f71e1 100644
--- a/system/include/libcxx/functional
+++ b/system/include/libcxx/functional
@@ -1221,7 +1221,7 @@ public:
     template <class... _ArgTypes>
        _LIBCPP_INLINE_VISIBILITY
        typename __invoke_return<type, _ArgTypes...>::type
-          operator() (_ArgTypes&&... __args)
+          operator() (_ArgTypes&&... __args) const
           {
               return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
           }
@@ -1421,7 +1421,7 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
         static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
     template <class _R2, class ..._Ap>
         _LIBCPP_INLINE_VISIBILITY
-        static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
+        static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;}
 
     template <class _Fp, bool = !is_same<_Fp, function>::value &&
                                 __invokable<_Fp&, _ArgTypes...>::value>
@@ -1617,21 +1617,22 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _
     if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
-        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
+        typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<_FF>
+#else
+            rebind_alloc<_FF>::other
+#endif
+            _Ap;
+        _Ap __a(__a0);
+        if (sizeof(_FF) <= sizeof(__buf_) && 
+            is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
         {
             __f_ = (__base*)&__buf_;
-            ::new (__f_) _FF(_VSTD::move(__f));
+            ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a));
         }
         else
         {
-            typedef typename __alloc_traits::template
-#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-                rebind_alloc<_FF>
-#else
-                rebind_alloc<_FF>::other
-#endif
-                                                         _Ap;
-            _Ap __a(__a0);
             typedef __allocator_destructor<_Ap> _Dp;
             unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
             ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
@@ -1857,7 +1858,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 typename __invoke_of<_Ti&, _Uj...>::type
 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
 {
-    return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
+    return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
 }
 
 template <class _Ti, class ..._Uj>
@@ -1892,7 +1893,7 @@ typename enable_if
 __mu(_Ti&, _Uj& __uj)
 {
     const size_t _Indx = is_placeholder<_Ti>::value - 1;
-    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
+    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
 }
 
 template <class _Ti, class _Uj>
@@ -2019,7 +2020,7 @@ typename __bind_return<_Fp, _BoundArgs, _Args>::type
 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
                 _Args&& __args)
 {
-    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
+    return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
 }
 
 template<class _Fp, class ..._BoundArgs>
diff --git a/system/include/libcxx/future b/system/include/libcxx/future
index 73d5456d71780..83513fa693d68 100644
--- a/system/include/libcxx/future
+++ b/system/include/libcxx/future
@@ -374,6 +374,10 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #pragma GCC system_header
 #endif
 
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <future> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 //enum class future_errc
@@ -1872,7 +1876,7 @@ template <class _Fp>
 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
     : __f_(nullptr)
 {
-    typedef typename remove_reference<_Fp>::type _FR;
+    typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
     typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
     if (sizeof(_FF) <= sizeof(__buf_))
     {
@@ -1897,7 +1901,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
     : __f_(nullptr)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    typedef typename remove_reference<_Fp>::type _FR;
+    typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
     typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
     if (sizeof(_FF) <= sizeof(__buf_))
     {
@@ -2612,4 +2616,6 @@ future<void>::share()
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_FUTURE
diff --git a/system/include/libcxx/iomanip b/system/include/libcxx/iomanip
index e334c7de9fd7c..a5042c7df8105 100644
--- a/system/include/libcxx/iomanip
+++ b/system/include/libcxx/iomanip
@@ -519,15 +519,16 @@ std::basic_ostream<_CharT, _Traits> &
 __quoted_output ( basic_ostream<_CharT, _Traits> &__os, 
         _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape )
 {
-    __os << __delim;
+    _VSTD::basic_string<_CharT, _Traits> __str;
+    __str.push_back(__delim);
     for ( ; __first != __last; ++ __first )
     {
         if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim))
-            __os << __escape;
-        __os << *__first;
+            __str.push_back(__escape);
+        __str.push_back(*__first);
     }
-    __os << __delim;
-    return __os;
+    __str.push_back(__delim);
+    return __put_character_sequence(__os, __str.data(), __str.size());
 }
 
 template <class _CharT, class _Traits, class _String>
diff --git a/system/include/libcxx/ios b/system/include/libcxx/ios
index b6cf07665172a..ff79998b0bbf9 100644
--- a/system/include/libcxx/ios
+++ b/system/include/libcxx/ios
@@ -216,7 +216,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
 #include <__locale>
 #include <system_error>
 
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 #include <atomic>     // for __xindex_
 #endif
 
@@ -367,7 +367,7 @@ private:
     int*            __index_;
     size_t          __event_size_;
     size_t          __event_cap_;
-#if __has_feature(cxx_atomic) && !defined(__EMSCRIPTEN__)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
     static atomic<int> __xindex_;
 #else
     static int      __xindex_;
diff --git a/system/include/libcxx/istream b/system/include/libcxx/istream
index 14fa466057cfc..168a4d0635f6f 100644
--- a/system/include/libcxx/istream
+++ b/system/include/libcxx/istream
@@ -82,6 +82,13 @@ public:
     pos_type tellg();
     basic_istream& seekg(pos_type);
     basic_istream& seekg(off_type, ios_base::seekdir);
+protected:
+    basic_istream(const basic_istream& rhs) = delete;
+    basic_istream(basic_istream&& rhs);
+    // 27.7.2.1.2 Assign/swap:
+    basic_istream& operator=(const basic_istream& rhs) = delete;
+    basic_istream& operator=(basic_istream&& rhs);
+    void swap(basic_istream& rhs);
 };
 
 // 27.7.1.2.3 character extraction templates:
@@ -184,13 +191,22 @@ protected:
     _LIBCPP_INLINE_VISIBILITY
     basic_istream(basic_istream&& __rhs);
 #endif
-
     // 27.7.1.1.2 Assign/swap:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     basic_istream& operator=(basic_istream&& __rhs);
 #endif
     void swap(basic_istream& __rhs);
+
+#if _LIBCPP_STD_VER > 11
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+    basic_istream           (const basic_istream& __rhs) = delete;
+    basic_istream& operator=(const basic_istream& __rhs) = delete;
+#else
+    basic_istream           (const basic_istream& __rhs); // not defined
+    basic_istream& operator=(const basic_istream& __rhs); // not defined
+#endif
+#endif
 public:
 
     // 27.7.1.1.3 Prefix/suffix:
diff --git a/system/include/libcxx/iterator b/system/include/libcxx/iterator
index d16aa2aa95fb3..88e615a32539b 100644
--- a/system/include/libcxx/iterator
+++ b/system/include/libcxx/iterator
@@ -138,6 +138,8 @@ template <class Iterator>
 reverse_iterator<Iterator>
 operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
 
+template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
+
 template <class Container>
 class back_insert_iterator
 {
@@ -327,6 +329,7 @@ template <class C> auto crend(const C& c) -> decltype(std::rend(c));          //
 */
 
 #include <__config>
+#include <__functional_base>
 #include <type_traits>
 #include <cstddef>
 #include <iosfwd>
@@ -335,11 +338,7 @@ template <class C> auto crend(const C& c) -> decltype(std::rend(c));          //
 #include <Availability.h>
 #endif
 
-#ifdef _LIBCPP_DEBUG
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
+#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -364,10 +363,10 @@ public:
     static const bool value = sizeof(__test<_Tp>(0)) == 1;
 };
 
-template <class _Iter, bool> struct ____iterator_traits {};
+template <class _Iter, bool> struct __iterator_traits_impl {};
 
 template <class _Iter>
-struct ____iterator_traits<_Iter, true>
+struct __iterator_traits_impl<_Iter, true>
 {
     typedef typename _Iter::difference_type   difference_type;
     typedef typename _Iter::value_type        value_type;
@@ -380,7 +379,7 @@ template <class _Iter, bool> struct __iterator_traits {};
 
 template <class _Iter>
 struct __iterator_traits<_Iter, true>
-    :  ____iterator_traits
+    :  __iterator_traits_impl
       <
         _Iter,
         is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
@@ -534,7 +533,7 @@ class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
                       typename iterator_traits<_Iter>::reference>
 {
 private:
-    mutable _Iter __t;
+    mutable _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
 protected:
     _Iter current;
 public:
@@ -548,8 +547,8 @@ public:
     template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
         : __t(__u.base()), current(__u.base()) {}
     _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
-    _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
-    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return _VSTD::addressof(operator*());}
     _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
     _LIBCPP_INLINE_VISIBILITY reverse_iterator  operator++(int)
         {reverse_iterator __tmp(*this); --current; return __tmp;}
@@ -632,6 +631,15 @@ operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_i
     return reverse_iterator<_Iter>(__x.base() - __n);
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
+{
+    return reverse_iterator<_Iter>(__i);
+}
+#endif
+
 template <class _Container>
 class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
     : public iterator<output_iterator_tag,
@@ -645,7 +653,7 @@ protected:
 public:
     typedef _Container container_type;
 
-    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
+    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
     _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
         {container->push_back(__value_); return *this;}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -678,7 +686,7 @@ protected:
 public:
     typedef _Container container_type;
 
-    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
+    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
     _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
         {container->push_front(__value_); return *this;}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -713,7 +721,7 @@ public:
     typedef _Container container_type;
 
     _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
-        : container(&__x), iter(__i) {}
+        : container(_VSTD::addressof(__x)), iter(__i) {}
     _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
         {iter = container->insert(iter, __value_); ++iter; return *this;}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1385,6 +1393,22 @@ operator+(typename __wrap_iter<_Iter>::difference_type __n,
     return __x;
 }
 
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_Tp*
+begin(_Tp (&__array)[_Np])
+{
+    return __array;
+}
+
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_Tp*
+end(_Tp (&__array)[_Np])
+{
+    return __array + _Np;
+}
+
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
 
 template <class _Cp>
@@ -1421,18 +1445,46 @@ end(const _Cp& __c) -> decltype(__c.end())
 
 #if _LIBCPP_STD_VER > 11
 
-template <class _Cp>
+template <class _Tp, size_t _Np>
 inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
+{
+    return reverse_iterator<_Tp*>(__array + _Np);
+}
+
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
+{
+    return reverse_iterator<_Tp*>(__array);
+}
+
+template <class _Ep>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
+{
+    return reverse_iterator<const _Ep*>(__il.end());
+}
+
+template <class _Ep>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
+{
+    return reverse_iterator<const _Ep*>(__il.begin());
+}
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 auto cbegin(const _Cp& __c) -> decltype(begin(__c))
 {
-    return __c.begin();
+    return begin(__c);
 }
 
 template <class _Cp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 auto cend(const _Cp& __c) -> decltype(end(__c))
 {
-    return __c.end();
+    return end(__c);
 }
 
 template <class _Cp>
@@ -1516,53 +1568,6 @@ end(const _Cp& __c)
 
 #endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
 
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-begin(_Tp (&__array)[_Np])
-{
-    return __array;
-}
-
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-end(_Tp (&__array)[_Np])
-{
-    return __array + _Np;
-}
-
-#if _LIBCPP_STD_VER > 11
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
-{
-    return reverse_iterator<_Tp*>(__array + _Np);
-}
-
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
-{
-    return reverse_iterator<_Tp*>(__array);
-}
-
-template <class _Ep>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
-{
-    return reverse_iterator<const _Ep*>(__il.end());
-}
-
-template <class _Ep>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
-{
-    return reverse_iterator<const _Ep*>(__il.begin());
-}
-
-#endif
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_ITERATOR
diff --git a/system/include/libcxx/limits b/system/include/libcxx/limits
index d917c577f1480..1acf03e30b601 100644
--- a/system/include/libcxx/limits
+++ b/system/include/libcxx/limits
@@ -235,7 +235,7 @@ protected:
 
     static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
     static _LIBCPP_CONSTEXPR const bool is_bounded = true;
-    static _LIBCPP_CONSTEXPR const bool is_modulo = true;
+    static _LIBCPP_CONSTEXPR const bool is_modulo = !_VSTD::is_signed<_Tp>::value;
 
 #if __i386__ || __x86_64__
     static _LIBCPP_CONSTEXPR const bool traps = true;
@@ -768,7 +768,7 @@ template <class _Tp>
 template <class _Tp>
     _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits10;
 template <class _Tp>
-    const int numeric_limits<const volatile _Tp>::max_digits10;
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_digits10;
 template <class _Tp>
     _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_signed;
 template <class _Tp>
diff --git a/system/include/libcxx/list b/system/include/libcxx/list
index 800a1a3f5aa82..13f8a53bf25fd 100644
--- a/system/include/libcxx/list
+++ b/system/include/libcxx/list
@@ -179,11 +179,7 @@ template <class T, class Alloc>
 
 #include <__undef_min_max>
 
-#ifdef _LIBCPP_DEBUG
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
+#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -214,10 +210,13 @@ struct __list_node_base
     pointer __next_;
 
     _LIBCPP_INLINE_VISIBILITY
-    __list_node_base()
-        : __prev_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))),
-          __next_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this)))
-          {}
+    __list_node_base() : __prev_(__self()), __next_(__self()) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    pointer __self()
+    {
+        return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
+    }
 };
 
 template <class _Tp, class _VoidPtr>
@@ -753,20 +752,14 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
     swap(__sz(), __c.__sz());
     swap(__end_, __c.__end_);
     if (__sz() == 0)
-        __end_.__next_ = __end_.__prev_ = static_cast<__node_pointer>(
-                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
+        __end_.__next_ = __end_.__prev_ = __end_.__self();
     else
-        __end_.__prev_->__next_ = __end_.__next_->__prev_
-                                = static_cast<__node_pointer>(
-                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
+        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
     if (__c.__sz() == 0)
-        __c.__end_.__next_ = __c.__end_.__prev_
-                           = static_cast<__node_pointer>(
-                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_));
+        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
     else
-        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_
-                                    = static_cast<__node_pointer>(
-                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_));
+        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
+
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __libcpp_db* __db = __get_db();
     __c_node* __cn1 = __db->__find_c_and_lock(this);
@@ -1059,7 +1052,9 @@ public:
 #endif  // _LIBCPP_DEBUG_LEVEL >= 2
 
 private:
-    static void __link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l);
+    static void __link_nodes  (__node_pointer __p, __node_pointer __f, __node_pointer __l);
+    void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
+    void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
     iterator __iterator(size_type __n);
     template <class _Comp>
         static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
@@ -1081,6 +1076,31 @@ list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_p
     __l->__next_ = __p;
 }
 
+// Link in nodes [__f, __l] at the front of the list
+template <class _Tp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
+{
+    __f->__prev_ = base::__end_.__self();
+    __l->__next_ = base::__end_.__next_;
+    __l->__next_->__prev_ = __l;
+    base::__end_.__next_ = __f;
+}
+
+// Link in nodes [__f, __l] at the front of the list
+template <class _Tp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
+{
+    __l->__next_ = base::__end_.__self();
+    __f->__prev_ = base::__end_.__prev_;
+    __f->__prev_->__next_ = __f;
+    base::__end_.__prev_ = __l;
+}
+
+
 template <class _Tp, class _Alloc>
 inline _LIBCPP_INLINE_VISIBILITY
 typename list<_Tp, _Alloc>::iterator
@@ -1502,7 +1522,7 @@ list<_Tp, _Alloc>::push_front(const value_type& __x)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1515,8 +1535,7 @@ list<_Tp, _Alloc>::push_back(const value_type& __x)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
-                         pointer_to(base::__end_)), __hold.get(), __hold.get());
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1531,7 +1550,7 @@ list<_Tp, _Alloc>::push_front(value_type&& __x)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1544,8 +1563,7 @@ list<_Tp, _Alloc>::push_back(value_type&& __x)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
-                         pointer_to(base::__end_)), __hold.get(), __hold.get());
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1561,7 +1579,7 @@ list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1575,8 +1593,7 @@ list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
-                         pointer_to(base::__end_)), __hold.get(), __hold.get());
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1826,8 +1843,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
-                         pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
+        __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
 }
@@ -2038,14 +2054,18 @@ template <class _Tp, class _Alloc>
 void
 list<_Tp, _Alloc>::remove(const value_type& __x)
 {
-    for (iterator __i = begin(), __e = end(); __i != __e;)
+    list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
+    for (const_iterator __i = begin(), __e = end(); __i != __e;)
     {
         if (*__i == __x)
         {
-            iterator __j = _VSTD::next(__i);
+            const_iterator __j = _VSTD::next(__i);
             for (; __j != __e && *__j == __x; ++__j)
                 ;
-            __i = erase(__i, __j);
+            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
+            __i = __j;
+            if (__i != __e)
+                ++__i;
         }
         else
             ++__i;
@@ -2065,6 +2085,8 @@ list<_Tp, _Alloc>::remove_if(_Pred __pred)
             for (; __j != __e && __pred(*__j); ++__j)
                 ;
             __i = erase(__i, __j);
+            if (__i != __e)
+                ++__i;
         }
         else
             ++__i;
diff --git a/system/include/libcxx/locale b/system/include/libcxx/locale
index ac3ae7ead92f5..78f85d8d0700f 100644
--- a/system/include/libcxx/locale
+++ b/system/include/libcxx/locale
@@ -193,9 +193,14 @@ template <class charT> class messages_byname;
 #include <ctime>
 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
 #include <support/win32/locale_win32.h>
-#else // _LIBCPP_MSVCRT
+#elif defined(_NEWLIB_VERSION)
+// FIXME: replace all the uses of _NEWLIB_VERSION with __NEWLIB__ preceded by an
+// include of <sys/cdefs.h> once https://sourceware.org/ml/newlib-cvs/2014-q3/msg00038.html
+// has had a chance to bake for a bit
+#include <support/newlib/xlocale.h>
+#elif !defined(__ANDROID__)
 #include <nl_types.h>
-#endif  // !_LIBCPP_MSVCRT
+#endif
 
 #ifdef __APPLE__
 #include <Availability.h>
@@ -229,7 +234,8 @@ typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 // OSX has nice foo_l() functions that let you turn off use of the global
 // locale.  Linux, not so much.  The following functions avoid the locale when
 // that's possible and otherwise do the wrong thing.  FIXME.
-#if defined(__linux__) || defined(__EMSCRIPTEN__) || defined(_AIX)
+#if defined(__linux__) || defined(__EMSCRIPTEN__) || defined(_AIX) || \
+    defined(_NEWLIB_VERSION)
 
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
 decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
@@ -417,7 +423,7 @@ int __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
 //  and failbit is set in __err.
 //  Else an iterator pointing to the matching keyword is found.  If more than
 //  one keyword matches, an iterator to the first matching keyword is returned.
-//  If on exit __b == __e, eofbit is set in __err.  If __case_senstive is false,
+//  If on exit __b == __e, eofbit is set in __err.  If __case_sensitive is false,
 //  __ct is used to force to lower case before comparing characters.
 //  Examples:
 //  Keywords:  "a", "abb"
@@ -1012,7 +1018,7 @@ num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if (__a_end == __a + __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
@@ -1062,7 +1068,7 @@ num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e,
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if (__a_end == __a + __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
@@ -1116,7 +1122,7 @@ num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_typ
     char __exp = 'E';
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if (__a_end == __a + __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
@@ -1166,7 +1172,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if (__a_end == __a + __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
@@ -1180,11 +1186,11 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
             break;
     }
     // Stage 3
-    __a[sizeof(__a)-1] = 0;
+    __buf.resize(__a_end - __a);
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    if (sscanf_l(__a, _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
+    if (sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
 #else
-    if (__sscanf_l(__a, __cloc(), "%p", &__v) != 1)
+    if (__sscanf_l(__buf.c_str(), __cloc(), "%p", &__v) != 1)
 #endif
         __err = ios_base::failbit;
     // EOF checked
@@ -1871,7 +1877,7 @@ public:
 };
 
 template <class _CharT>
-class _LIBCPP_TYPE_VIS __time_get_c_storage
+class _LIBCPP_TYPE_VIS_ONLY __time_get_c_storage
 {
 protected:
     typedef basic_string<_CharT> string_type;
@@ -2038,7 +2044,7 @@ template <class _CharT, class _InputIterator>
 locale::id
 time_get<_CharT, _InputIterator>::id;
 
-// time_get primatives
+// time_get primitives
 
 template <class _CharT, class _InputIterator>
 void
@@ -2259,7 +2265,7 @@ time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e,
         __err |= ios_base::eofbit;
 }
 
-// time_get end primatives
+// time_get end primitives
 
 template <class _CharT, class _InputIterator>
 _InputIterator
@@ -2509,7 +2515,7 @@ protected:
 };
 
 template <class _CharT>
-class _LIBCPP_TYPE_VIS __time_get_storage
+class _LIBCPP_TYPE_VIS_ONLY __time_get_storage
     : public __time_get
 {
 protected:
@@ -3673,14 +3679,14 @@ template <class _CharT>
 typename messages<_CharT>::catalog
 messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
 {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__ANDROID__) || defined(_NEWLIB_VERSION)
     return -1;
-#else // _WIN32
+#else // _WIN32 || __ANDROID__
     catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
     if (__cat != -1)
         __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
     return __cat;
-#endif // _WIN32
+#endif // _WIN32 || __ANDROID__
 }
 
 template <class _CharT>
@@ -3688,7 +3694,7 @@ typename messages<_CharT>::string_type
 messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
                          const string_type& __dflt) const
 {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__ANDROID__) || defined(_NEWLIB_VERSION)
     return __dflt;
 #else // _WIN32
     string __ndflt;
@@ -3710,7 +3716,7 @@ template <class _CharT>
 void
 messages<_CharT>::do_close(catalog __c) const
 {
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(_NEWLIB_VERSION)
     if (__c != -1)
         __c <<= 1;
     nl_catd __cat = (nl_catd)__c;
diff --git a/system/include/libcxx/map b/system/include/libcxx/map
index 9779b70e21224..5c3969acdd28c 100644
--- a/system/include/libcxx/map
+++ b/system/include/libcxx/map
@@ -159,7 +159,7 @@ public:
     template<typename K>
         const_iterator find(const K& x) const;  // C++14
     template<typename K>
-      size_type count(const K& x) const;
+      size_type count(const K& x) const;        // C++14
 
     size_type      count(const key_type& k) const;
           iterator lower_bound(const key_type& k);
@@ -353,7 +353,7 @@ public:
     template<typename K>
         const_iterator find(const K& x) const;  // C++14
     template<typename K>
-      size_type count(const K& x) const;
+      size_type count(const K& x) const;        // C++14
 
     size_type      count(const key_type& k) const;
           iterator lower_bound(const key_type& k);
@@ -835,11 +835,18 @@ public:
     typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit map(const key_compare& __comp = key_compare())
+    map()
         _NOEXCEPT_(
             is_nothrow_default_constructible<allocator_type>::value &&
             is_nothrow_default_constructible<key_compare>::value &&
             is_nothrow_copy_constructible<key_compare>::value)
+        : __tree_(__vc(key_compare())) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit map(const key_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__vc(__comp)) {}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1097,6 +1104,12 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type      count(const key_type& __k) const
         {return __tree_.__count_unique(__k);}
+#if _LIBCPP_STD_VER > 11
+    template <typename _K2>
+    _LIBCPP_INLINE_VISIBILITY
+    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
+    count(const _K2& __k)                  {return __tree_.__count_unique(__k);}
+#endif
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
         {return __tree_.lower_bound(__k);}
@@ -1568,11 +1581,18 @@ public:
     typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit multimap(const key_compare& __comp = key_compare())
+    multimap()
         _NOEXCEPT_(
             is_nothrow_default_constructible<allocator_type>::value &&
             is_nothrow_default_constructible<key_compare>::value &&
             is_nothrow_copy_constructible<key_compare>::value)
+        : __tree_(__vc(key_compare())) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit multimap(const key_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__vc(__comp)) {}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1820,6 +1840,12 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type      count(const key_type& __k) const
         {return __tree_.__count_multi(__k);}
+#if _LIBCPP_STD_VER > 11
+    template <typename _K2>
+    _LIBCPP_INLINE_VISIBILITY
+    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
+    count(const _K2& __k)                   {return __tree_.__count_multi(__k);}
+#endif
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
         {return __tree_.lower_bound(__k);}
diff --git a/system/include/libcxx/memory b/system/include/libcxx/memory
index b382f70b02f02..a9256da65e8a4 100644
--- a/system/include/libcxx/memory
+++ b/system/include/libcxx/memory
@@ -479,6 +479,8 @@ public:
     template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
     weak_ptr(weak_ptr const& r) noexcept;
     template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
+    weak_ptr(weak_ptr&& r) noexcept;                      // C++14
+    template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
 
     // destructor
     ~weak_ptr();
@@ -487,6 +489,8 @@ public:
     weak_ptr& operator=(weak_ptr const& r) noexcept;
     template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
     template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
+    weak_ptr& operator=(weak_ptr&& r) noexcept;                      // C++14
+    template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
 
     // modifiers
     void swap(weak_ptr& r) noexcept;
@@ -606,7 +610,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
     #include <cassert>
 #endif
 
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 #  include <atomic>
 #endif
 
@@ -1627,9 +1631,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
         {return _VSTD::addressof(__x);}
     _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
-        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
+        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
-        {::operator delete((void*)__p);}
+        {_VSTD::__deallocate((void*)__p);}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
         {return size_type(~0) / sizeof(_Tp);}
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -1717,9 +1721,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
         {return _VSTD::addressof(__x);}
     _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
-        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
+        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
-        {::operator delete((void*)__p);}
+        {_VSTD::__deallocate((void*)__p);}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
         {return size_type(~0) / sizeof(_Tp);}
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -2001,8 +2005,8 @@ public:
                                      tuple<_Args2...> __second_args,
                                      __tuple_indices<_I1...>,
                                      __tuple_indices<_I2...>)
-            : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
-              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+            : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
+              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
             {}
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
@@ -2015,7 +2019,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
     {
         using _VSTD::swap;
         swap(__first_, __x.__first_);
@@ -2092,8 +2096,8 @@ public:
                                      tuple<_Args2...> __second_args,
                                      __tuple_indices<_I1...>,
                                      __tuple_indices<_I2...>)
-            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
-              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
+              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
             {}
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
@@ -2106,7 +2110,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
     {
         using _VSTD::swap;
         swap(__second_, __x.__second_);
@@ -2184,8 +2188,8 @@ public:
                                      tuple<_Args2...> __second_args,
                                      __tuple_indices<_I1...>,
                                      __tuple_indices<_I2...>)
-            : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
-              __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
+            : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
+              __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
               
             {}
 
@@ -2199,7 +2203,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
     {
         using _VSTD::swap;
         swap(__first_, __x.__first_);
@@ -2274,8 +2278,8 @@ public:
                                      tuple<_Args2...> __second_args,
                                      __tuple_indices<_I1...>,
                                      __tuple_indices<_I2...>)
-            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
-              _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
+              _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
             {}
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
@@ -2288,7 +2292,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
     {
     }
 };
@@ -2371,7 +2375,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
         {base::swap(__x);}
 };
 
@@ -2380,7 +2384,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 void
 swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
         _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
-                   __is_nothrow_swappable<_T1>::value)
+                   __is_nothrow_swappable<_T2>::value)
     {__x.swap(__y);}
 
 // __same_or_less_cv_qualified
@@ -2397,13 +2401,14 @@ template <class _Ptr1, class _Ptr2>
 struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
     : false_type {};
 
-template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
-                                         !is_pointer<_Ptr1>::value>
+template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
+                                           is_same<_Ptr1, _Ptr2>::value ||
+                                           __has_element_type<_Ptr1>::value>
 struct __same_or_less_cv_qualified
     : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
 
 template <class _Ptr1, class _Ptr2>
-struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
+struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
     : false_type {};
 
 // default_delete
@@ -2666,23 +2671,21 @@ public:
                 "unique_ptr constructed with null function pointer deleter");
         }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    template <class _Pp,
-              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
-             >
-    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
+    template <class _Pp>
+    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
+            typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
         : __ptr_(__p)
         {
             static_assert(!is_pointer<deleter_type>::value,
                 "unique_ptr constructed with null function pointer deleter");
         }
 
-    template <class _Pp,
-              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
-             >
+    template <class _Pp>
     _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
                                        is_reference<deleter_type>::value,
                                        deleter_type,
-                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
+                                       typename add_lvalue_reference<const deleter_type>::type>::type __d,
+                                       typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
              _NOEXCEPT
         : __ptr_(__p, __d) {}
 
@@ -2693,10 +2696,10 @@ public:
              _NOEXCEPT
         : __ptr_(pointer(), __d) {}
 
-    template <class _Pp,
-              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
-             >
-    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
+    template <class _Pp>
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
+                                         typename remove_reference<deleter_type>::type&& __d,
+                                         typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
              _NOEXCEPT
         : __ptr_(__p, _VSTD::move(__d))
         {
@@ -2811,10 +2814,10 @@ public:
     }
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    template <class _Pp,
-              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
-             >
-    _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
+    template <class _Pp>
+    _LIBCPP_INLINE_VISIBILITY
+    typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
+    reset(_Pp __p) _NOEXCEPT
     {
         pointer __tmp = __ptr_.first();
         __ptr_.first() = __p;
@@ -3759,27 +3762,15 @@ private:
 public:
     _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
     _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
-    template<class _Yp,
-             class = typename enable_if
-                     <
-                        is_convertible<_Yp*, element_type*>::value
-                     >::type
-            >
-        explicit shared_ptr(_Yp* __p);
-    template<class _Yp, class _Dp,
-             class = typename enable_if
-                     <
-                        is_convertible<_Yp*, element_type*>::value
-                     >::type
-            >
-        shared_ptr(_Yp* __p, _Dp __d);
-    template<class _Yp, class _Dp, class _Alloc,
-             class = typename enable_if
-                     <
-                        is_convertible<_Yp*, element_type*>::value
-                     >::type
-            >
-        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
+    template<class _Yp>
+        explicit shared_ptr(_Yp* __p,
+                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
+    template<class _Yp, class _Dp>
+        shared_ptr(_Yp* __p, _Dp __d,
+                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
+    template<class _Yp, class _Dp, class _Alloc>
+        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
+                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
     template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
     template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
     template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
@@ -3797,59 +3788,52 @@ public:
     template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    template<class _Yp,
-             class = typename enable_if
-                     <
-                        is_convertible<_Yp*, element_type*>::value
-                     >::type
-            >
-        shared_ptr(auto_ptr<_Yp>&& __r);
+    template<class _Yp>
+        shared_ptr(auto_ptr<_Yp>&& __r,
+                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
 #else
-    template<class _Yp,
-             class = typename enable_if
-                     <
-                        is_convertible<_Yp*, element_type*>::value
-                     >::type
-            >
-        shared_ptr(auto_ptr<_Yp> __r);
+    template<class _Yp>
+        shared_ptr(auto_ptr<_Yp> __r,
+                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
 #endif
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    template <class _Yp, class _Dp,
-                 class = typename enable_if
-                 <
-                    !is_array<_Yp>::value &&
-                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
-                 >::type
-             >
-       shared_ptr(unique_ptr<_Yp, _Dp>&&,
-       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
-    template <class _Yp, class _Dp,
-                 class = typename enable_if
-                 <
-                    !is_array<_Yp>::value &&
-                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
-                 >::type
-             >
-       shared_ptr(unique_ptr<_Yp, _Dp>&&,
-       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+    template <class _Yp, class _Dp>
+        shared_ptr(unique_ptr<_Yp, _Dp>&&,
+                   typename enable_if
+                   <
+                       !is_lvalue_reference<_Dp>::value &&
+                       !is_array<_Yp>::value &&
+                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                       __nat
+                   >::type = __nat());
+    template <class _Yp, class _Dp>
+        shared_ptr(unique_ptr<_Yp, _Dp>&&,
+                   typename enable_if
+                   <
+                       is_lvalue_reference<_Dp>::value &&
+                       !is_array<_Yp>::value &&
+                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                       __nat
+                   >::type = __nat());
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    template <class _Yp, class _Dp,
-                 class = typename enable_if
-                 <
-                    !is_array<_Yp>::value &&
-                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
-                 >::type
-             > shared_ptr(unique_ptr<_Yp, _Dp>,
-       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
-    template <class _Yp, class _Dp,
-                 class = typename enable_if
-                 <
-                    !is_array<_Yp>::value &&
-                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
-                 >::type
-             >
-       shared_ptr(unique_ptr<_Yp, _Dp>,
-       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+    template <class _Yp, class _Dp>
+        shared_ptr(unique_ptr<_Yp, _Dp>,
+                   typename enable_if
+                   <
+                       !is_lvalue_reference<_Dp>::value &&
+                       !is_array<_Yp>::value &&
+                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                       __nat
+                   >::type = __nat());
+    template <class _Yp, class _Dp>
+        shared_ptr(unique_ptr<_Yp, _Dp>,
+                   typename enable_if
+                   <
+                       is_lvalue_reference<_Dp>::value &&
+                       !is_array<_Yp>::value &&
+                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                       __nat
+                   >::type = __nat());
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     ~shared_ptr();
@@ -4039,8 +4023,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
 }
 
 template<class _Tp>
-template<class _Yp, class>
-shared_ptr<_Tp>::shared_ptr(_Yp* __p)
+template<class _Yp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p,
+                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
     : __ptr_(__p)
 {
     unique_ptr<_Yp> __hold(__p);
@@ -4051,8 +4036,9 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p)
 }
 
 template<class _Tp>
-template<class _Yp, class _Dp, class>
-shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
+template<class _Yp, class _Dp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
+                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
     : __ptr_(__p)
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -4094,8 +4080,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
 }
 
 template<class _Tp>
-template<class _Yp, class _Dp, class _Alloc, class>
-shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
+template<class _Yp, class _Dp, class _Alloc>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
+                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
     : __ptr_(__p)
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -4208,12 +4195,13 @@ shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-template<class _Yp, class>
+template<class _Yp>
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
 #else
-shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
 #endif
+                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
     : __ptr_(__r.get())
 {
     typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
@@ -4223,13 +4211,19 @@ shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
 }
 
 template<class _Tp>
-template <class _Yp, class _Dp, class>
+template <class _Yp, class _Dp>
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
 #else
 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
 #endif
-           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
+                            typename enable_if
+                            <
+                                !is_lvalue_reference<_Dp>::value &&
+                                !is_array<_Yp>::value &&
+                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                                __nat
+                            >::type)
     : __ptr_(__r.get())
 {
     typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
@@ -4239,13 +4233,19 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
 }
 
 template<class _Tp>
-template <class _Yp, class _Dp, class>
+template <class _Yp, class _Dp>
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
 #else
 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
 #endif
-           typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
+                            typename enable_if
+                            <
+                                is_lvalue_reference<_Dp>::value &&
+                                !is_array<_Yp>::value &&
+                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+                                __nat
+                            >::type)
     : __ptr_(__r.get())
 {
     typedef __shared_ptr_pointer<_Yp*,
@@ -5262,7 +5262,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
 
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 
 class _LIBCPP_TYPE_VIS __sp_mut
 {
@@ -5388,7 +5388,7 @@ atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v
     return atomic_compare_exchange_weak(__p, __v, __w);
 }
 
-#endif  // __has_feature(cxx_atomic)
+#endif  // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 
 //enum class
 struct _LIBCPP_TYPE_VIS pointer_safety
diff --git a/system/include/libcxx/module.modulemap b/system/include/libcxx/module.modulemap
new file mode 100644
index 0000000000000..6aeb23f028bf2
--- /dev/null
+++ b/system/include/libcxx/module.modulemap
@@ -0,0 +1,472 @@
+module std [system] {
+  // FIXME: The standard does not require that each of these submodules
+  // re-exports its imported modules. We should provide an alternative form of
+  // export that issues a warning if a name from the submodule is used, and
+  // use that to provide a 'strict mode' for libc++.
+  module algorithm {
+    header "algorithm"
+    export initializer_list
+    export *
+  }
+  module array {
+    header "array"
+    export initializer_list
+    export *
+  }
+  module atomic {
+    header "atomic"
+    export *
+    requires cplusplus11
+  }
+  module bitset {
+    header "bitset"
+    export string
+    export iosfwd
+    export *
+  }
+  // No submodule for cassert. It fundamentally needs repeated, textual inclusion.
+  module ccomplex {
+    header "ccomplex"
+    export complex
+    export *
+  }
+  module cctype {
+    header "cctype"
+    export *
+  }
+  module cerrno {
+    header "cerrno"
+/*
+    export_macros    ECONNREFUSED, EIO,          ENODEV,      ENOTEMPTY,       ERANGE,
+      E2BIG,         ECONNRESET,   EISCONN,      ENOENT,      ENOTRECOVERABLE, EROFS,
+      EACCES,        EDEADLK,      EISDIR,       ENOEXEC,     ENOTSOCK,        ESPIPE,
+      EADDRINUSE,    EDESTADDRREQ, ELOOP,        ENOLCK,      ENOTSUP,         ESRCH,
+      EADDRNOTAVAIL, EDOM,         EMFILE,       ENOLINK,     ENOTTY,          ETIME,
+      EAFNOSUPPORT,  EEXIST,       EMLINK,       ENOMEM,      ENXIO,           ETIMEDOUT,
+      EAGAIN,        EFAULT,       EMSGSIZE,     ENOMSG,      EOPNOTSUPP,      ETXTBSY,
+      EALREADY,      EFBIG,        ENAMETOOLONG, ENOPROTOOPT, EOVERFLOW,       EWOULDBLOCK,
+      EBADF,         EHOSTUNREACH, ENETDOWN,     ENOSPC,      EOWNERDEAD,      EXDEV,
+      EBADMSG,       EIDRM,        ENETRESET,    ENOSR,       EPERM,           errno,
+      EBUSY,         EILSEQ,       ENETUNREACH,  ENOSTR,      EPIPE,
+      ECANCELED,     EINPROGRESS,  ENFILE,       ENOSYS,      EPROTO,
+      ECHILD,        EINTR,        ENOBUFS,      ENOTCONN,    EPROTONOSUPPORT,
+      ECONNABORTED,  EINVAL,       ENODATA,      ENOTDIR,     EPROTOTYPE
+*/
+    export *
+  }
+  module cfenv {
+    header "cfenv"
+/*
+    export_macros FE_ALL_EXCEPT, FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW,
+                  FE_UNDERFLOW, FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD,
+                  FE_DFL_ENV
+*/
+    export *
+  }
+  module cfloat {
+    header "cfloat"
+/*
+    export_macros FLT_EVAL_METHOD, FLT_RADIX, FLT_ROUNDS,
+                  FLT_DIG, FLT_EPSILON, FLT_MANT_DIG,
+                  FLT_MAX, FLT_MAX_10_EXP, FLT_MAX_EXP,
+                  FLT_MIN, FLT_MIN_10_EXP, FLT_MIN_EXP,
+                  DBL_DIG, DBL_EPSILON, DBL_MANT_DIG,
+                  DBL_MAX, DBL_MAX_10_EXP, DBL_MAX_EXP,
+                  DBL_MIN, DBL_MIN_10_EXP, DBL_MIN_EXP,
+                  LDBL_DIG, LDBL_EPSILON, LDBL_MANT_DIG,
+                  LDBL_MAX, LDBL_MAX_10_EXP, LDBL_MAX_EXP,
+                  LDBL_MIN, LDBL_MIN_10_EXP, LDBL_MIN_EXP
+*/
+    export *
+  }
+  module chrono {
+    header "chrono"
+    export *
+  }
+  module cinttypes {
+    header "cinttypes"
+    export cstdint
+/*
+    export_macros
+      PRId8, PRId16, PRId32, PRId64, PRIdFAST8, PRIdFAST16, PRIdFAST32, PRIdFAST64, PRIdLEAST8, PRIdLEAST16, PRIdLEAST32, PRIdLEAST64, PRIdMAX, PRIdPTR,
+      PRIi8, PRIi16, PRIi32, PRIi64, PRIiFAST8, PRIiFAST16, PRIiFAST32, PRIiFAST64, PRIiLEAST8, PRIiLEAST16, PRIiLEAST32, PRIiLEAST64, PRIiMAX, PRIiPTR,
+      PRIo8, PRIo16, PRIo32, PRIo64, PRIoFAST8, PRIoFAST16, PRIoFAST32, PRIoFAST64, PRIoLEAST8, PRIoLEAST16, PRIoLEAST32, PRIoLEAST64, PRIoMAX, PRIoPTR,
+      PRIu8, PRIu16, PRIu32, PRIu64, PRIuFAST8, PRIuFAST16, PRIuFAST32, PRIuFAST64, PRIuLEAST8, PRIuLEAST16, PRIuLEAST32, PRIuLEAST64, PRIuMAX, PRIuPTR,
+      PRIx8, PRIx16, PRIx32, PRIx64, PRIxFAST8, PRIxFAST16, PRIxFAST32, PRIxFAST64, PRIxLEAST8, PRIxLEAST16, PRIxLEAST32, PRIxLEAST64, PRIxMAX, PRIxPTR,
+      PRIX8, PRIX16, PRIX32, PRIX64, PRIXFAST8, PRIXFAST16, PRIXFAST32, PRIXFAST64, PRIXLEAST8, PRIXLEAST16, PRIXLEAST32, PRIXLEAST64, PRIXMAX, PRIXPTR,
+      SCNd8, SCNd16, SCNd32, SCNd64, SCNdFAST8, SCNdFAST16, SCNdFAST32, SCNdFAST64, SCNdLEAST8, SCNdLEAST16, SCNdLEAST32, SCNdLEAST64, SCNdMAX, SCNdPTR,
+      SCNi8, SCNi16, SCNi32, SCNi64, SCNiFAST8, SCNiFAST16, SCNiFAST32, SCNiFAST64, SCNiLEAST8, SCNiLEAST16, SCNiLEAST32, SCNiLEAST64, SCNiMAX, SCNiPTR,
+      SCNo8, SCNo16, SCNo32, SCNo64, SCNoFAST8, SCNoFAST16, SCNoFAST32, SCNoFAST64, SCNoLEAST8, SCNoLEAST16, SCNoLEAST32, SCNoLEAST64, SCNoMAX, SCNoPTR,
+      SCNu8, SCNu16, SCNu32, SCNu64, SCNuFAST8, SCNuFAST16, SCNuFAST32, SCNuFAST64, SCNuLEAST8, SCNuLEAST16, SCNuLEAST32, SCNuLEAST64, SCNuMAX, SCNuPTR,
+      SCNx8, SCNx16, SCNx32, SCNx64, SCNxFAST8, SCNxFAST16, SCNxFAST32, SCNxFAST64, SCNxLEAST8, SCNxLEAST16, SCNxLEAST32, SCNxLEAST64, SCNxMAX, SCNxPTR,
+      SCNX8, SCNX16, SCNX32, SCNX64, SCNXFAST8, SCNXFAST16, SCNXFAST32, SCNXFAST64, SCNXLEAST8, SCNXLEAST16, SCNXLEAST32, SCNXLEAST64, SCNXMAX, SCNXPTR
+*/
+    export *
+  }
+  module ciso646 {
+    header "ciso646"
+    export *
+  }
+  module climits {
+    header "climits"
+/*
+    export_macros CHAR_BIT,  CHAR_MIN,  CHAR_MAX,
+                  SCHAR_MIN, SCHAR_MAX, UCHAR_MAX,
+                  SHRT_MIN,  SHRT_MAX,  USHRT_MAX,
+                  INT_MIN,   INT_MAX,   UINT_MAX,
+                  LONG_MIN,  LONG_MAX,  ULONG_MAX,
+                  LLONG_MIN, LLONG_MAX, ULLONG_MAX,
+                  MB_LEN_MAX
+*/
+    export *
+  }
+  module clocale {
+    header "clocale"
+/*
+    export_macros LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, NULL
+*/
+    export *
+  }
+  module cmath {
+    header "cmath"
+/*
+    export_macros FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL, FP_ILOGBO, FP_ILOGBNAN,
+                  FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO,
+                  HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY, NAN,
+                  MATH_ERRNO, MATH_ERREXCEPT, math_errhandling
+*/
+    export *
+  }
+  module codecvt {
+    header "codecvt"
+    export *
+  }
+  module complex {
+    header "complex"
+    export *
+  }
+  module condition_variable {
+    header "condition_variable"
+    export *
+  }
+  module csetjmp {
+    header "csetjmp"
+/*
+    export_macros setjmp
+*/
+    export *
+  }
+  module csignal {
+    header "csignal"
+/*
+    export_macros SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM,
+                  SIG_DFL, SIG_IGN, SIG_ERR
+*/
+    export *
+  }
+  module cstdarg {
+    header "cstdarg"
+/*
+    export_macros va_arg, va_start, va_end, va_copy
+*/
+    export *
+  }
+  module cstdbool {
+    header "cstdbool"
+/*
+    export_macros __bool_true_false_are_defined
+*/
+    export *
+  }
+  module cstddef {
+    header "cstddef"
+/*
+    export_macros NULL, offsetof
+*/
+    export *
+  }
+  module cstdint {
+    header "cstdint"
+/*
+    export_macros
+      INT_8_MIN, INT_8_MAX, UINT_8_MAX, INT_16_MIN, INT_16_MAX, UINT_16_MAX,
+      INT_32_MIN, INT_32_MAX, UINT_32_MAX, INT_64_MIN, INT_64_MAX, UINT_64_MAX,
+      INT_FAST8_MIN, INT_FAST8_MAX, UINT_FAST8_MAX, INT_FAST16_MIN, INT_FAST16_MAX, UINT_FAST16_MAX,
+      INT_FAST32_MIN, INT_FAST32_MAX, UINT_FAST32_MAX, INT_FAST64_MIN, INT_FAST64_MAX, UINT_FAST64_MAX,
+      INT_LEAST8_MIN, INT_LEAST8_MAX, UINT_LEAST8_MAX, INT_LEAST16_MIN, INT_LEAST16_MAX, UINT_LEAST16_MAX,
+      INT_LEAST32_MIN, INT_LEAST32_MAX, UINT_LEAST32_MAX, INT_LEAST64_MIN, INT_LEAST64_MAX, UINT_LEAST64_MAX,
+      INT_MAX_MIN, INT_MAX_MAX, UINT_MAX_MAX, INT_PTR_MIN, INT_PTR_MAX, UINT_PTR_MAX,
+      PTRDIFF_MIN, PTRDIFF_MAX, SIG_ATOMIC_MIN, SIG_ATOMIC_MAX, WCHAR_MIN, WCHAR_MAX, WINT_MIN, WINT_MAX,
+      SIZE_MAX
+*/
+    export *
+  }
+  module cstdio {
+    header "cstdio"
+/*
+    export_macros BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_tmpnam, NULL,
+                  SEEK_CUR, SEEK_END, SEEK_SET, TMP_MAX, _IOFBF, _IOLBF,
+                  stdin, stdout, stderr
+*/
+    export *
+  }
+  module cstdlib {
+    header "cstdlib"
+/*
+    export_macros RAND_MAX
+*/
+    export *
+  }
+  module cstring {
+    header "cstring"
+/*
+    export_macros NULL
+*/
+    export *
+  }
+  module ctgmath {
+    header "ctgmath"
+    export ccomplex
+    export cmath
+    export *
+  }
+  module ctime {
+    header "ctime"
+/*
+    export_macros NULL, CLOCKS_PER_SEC
+*/
+    export *
+  }
+  module cwchar {
+    header "cwchar"
+/*
+    export_macros NULL, WCHAR_MAX, WCHAR_MIN, WEOF
+*/
+    export *
+  }
+  module cwctype {
+    header "cwctype"
+/*
+    export_macros WEOF
+*/
+    export *
+  }
+  module deque {
+    header "deque"
+    export initializer_list
+    export *
+  }
+  module exception {
+    header "exception"
+    export *
+  }
+  module forward_list {
+    header "forward_list"
+    export initializer_list
+    export *
+  }
+  module fstream {
+    header "fstream"
+    export *
+  }
+  module functional {
+    header "functional"
+    export *
+  }
+  module future {
+    header "future"
+    export *
+  }
+  module initializer_list {
+    header "initializer_list"
+    export *
+  }
+  module iomanip {
+    header "iomanip"
+    export *
+  }
+  module ios {
+    header "ios"
+    export iosfwd
+    export *
+  }
+  module iosfwd {
+    header "iosfwd"
+    export *
+  }
+  module iostream {
+    header "iostream"
+    export ios
+    export streambuf
+    export istream
+    export ostream
+    export *
+  }
+  module istream {
+    header "istream"
+    // FIXME: should re-export ios, streambuf?
+    export *
+  }
+  module iterator {
+    header "iterator"
+    export *
+  }
+  module limits {
+    header "limits"
+    export *
+  }
+  module list {
+    header "list"
+    export initializer_list
+    export *
+  }
+  module locale {
+    header "locale"
+    export *
+  }
+  module map {
+    header "map"
+    export initializer_list
+    export *
+  }
+  module memory {
+    header "memory"
+    export *
+  }
+  module mutex {
+    header "mutex"
+    export *
+  }
+  module new {
+    header "new"
+    export *
+  }
+  module numeric {
+    header "numeric"
+    export *
+  }
+  module ostream {
+    header "ostream"
+    // FIXME: should re-export ios, streambuf?
+    export *
+  }
+  module queue {
+    header "queue"
+    export initializer_list
+    export *
+  }
+  module random {
+    header "random"
+    export initializer_list
+    export *
+  }
+  module ratio {
+    header "ratio"
+    export *
+  }
+  module regex {
+    header "regex"
+    export initializer_list
+    export *
+  }
+  module scoped_allocator {
+    header "scoped_allocator"
+    export *
+  }
+  module set {
+    header "set"
+    export initializer_list
+    export *
+  }
+  module sstream {
+    header "sstream"
+    // FIXME: should re-export istream, ostream, ios, streambuf, string?
+    export *
+  }
+  module stack {
+    header "stack"
+    export initializer_list
+    export *
+  }
+  module stdexcept {
+    header "stdexcept"
+    export *
+  }
+  module streambuf {
+    header "streambuf"
+    export *
+  }
+  module string {
+    header "string"
+    export initializer_list
+    export *
+  }
+  module strstream {
+    header "strstream"
+    requires !cplusplus11
+  }
+  module system_error {
+    header "system_error"
+    export *
+  }
+  module thread {
+    header "thread"
+    export *
+  }
+  module tuple {
+    header "tuple"
+    export *
+  }
+  module type_traits {
+    header "type_traits"
+    export *
+  }
+  module typeindex {
+    header "typeindex"
+    export *
+  }
+  module typeinfo {
+    header "typeinfo"
+    export *
+  }
+  module unordered_map {
+    header "unordered_map"
+    export initializer_list
+    export *
+  }
+  module unordered_set {
+    header "unordered_set"
+    export initializer_list
+    export *
+  }
+  module utility {
+    header "utility"
+    export initializer_list
+    export *
+  }
+  module valarray {
+    header "valarray"
+    export initializer_list
+    export *
+  }
+  module vector {
+    header "vector"
+    export initializer_list
+    export *
+  }
+
+  // FIXME: These should be private.
+  module __bit_reference { header "__bit_reference" export * }
+  module __config { header "__config" export * }
+  module __debug { header "__debug" export * }
+  module __functional_base { header "__functional_base" export * }
+  module __hash_table { header "__hash_table" export * }
+  module __locale { header "__locale" export * }
+  module __mutex_base { header "__mutex_base" export * }
+  module __split_buffer { header "__split_buffer" export * }
+  module __sso_allocator { header "__sso_allocator" export * }
+  module __std_stream { header "__std_stream" export * }
+  module __tree { header "__tree" export * }
+  module __tuple { header "__tuple" export * }
+  module __undef_min_max { header "__undef_min_max" export * }
+}
diff --git a/system/include/libcxx/mutex b/system/include/libcxx/mutex
index e0c02adb59ed1..9c26356590d36 100644
--- a/system/include/libcxx/mutex
+++ b/system/include/libcxx/mutex
@@ -187,6 +187,8 @@ template<class Callable, class ...Args>
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 class _LIBCPP_TYPE_VIS recursive_mutex
 {
     pthread_mutex_t __m_;
@@ -425,7 +427,9 @@ lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-struct _LIBCPP_TYPE_VIS once_flag;
+#endif // !_LIBCPP_HAS_NO_THREADS
+
+struct _LIBCPP_TYPE_VIS_ONLY once_flag;
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
diff --git a/system/include/libcxx/new b/system/include/libcxx/new
index ea4a4a01a993d..a710ed93fb43b 100644
--- a/system/include/libcxx/new
+++ b/system/include/libcxx/new
@@ -147,4 +147,24 @@ inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _N
 inline _LIBCPP_INLINE_VISIBILITY void  operator delete  (void*, void*) _NOEXCEPT {}
 inline _LIBCPP_INLINE_VISIBILITY void  operator delete[](void*, void*) _NOEXCEPT {}
 
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
+#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
+  return ::operator new(__size);
+#else
+  return __builtin_operator_new(__size);
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
+#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
+  ::operator delete(__ptr);
+#else
+  __builtin_operator_delete(__ptr);
+#endif
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
 #endif  // _LIBCPP_NEW
diff --git a/system/include/libcxx/ostream b/system/include/libcxx/ostream
index 041314acc7568..a7af2994b6b9f 100644
--- a/system/include/libcxx/ostream
+++ b/system/include/libcxx/ostream
@@ -67,6 +67,13 @@ public:
     pos_type tellp();
     basic_ostream& seekp(pos_type);
     basic_ostream& seekp(off_type, ios_base::seekdir);
+protected:
+    basic_ostream(const basic_ostream& rhs) = delete;
+    basic_ostream(basic_ostream&& rhs);
+    // 27.7.3.3 Assign/swap
+    basic_ostream& operator=(basic_ostream& rhs) = delete;
+    basic_ostream& operator=(const basic_ostream&& rhs);
+    void swap(basic_ostream& rhs);
 };
 
 // 27.7.2.6.4 character inserters
@@ -162,14 +169,19 @@ protected:
 #endif
 
     // 27.7.2.3 Assign/swap
-#if _LIBCPP_STD_VER > 11
-    basic_ostream& operator=(const basic_ostream&) = delete;
-#endif
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     basic_ostream& operator=(basic_ostream&& __rhs);
 #endif
     void swap(basic_ostream& __rhs);
+
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+    basic_ostream           (const basic_ostream& __rhs) = delete;
+    basic_ostream& operator=(const basic_ostream& __rhs) = delete;
+#else
+    basic_ostream           (const basic_ostream& __rhs); // not defined
+    basic_ostream& operator=(const basic_ostream& __rhs); // not defined
+#endif
 public:
 
     // 27.7.2.4 Prefix/suffix:
@@ -729,7 +741,8 @@ basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
 
 template<class _CharT, class _Traits>
 basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
+__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
+                          const _CharT* __str, size_t __len)
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
     try
@@ -740,11 +753,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
         {
             typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
             if (__pad_and_output(_Ip(__os),
-                                 &__c,
+                                 __str,
                                  (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     &__c + 1 :
-                                     &__c,
-                                 &__c + 1,
+                                     __str + __len :
+                                     __str,
+                                 __str + __len,
                                  __os,
                                  __os.fill()).failed())
                 __os.setstate(ios_base::badbit | ios_base::failbit);
@@ -759,6 +772,14 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
     return __os;
 }
 
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
+{
+    return _VSTD::__put_character_sequence(__os, &__c, 1);
+}
+
 template<class _CharT, class _Traits>
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
@@ -796,129 +817,28 @@ template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, char __c)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            if (__pad_and_output(_Ip(__os),
-                                 &__c,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     &__c + 1 :
-                                     &__c,
-                                 &__c + 1,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, &__c, 1);
 }
 
 template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            if (__pad_and_output(_Ip(__os),
-                                 (char*)&__c,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     (char*)&__c + 1 :
-                                     (char*)&__c,
-                                 (char*)&__c + 1,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
 }
 
 template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            if (__pad_and_output(_Ip(__os),
-                                 (char*)&__c,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     (char*)&__c + 1 :
-                                     (char*)&__c,
-                                 (char*)&__c + 1,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
 }
 
 template<class _CharT, class _Traits>
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
-            size_t __len = _Traits::length(__str);
-            if (__pad_and_output(_Ip(__os),
-                                 __str,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     __str + __len :
-                                     __str,
-                                 __str + __len,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
 }
 
 template<class _CharT, class _Traits>
@@ -971,99 +891,23 @@ template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            size_t __len = _Traits::length(__str);
-            if (__pad_and_output(_Ip(__os),
-                                 __str,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     __str + __len :
-                                     __str,
-                                 __str + __len,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
 }
 
 template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            size_t __len = _Traits::length((const char*)__str);
-            if (__pad_and_output(_Ip(__os),
-                                 (const char*)__str,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     (const char*)__str + __len :
-                                     (const char*)__str,
-                                 (const char*)__str + __len,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    const char *__s = (const char *) __str;
+    return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
 }
 
 template<class _Traits>
 basic_ostream<char, _Traits>&
 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<char, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<char, _Traits> _Ip;
-            size_t __len = _Traits::length((const char*)__str);
-            if (__pad_and_output(_Ip(__os),
-                                 (const char*)__str,
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     (const char*)__str + __len :
-                                     (const char*)__str,
-                                 (const char*)__str + __len,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    const char *__s = (const char *) __str;
+    return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
 }
 
 template <class _CharT, class _Traits>
@@ -1233,33 +1077,7 @@ basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const basic_string<_CharT, _Traits, _Allocator>& __str)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try
-    {
-#endif  // _LIBCPP_NO_EXCEPTIONS
-        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
-        if (__s)
-        {
-            typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
-            size_t __len = __str.size();
-            if (__pad_and_output(_Ip(__os),
-                                 __str.data(),
-                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
-                                     __str.data() + __len :
-                                     __str.data(),
-                                 __str.data() + __len,
-                                 __os,
-                                 __os.fill()).failed())
-                __os.setstate(ios_base::badbit | ios_base::failbit);
-        }
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-        __os.__set_badbit_and_consider_rethrow();
-    }
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    return __os;
+    return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
 }
 
 template <class _CharT, class _Traits>
diff --git a/system/include/libcxx/random b/system/include/libcxx/random
index c0db1abacc0a0..e7053ce4ecfff 100644
--- a/system/include/libcxx/random
+++ b/system/include/libcxx/random
@@ -4009,6 +4009,8 @@ binomial_distribution<_IntType>::param_type::param_type(result_type __t, double
     }
 }
 
+// Reference: Kemp, C.D. (1986). `A modal method for generating binomial
+//           variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.
 template<class _IntType>
 template<class _URNG>
 _IntType
@@ -4035,7 +4037,8 @@ binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr)
             if (__u < 0)
                 return __rd - 1;
         }
-        --__rd;
+        if ( __rd != 0 )
+            --__rd;
         ++__ru;
         if (__ru <= __pr.__t_)
         {
diff --git a/system/include/libcxx/readme.txt b/system/include/libcxx/readme.txt
index ccac2fcdf3110..44d9fb7efa3be 100644
--- a/system/include/libcxx/readme.txt
+++ b/system/include/libcxx/readme.txt
@@ -1 +1 @@
-These files are from libc++, svn revision 195693, 2013-11-26.
+These files are from libc++, svn revision 218372, 2014-09-24.
diff --git a/system/include/libcxx/regex b/system/include/libcxx/regex
index ffe39cf1cffad..5e1c37c64e836 100644
--- a/system/include/libcxx/regex
+++ b/system/include/libcxx/regex
@@ -437,7 +437,7 @@ class match_results
 public:
     typedef sub_match<BidirectionalIterator>                  value_type;
     typedef const value_type&                                 const_reference;
-    typedef const_reference                                   reference;
+    typedef value_type&                                       reference;
     typedef /implementation-defined/                          const_iterator;
     typedef const_iterator                                    iterator;
     typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
@@ -546,6 +546,13 @@ template <class ST, class SA, class Allocator, class charT, class traits>
                 const basic_regex<charT, traits>& e,
                 regex_constants::match_flag_type flags = regex_constants::match_default);
 
+template <class ST, class SA, class Allocator, class charT, class traits>
+    bool
+    regex_match(const basic_string<charT, ST, SA>&& s,
+                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
+                const basic_regex<charT, traits>& e,
+                regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
+
 template <class charT, class traits>
     bool
     regex_match(const charT* str, const basic_regex<charT, traits>& e,
@@ -594,6 +601,13 @@ template <class ST, class SA, class Allocator, class charT, class traits>
                  const basic_regex<charT, traits>& e,
                  regex_constants::match_flag_type flags = regex_constants::match_default);
 
+template <class ST, class SA, class Allocator, class charT, class traits>
+    bool
+    regex_search(const basic_string<charT, ST, SA>&& s,
+                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
+                 const basic_regex<charT, traits>& e,
+                 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
+
 template <class OutputIterator, class BidirectionalIterator,
           class traits, class charT, class ST, class SA>
     OutputIterator
@@ -655,6 +669,10 @@ public:
     regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
                    const regex_type& re,
                    regex_constants::match_flag_type m = regex_constants::match_default);
+    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                   const regex_type&& __re,
+                   regex_constants::match_flag_type __m 
+                                     = regex_constants::match_default) = delete; // C++14
     regex_iterator(const regex_iterator&);
     regex_iterator& operator=(const regex_iterator&);
 
@@ -690,16 +708,29 @@ public:
     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                          const regex_type& re, int submatch = 0,
                          regex_constants::match_flag_type m = regex_constants::match_default);
+    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+                         const regex_type&& re, int submatch = 0,
+                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                          const regex_type& re, const vector<int>& submatches,
                          regex_constants::match_flag_type m = regex_constants::match_default);
+    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+                         const regex_type&& re, const vector<int>& submatches,
+                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                          const regex_type& re, initializer_list<int> submatches,
                          regex_constants::match_flag_type m = regex_constants::match_default);
+    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+                         const regex_type&& re, initializer_list<int> submatches,
+                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
     template <size_t N>
         regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                              const regex_type& re, const int (&submatches)[N],
                              regex_constants::match_flag_type m = regex_constants::match_default);
+    template <size_t N>
+        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
+                             const regex_type& re, const int (&submatches)[N],
+                             regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
     regex_token_iterator(const regex_token_iterator&);
     regex_token_iterator& operator=(const regex_token_iterator&);
 
@@ -1161,7 +1192,8 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
 
 // lookup_classname
 
-ctype_base::mask _LIBCPP_FUNC_VIS __get_classname(const char* __s, bool __icase);
+regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
+__get_classname(const char* __s, bool __icase);
 
 template <class _CharT>
 template <class _ForwardIterator>
@@ -2153,8 +2185,8 @@ class __bracket_expression
     vector<pair<string_type, string_type> > __ranges_;
     vector<pair<_CharT, _CharT> > __digraphs_;
     vector<string_type> __equivalences_;
-    ctype_base::mask __mask_;
-    ctype_base::mask __neg_mask_;
+    typename regex_traits<_CharT>::char_class_type __mask_;
+    typename regex_traits<_CharT>::char_class_type __neg_mask_;
     bool __negate_;
     bool __icase_;
     bool __collate_;
@@ -2250,10 +2282,10 @@ public:
     void __add_equivalence(const string_type& __s)
         {__equivalences_.push_back(__s);}
     _LIBCPP_INLINE_VISIBILITY
-    void __add_class(ctype_base::mask __mask)
+    void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
         {__mask_ |= __mask;}
     _LIBCPP_INLINE_VISIBILITY
-    void __add_neg_class(ctype_base::mask __mask)
+    void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
         {__neg_mask_ |= __mask;}
 };
 
@@ -3310,10 +3342,14 @@ basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
         _ForwardIterator __temp = _VSTD::next(__first);
         if (__temp != __last)
         {
-            if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
-            {
-                __push_back_ref(*__temp - '0');
-                __first = ++__temp;
+            if (*__first == '\\')
+            { 
+                int __val = __traits_.value(*__temp, 10);
+                if (__val >= 1 && __val <= 9)
+                {
+                    __push_back_ref(__val);
+                    __first = ++__temp;
+                }
             }
         }
     }
@@ -4052,14 +4088,19 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
                                                 _ForwardIterator __last,
                                                 int& __c)
 {
-    if (__first != __last && '0' <= *__first && *__first <= '9')
+    if (__first != __last )
     {
-        __c = *__first - '0';
-        for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
-                                                                      ++__first)
+        int __val = __traits_.value(*__first, 10);
+        if ( __val != -1 )
         {
-            __c *= 10;
-            __c += *__first - '0';
+            __c = __val;
+            for (++__first; 
+                 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
+                 ++__first)
+            {
+                __c *= 10;
+                __c += __val;
+            }
         }
     }
     return __first;
@@ -4501,6 +4542,13 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
                 __push_char(_CharT(__sum));
             ++__first;
             break;
+        case '0':
+            if (__str)
+                *__str = _CharT(0);
+            else
+                __push_char(_CharT(0));
+            ++__first;
+            break;
         default:
             if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
             {
@@ -5223,7 +5271,7 @@ private:
 public:
     _BidirectionalIterator __position_start_;
     typedef const value_type&                                 const_reference;
-    typedef const_reference                                   reference;
+    typedef value_type&                                       reference;
     typedef typename __container_type::const_iterator         const_iterator;
     typedef const_iterator                                    iterator;
     typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
@@ -5934,6 +5982,15 @@ regex_search(const basic_string<_CharT, _ST, _SA>& __s,
     return __r;
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
+bool
+regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
+             match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
+             const basic_regex<_Cp, _Tp>& __e,
+             regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; 
+#endif
+
 // regex_match
 
 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
@@ -5986,6 +6043,16 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
     return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
+            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
+            const basic_regex<_CharT, _Traits>& __e,
+            regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; 
+#endif
+
 template <class _CharT, class _Traits>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
@@ -6031,7 +6098,14 @@ public:
     regex_iterator();
     regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
                    const regex_type& __re,
-                   regex_constants::match_flag_type __m = regex_constants::match_default);
+                   regex_constants::match_flag_type __m
+                                              = regex_constants::match_default);
+#if _LIBCPP_STD_VER > 11
+    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                   const regex_type&& __re,
+                   regex_constants::match_flag_type __m 
+                                     = regex_constants::match_default) = delete;
+#endif
 
     bool operator==(const regex_iterator& __x) const;
     _LIBCPP_INLINE_VISIBILITY
@@ -6147,16 +6221,38 @@ public:
                          const regex_type& __re, int __submatch = 0,
                          regex_constants::match_flag_type __m =
                                                 regex_constants::match_default);
+#if _LIBCPP_STD_VER > 11
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type&& __re, int __submatch = 0,
+                         regex_constants::match_flag_type __m =
+                                       regex_constants::match_default) = delete;
+#endif
+
     regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
                          const regex_type& __re, const vector<int>& __submatches,
                          regex_constants::match_flag_type __m =
                                                 regex_constants::match_default);
+#if _LIBCPP_STD_VER > 11
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type&& __re, const vector<int>& __submatches,
+                         regex_constants::match_flag_type __m =
+                                     regex_constants::match_default) = delete;
+#endif
+
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
                          const regex_type& __re,
                          initializer_list<int> __submatches,
                          regex_constants::match_flag_type __m =
                                                 regex_constants::match_default);
+
+#if _LIBCPP_STD_VER > 11
+    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
+                         const regex_type&& __re,
+                         initializer_list<int> __submatches,
+                         regex_constants::match_flag_type __m =
+                                       regex_constants::match_default) = delete;
+#endif
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     template <size_t _Np>
         regex_token_iterator(_BidirectionalIterator __a,
@@ -6165,6 +6261,16 @@ public:
                              const int (&__submatches)[_Np],
                              regex_constants::match_flag_type __m =
                                                 regex_constants::match_default);
+#if _LIBCPP_STD_VER > 11
+    template <std::size_t _Np>
+        regex_token_iterator(_BidirectionalIterator __a,
+                             _BidirectionalIterator __b,
+                             const regex_type&& __re,
+                             const int (&__submatches)[_Np],
+                             regex_constants::match_flag_type __m =
+                                      regex_constants::match_default) = delete;
+#endif
+
     regex_token_iterator(const regex_token_iterator&);
     regex_token_iterator& operator=(const regex_token_iterator&);
 
@@ -6188,6 +6294,12 @@ public:
 
 private:
     void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
+    void __establish_result () {
+        if (__subs_[_N_] == -1)
+            __result_ = &__position_->prefix();
+        else
+            __result_ = &(*__position_)[__subs_[_N_]];
+        }       
 };
 
 template <class _BidirectionalIterator, class _CharT, class _Traits>
@@ -6205,12 +6317,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
     __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
 {
     if (__position_ != _Position())
-    {
-        if (__subs_[_N_] == -1)
-            __result_ = &__position_->prefix();
-        else
-            __result_ = &(*__position_)[__subs_[_N_]];
-    }
+        __establish_result ();
     else if (__subs_[_N_] == -1)
     {
         __suffix_.matched = true;
@@ -6287,7 +6394,9 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
       __subs_(__x.__subs_)
 {
     if (__x.__result_ == &__x.__suffix_)
-        __result_ == &__suffix_;
+        __result_ = &__suffix_;
+    else if ( __result_ != nullptr )
+        __establish_result ();
 }
 
 template <class _BidirectionalIterator, class _CharT, class _Traits>
@@ -6299,12 +6408,15 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
     {
         __position_ = __x.__position_;
         if (__x.__result_ == &__x.__suffix_)
-            __result_ == &__suffix_;
+            __result_ = &__suffix_;
         else
             __result_ = __x.__result_;
         __suffix_ = __x.__suffix_;
         _N_ = __x._N_;
         __subs_ = __x.__subs_;
+
+        if ( __result_ != nullptr && __result_ != &__suffix_ )
+            __establish_result();
     }
     return *this;
 }
@@ -6337,22 +6449,14 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
     else if (_N_ + 1 < __subs_.size())
     {
         ++_N_;
-        if (__subs_[_N_] == -1)
-            __result_ = &__position_->prefix();
-        else
-            __result_ = &(*__position_)[__subs_[_N_]];
+        __establish_result();
     }
     else
     {
         _N_ = 0;
         ++__position_;
         if (__position_ != _Position())
-        {
-            if (__subs_[_N_] == -1)
-                __result_ = &__position_->prefix();
-            else
-                __result_ = &(*__position_)[__subs_[_N_]];
-        }
+            __establish_result();
         else
         {
             if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
diff --git a/system/include/libcxx/set b/system/include/libcxx/set
index a537c5fe3457b..22d794da547af 100644
--- a/system/include/libcxx/set
+++ b/system/include/libcxx/set
@@ -425,14 +425,22 @@ public:
     typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit set(const value_compare& __comp = value_compare())
+    set()
         _NOEXCEPT_(
             is_nothrow_default_constructible<allocator_type>::value &&
             is_nothrow_default_constructible<key_compare>::value &&
             is_nothrow_copy_constructible<key_compare>::value)
+        : __tree_(value_compare()) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit set(const value_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__comp) {}
+
     _LIBCPP_INLINE_VISIBILITY
-    set(const value_compare& __comp, const allocator_type& __a)
+    explicit set(const value_compare& __comp, const allocator_type& __a)
         : __tree_(__comp, __a) {}
     template <class _InputIterator>
         _LIBCPP_INLINE_VISIBILITY
@@ -655,6 +663,12 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type      count(const key_type& __k) const
         {return __tree_.__count_unique(__k);}
+#if _LIBCPP_STD_VER > 11
+    template <typename _K2>
+    _LIBCPP_INLINE_VISIBILITY
+    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
+    count(const _K2& __k)                  {return __tree_.__count_unique(__k);}
+#endif
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
         {return __tree_.lower_bound(__k);}
@@ -822,14 +836,22 @@ public:
 
     // construct/copy/destroy:
     _LIBCPP_INLINE_VISIBILITY
-    explicit multiset(const value_compare& __comp = value_compare())
+    multiset()
         _NOEXCEPT_(
             is_nothrow_default_constructible<allocator_type>::value &&
             is_nothrow_default_constructible<key_compare>::value &&
             is_nothrow_copy_constructible<key_compare>::value)
+        : __tree_(value_compare()) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit multiset(const value_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__comp) {}
+
     _LIBCPP_INLINE_VISIBILITY
-    multiset(const value_compare& __comp, const allocator_type& __a)
+    explicit multiset(const value_compare& __comp, const allocator_type& __a)
         : __tree_(__comp, __a) {}
     template <class _InputIterator>
         _LIBCPP_INLINE_VISIBILITY
@@ -1050,6 +1072,12 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type      count(const key_type& __k) const
         {return __tree_.__count_multi(__k);}
+#if _LIBCPP_STD_VER > 11
+    template <typename _K2>
+    _LIBCPP_INLINE_VISIBILITY
+    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
+    count(const _K2& __k)                  {return __tree_.__count_multi(__k);}
+#endif
 
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
diff --git a/system/include/libcxx/shared_mutex b/system/include/libcxx/shared_mutex
index 5b1f53aafe81e..9b7f0bf773546 100644
--- a/system/include/libcxx/shared_mutex
+++ b/system/include/libcxx/shared_mutex
@@ -19,14 +19,14 @@
 namespace std
 {
 
-class shared_mutex
+class shared_timed_mutex
 {
 public:
-    shared_mutex();
-    ~shared_mutex();
+    shared_timed_mutex();
+    ~shared_timed_mutex();
 
-    shared_mutex(const shared_mutex&) = delete;
-    shared_mutex& operator=(const shared_mutex&) = delete;
+    shared_timed_mutex(const shared_timed_mutex&) = delete;
+    shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
 
     // Exclusive ownership
     void lock(); // blocking
@@ -112,9 +112,13 @@ template <class Mutex>
 #pragma GCC system_header
 #endif
 
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <shared_mutex> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_TYPE_VIS shared_mutex
+class _LIBCPP_TYPE_VIS shared_timed_mutex
 {
     mutex               __mut_;
     condition_variable  __gate1_;
@@ -124,11 +128,11 @@ class _LIBCPP_TYPE_VIS shared_mutex
     static const unsigned __write_entered_ = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1);
     static const unsigned __n_readers_ = ~__write_entered_;
 public:
-    shared_mutex();
-    _LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default;
+    shared_timed_mutex();
+    _LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default;
 
-    shared_mutex(const shared_mutex&) = delete;
-    shared_mutex& operator=(const shared_mutex&) = delete;
+    shared_timed_mutex(const shared_timed_mutex&) = delete;
+    shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
 
     // Exclusive ownership
     void lock();
@@ -163,7 +167,7 @@ public:
 
 template <class _Clock, class _Duration>
 bool
-shared_mutex::try_lock_until(
+shared_timed_mutex::try_lock_until(
                         const chrono::time_point<_Clock, _Duration>& __abs_time)
 {
     unique_lock<mutex> __lk(__mut_);
@@ -198,7 +202,7 @@ shared_mutex::try_lock_until(
 
 template <class _Clock, class _Duration>
 bool
-shared_mutex::try_lock_shared_until(
+shared_timed_mutex::try_lock_shared_until(
                         const chrono::time_point<_Clock, _Duration>& __abs_time)
 {
     unique_lock<mutex> __lk(__mut_);
@@ -232,7 +236,7 @@ private:
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    shared_lock() noexcept
+    shared_lock() _NOEXCEPT
         : __m_(nullptr),
           __owns_(false)
         {}
@@ -244,7 +248,7 @@ public:
         {__m_->lock_shared();}
 
     _LIBCPP_INLINE_VISIBILITY
-    shared_lock(mutex_type& __m, defer_lock_t) noexcept
+    shared_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
         : __m_(&__m),
           __owns_(false)
         {}
@@ -288,7 +292,7 @@ public:
     shared_lock& operator=(shared_lock const&) = delete;
 
     _LIBCPP_INLINE_VISIBILITY
-    shared_lock(shared_lock&& __u) noexcept
+    shared_lock(shared_lock&& __u) _NOEXCEPT
         : __m_(__u.__m_),
           __owns_(__u.__owns_)
         {
@@ -297,7 +301,7 @@ public:
         }
 
     _LIBCPP_INLINE_VISIBILITY
-    shared_lock& operator=(shared_lock&& __u) noexcept
+    shared_lock& operator=(shared_lock&& __u) _NOEXCEPT
     {
         if (__owns_)
             __m_->unlock_shared();
@@ -320,14 +324,14 @@ public:
 
     // Setters
     _LIBCPP_INLINE_VISIBILITY
-    void swap(shared_lock& __u) noexcept
+    void swap(shared_lock& __u) _NOEXCEPT
     {
         _VSTD::swap(__m_, __u.__m_);
         _VSTD::swap(__owns_, __u.__owns_);
     }
 
     _LIBCPP_INLINE_VISIBILITY
-    mutex_type* release() noexcept
+    mutex_type* release() _NOEXCEPT
     {
         mutex_type* __m = __m_;
         __m_ = nullptr;
@@ -337,13 +341,13 @@ public:
 
     // Getters
     _LIBCPP_INLINE_VISIBILITY
-    bool owns_lock() const noexcept {return __owns_;}
+    bool owns_lock() const _NOEXCEPT {return __owns_;}
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit operator bool () const noexcept {return __owns_;}
+    explicit operator bool () const _NOEXCEPT {return __owns_;}
 
     _LIBCPP_INLINE_VISIBILITY
-    mutex_type* mutex() const noexcept {return __m_;}
+    mutex_type* mutex() const _NOEXCEPT {return __m_;}
 };
 
 template <class _Mutex>
@@ -409,11 +413,13 @@ shared_lock<_Mutex>::unlock()
 template <class _Mutex>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept
+swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT
     {__x.swap(__y);}
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif  // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_STD_VER > 11
 
 #endif  // _LIBCPP_SHARED_MUTEX
diff --git a/system/include/libcxx/sstream b/system/include/libcxx/sstream
index f90d4464a4021..27ae78f9d45f5 100644
--- a/system/include/libcxx/sstream
+++ b/system/include/libcxx/sstream
@@ -325,11 +325,16 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
     __p = const_cast<char_type*>(__str_.data());
     if (__binp != -1)
         this->setg(__p + __binp, __p + __ninp, __p + __einp);
+    else
+        this->setg(nullptr, nullptr, nullptr);
     if (__bout != -1)
     {
         this->setp(__p + __bout, __p + __eout);
         this->pbump(__nout);
     }
+    else
+        this->setp(nullptr, nullptr);
+
     __hm_ = __hm == -1 ? nullptr : __p + __hm;
     __mode_ = __rhs.__mode_;
     __p = const_cast<char_type*>(__rhs.__str_.data());
diff --git a/system/include/libcxx/stdexcept b/system/include/libcxx/stdexcept
index ef5de595f032f..5fc912a644be8 100644
--- a/system/include/libcxx/stdexcept
+++ b/system/include/libcxx/stdexcept
@@ -50,6 +50,14 @@ public:
 #pragma GCC system_header
 #endif
 
+#ifndef _LIBCPP___REFSTRING
+_LIBCPP_BEGIN_NAMESPACE_STD
+class _LIBCPP_HIDDEN __libcpp_refstring {
+    const char *__imp_;
+};
+_LIBCPP_END_NAMESPACE_STD
+#endif
+
 namespace std  // purposefully not using versioning namespace
 {
 
@@ -57,7 +65,7 @@ class _LIBCPP_EXCEPTION_ABI logic_error
     : public exception
 {
 private:
-    void* __imp_;
+    _VSTD::__libcpp_refstring __imp_;
 public:
     explicit logic_error(const string&);
     explicit logic_error(const char*);
@@ -74,7 +82,7 @@ class _LIBCPP_EXCEPTION_ABI runtime_error
     : public exception
 {
 private:
-    void* __imp_;
+    _VSTD::__libcpp_refstring __imp_;
 public:
     explicit runtime_error(const string&);
     explicit runtime_error(const char*);
diff --git a/system/include/libcxx/string b/system/include/libcxx/string
index e8bd69fcabd7d..12f541e263794 100644
--- a/system/include/libcxx/string
+++ b/system/include/libcxx/string
@@ -161,7 +161,7 @@ public:
     basic_string& operator+=(initializer_list<value_type>);
 
     basic_string& append(const basic_string& str);
-    basic_string& append(const basic_string& str, size_type pos, size_type n);
+    basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
     basic_string& append(const value_type* s, size_type n);
     basic_string& append(const value_type* s);
     basic_string& append(size_type n, value_type c);
@@ -178,7 +178,7 @@ public:
 
     basic_string& assign(const basic_string& str);
     basic_string& assign(basic_string&& str);
-    basic_string& assign(const basic_string& str, size_type pos, size_type n);
+    basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
     basic_string& assign(const value_type* s, size_type n);
     basic_string& assign(const value_type* s);
     basic_string& assign(size_type n, value_type c);
@@ -189,7 +189,7 @@ public:
     basic_string& insert(size_type pos1, const basic_string& str);
     basic_string& insert(size_type pos1, const basic_string& str,
                          size_type pos2, size_type n);
-    basic_string& insert(size_type pos, const value_type* s, size_type n);
+    basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
     basic_string& insert(size_type pos, const value_type* s);
     basic_string& insert(size_type pos, size_type n, value_type c);
     iterator      insert(const_iterator p, value_type c);
@@ -204,7 +204,7 @@ public:
 
     basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
     basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
-                          size_type pos2, size_type n2);
+                          size_type pos2, size_type n2=npos); // C++14
     basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
     basic_string& replace(size_type pos, size_type n1, const value_type* s);
     basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
@@ -261,7 +261,7 @@ public:
     int compare(const basic_string& str) const noexcept;
     int compare(size_type pos1, size_type n1, const basic_string& str) const;
     int compare(size_type pos1, size_type n1, const basic_string& str,
-                size_type pos2, size_type n2) const;
+                size_type pos2, size_type n2=npos) const; // C++14
     int compare(const value_type* s) const noexcept;
     int compare(size_type pos1, size_type n1, const value_type* s) const;
     int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
@@ -453,6 +453,8 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
 
 #include <__undef_min_max>
 
+#include <__debug>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
@@ -507,14 +509,11 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits
     typedef streampos pos_type;
     typedef mbstate_t state_type;
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
+    static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
@@ -524,20 +523,15 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  to_int_type(char_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool      eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool      eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
         {return int_type(EOF);}
 };
 
@@ -634,51 +628,37 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
     typedef streampos pos_type;
     typedef mbstate_t state_type;
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
+    static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
             {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return (unsigned char)__c1 < (unsigned char)__c2;}
 
-    _LIBCPP_INLINE_VISIBILITY
-    static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
+    static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
         {return memcmp(__s1, __s2, __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static size_t length(const char_type* __s) {return strlen(__s);}
-    _LIBCPP_INLINE_VISIBILITY
-    static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
+    static inline size_t length(const char_type* __s) {return strlen(__s);}
+    static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
         {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
+    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
         {return (char_type*)memmove(__s1, __s2, __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
+    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
         {
             _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
             return (char_type*)memcpy(__s1, __s2, __n);
         }
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* assign(char_type* __s, size_t __n, char_type __a)
+    static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
         {return (char_type*)memset(__s, to_int_type(__a), __n);}
 
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type((unsigned char)__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
         {return int_type(EOF);}
 };
 
@@ -693,52 +673,38 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
     typedef streampos pos_type;
     typedef mbstate_t state_type;
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
+    static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
-    _LIBCPP_INLINE_VISIBILITY
-    static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
+    static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
         {return wmemcmp(__s1, __s2, __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static size_t length(const char_type* __s)
+    static inline size_t length(const char_type* __s)
         {return wcslen(__s);}
-    _LIBCPP_INLINE_VISIBILITY
-    static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
+    static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
         {return (const char_type*)wmemchr(__s, __a, __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
+    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
         {return (char_type*)wmemmove(__s1, __s2, __n);}
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
+    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
         {
             _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
             return (char_type*)wmemcpy(__s1, __s2, __n);
         }
-    _LIBCPP_INLINE_VISIBILITY
-    static char_type* assign(char_type* __s, size_t __n, char_type __a)
+    static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
         {return (char_type*)wmemset(__s, __a, __n);}
 
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(WEOF);}
 };
 
@@ -753,14 +719,11 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
     typedef u16streampos   pos_type;
     typedef mbstate_t      state_type;
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
+    static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
@@ -770,20 +733,15 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(0xDFFF);}
 };
 
@@ -874,14 +832,11 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
     typedef u32streampos   pos_type;
     typedef mbstate_t      state_type;
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
+    static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
@@ -891,20 +846,15 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
-    _LIBCPP_INLINE_VISIBILITY
-    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
+    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(0xFFFFFFFF);}
 };
 
@@ -988,6 +938,191 @@ char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
 
 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
 
+// helper fns for basic_string
+
+// __str_find
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find(const _CharT *__p, _SizeT __sz, 
+             _CharT __c, _SizeT __pos) _NOEXCEPT
+{
+    if (__pos >= __sz)
+        return __npos;
+    const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
+    if (__r == 0)
+        return __npos;
+    return static_cast<_SizeT>(__r - __p);
+}
+
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find(const _CharT *__p, _SizeT __sz, 
+       const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+{
+    if (__pos > __sz || __sz - __pos < __n)
+        return __npos;
+    if (__n == 0)
+        return __pos;
+    const _CharT* __r = 
+        _VSTD::__search(__p + __pos, __p + __sz,
+                        __s, __s + __n, _Traits::eq,
+                        random_access_iterator_tag(), random_access_iterator_tag());
+    if (__r == __p + __sz)
+        return __npos;
+    return static_cast<_SizeT>(__r - __p);
+}
+
+
+// __str_rfind
+
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_rfind(const _CharT *__p, _SizeT __sz, 
+              _CharT __c, _SizeT __pos) _NOEXCEPT
+{
+    if (__sz < 1)
+        return __npos;
+    if (__pos < __sz)
+        ++__pos;
+    else
+        __pos = __sz;
+    for (const _CharT* __ps = __p + __pos; __ps != __p;)
+    {
+        if (_Traits::eq(*--__ps, __c))
+            return static_cast<_SizeT>(__ps - __p);
+    }
+    return __npos;
+}
+
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_rfind(const _CharT *__p, _SizeT __sz, 
+        const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+{
+    __pos = _VSTD::min(__pos, __sz);
+    if (__n < __sz - __pos)
+        __pos += __n;
+    else
+        __pos = __sz;
+    const _CharT* __r = _VSTD::__find_end(
+                  __p, __p + __pos, __s, __s + __n, _Traits::eq, 
+                        random_access_iterator_tag(), random_access_iterator_tag());
+    if (__n > 0 && __r == __p + __pos)
+        return __npos;
+    return static_cast<_SizeT>(__r - __p);
+}
+
+// __str_find_first_of
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find_first_of(const _CharT *__p, _SizeT __sz,
+                const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+{
+    if (__pos >= __sz || __n == 0)
+        return __npos;
+    const _CharT* __r = _VSTD::__find_first_of_ce
+        (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
+    if (__r == __p + __sz)
+        return __npos;
+    return static_cast<_SizeT>(__r - __p);
+}
+
+
+// __str_find_last_of
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 
+__str_find_last_of(const _CharT *__p, _SizeT __sz,
+               const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+    {
+    if (__n != 0)
+    {
+        if (__pos < __sz)
+            ++__pos;
+        else
+            __pos = __sz;
+        for (const _CharT* __ps = __p + __pos; __ps != __p;)
+        {
+            const _CharT* __r = _Traits::find(__s, __n, *--__ps);
+            if (__r)
+                return static_cast<_SizeT>(__ps - __p);
+        }
+    }
+    return __npos;
+}
+
+
+// __str_find_first_not_of
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
+                    const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+{
+    if (__pos < __sz)
+    {
+        const _CharT* __pe = __p + __sz;
+        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
+            if (_Traits::find(__s, __n, *__ps) == 0)
+                return static_cast<_SizeT>(__ps - __p);
+    }
+    return __npos;
+}
+
+
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
+                          _CharT __c, _SizeT __pos) _NOEXCEPT
+{
+    if (__pos < __sz)
+    {
+        const _CharT* __pe = __p + __sz;
+        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
+            if (!_Traits::eq(*__ps, __c))
+                return static_cast<_SizeT>(__ps - __p);
+    }
+    return __npos;
+}
+
+
+// __str_find_last_not_of
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
+                   const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
+{
+    if (__pos < __sz)
+        ++__pos;
+    else
+        __pos = __sz;
+    for (const _CharT* __ps = __p + __pos; __ps != __p;)
+        if (_Traits::find(__s, __n, *--__ps) == 0)
+            return static_cast<_SizeT>(__ps - __p);
+    return __npos;
+}
+
+
+template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
+                         _CharT __c, _SizeT __pos) _NOEXCEPT
+{
+    if (__pos < __sz)
+        ++__pos;
+    else
+        __pos = __sz;
+    for (const _CharT* __ps = __p + __pos; __ps != __p;)
+        if (!_Traits::eq(*--__ps, __c))
+            return static_cast<_SizeT>(__ps - __p);
+    return __npos;
+}
+
+template<class _Ptr>
+size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
+{
+    typedef typename iterator_traits<_Ptr>::value_type value_type;
+    return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
+}
+
 // basic_string
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -1324,7 +1459,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     basic_string& append(const basic_string& __str);
-    basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
+    basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
     basic_string& append(const value_type* __s, size_type __n);
     basic_string& append(const value_type* __s);
     basic_string& append(size_type __n, value_type __c);
@@ -1363,7 +1498,7 @@ public:
     basic_string& assign(basic_string&& str)
         {*this = _VSTD::move(str); return *this;}
 #endif
-    basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
+    basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
     basic_string& assign(const value_type* __s, size_type __n);
     basic_string& assign(const value_type* __s);
     basic_string& assign(size_type __n, value_type __c);
@@ -1389,7 +1524,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     basic_string& insert(size_type __pos1, const basic_string& __str);
-    basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
+    basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
     basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
     basic_string& insert(size_type __pos, const value_type* __s);
     basic_string& insert(size_type __pos, size_type __n, value_type __c);
@@ -1425,7 +1560,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY
     basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
-    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
+    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
     basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
     basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
     basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
@@ -1517,7 +1652,7 @@ public:
     int compare(const basic_string& __str) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
-    int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
+    int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
     int compare(const value_type* __s) const _NOEXCEPT;
     int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
     int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
@@ -1951,11 +2086,13 @@ inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
     : __r_(__a)
 {
-    if (__a == __str.__alloc() || !__str.__is_long())
-        __r_.first().__r = __str.__r_.first().__r;
-    else
+    if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
         __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
-    __str.__zero();
+    else
+    {
+        __r_.first().__r = __str.__r_.first().__r;
+        __str.__zero();
+    }
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->__insert_c(this);
     if (__is_long())
@@ -2209,7 +2346,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign recieved nullptr");
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
     size_type __cap = capacity();
     if (__cap >= __n)
     {
@@ -2383,7 +2520,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::assign recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
     return assign(__s, traits_type::length(__s));
 }
 
@@ -2393,7 +2530,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append recieved nullptr");
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
     size_type __cap = capacity();
     size_type __sz = size();
     if (__cap - __sz >= __n)
@@ -2530,7 +2667,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::append recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
     return append(__s, traits_type::length(__s));
 }
 
@@ -2540,7 +2677,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert recieved nullptr");
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
     size_type __sz = size();
     if (__pos > __sz)
         this->__throw_out_of_range();
@@ -2692,7 +2829,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::insert recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
     return insert(__pos, __s, traits_type::length(__s));
 }
 
@@ -2743,7 +2880,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
 {
-    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace recieved nullptr");
+    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
     size_type __sz = size();
     if (__pos > __sz)
         this->__throw_out_of_range();
@@ -2875,7 +3012,7 @@ template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::replace recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
     return replace(__pos, __n1, __s, traits_type::length(__s));
 }
 
@@ -3243,18 +3380,9 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
                                                 size_type __pos,
                                                 size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): recieved nullptr");
-    size_type __sz = size();
-    if (__pos > __sz || __sz - __pos < __n)
-        return npos;
-    if (__n == 0)
-        return __pos;
-    const value_type* __p = data();
-    const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
-                                     __traits_eq<traits_type>());
-    if (__r == __p + __sz)
-        return npos;
-    return static_cast<size_type>(__r - __p);
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
+    return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3263,7 +3391,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
                                                 size_type __pos) const _NOEXCEPT
 {
-    return find(__str.data(), __pos, __str.size());
+    return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3272,8 +3401,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
                                                 size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::find(): recieved nullptr");
-    return find(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
+    return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3281,14 +3411,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
                                                 size_type __pos) const _NOEXCEPT
 {
-    size_type __sz = size();
-    if (__pos >= __sz)
-        return npos;
-    const value_type* __p = data();
-    const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
-    if (__r == 0)
-        return npos;
-    return static_cast<size_type>(__r - __p);
+    return _VSTD::__str_find<value_type, size_type, traits_type, npos>
+        (data(), size(), __c, __pos);
 }
 
 // rfind
@@ -3299,19 +3423,9 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
                                                  size_type __pos,
                                                  size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): recieved nullptr");
-    size_type __sz = size();
-    __pos = _VSTD::min(__pos, __sz);
-    if (__n < __sz - __pos)
-        __pos += __n;
-    else
-        __pos = __sz;
-    const value_type* __p = data();
-    const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
-                                       __traits_eq<traits_type>());
-    if (__n > 0 && __r == __p + __pos)
-        return npos;
-    return static_cast<size_type>(__r - __p);
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
+    return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3320,7 +3434,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
                                                  size_type __pos) const _NOEXCEPT
 {
-    return rfind(__str.data(), __pos, __str.size());
+    return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3329,8 +3444,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
                                                  size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): recieved nullptr");
-    return rfind(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
+    return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3338,21 +3454,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
                                                  size_type __pos) const _NOEXCEPT
 {
-    size_type __sz = size();
-    if (__sz)
-    {
-        if (__pos < __sz)
-            ++__pos;
-        else
-            __pos = __sz;
-        const value_type* __p = data();
-        for (const value_type* __ps = __p + __pos; __ps != __p;)
-        {
-            if (traits_type::eq(*--__ps, __c))
-                return static_cast<size_type>(__ps - __p);
-        }
-    }
-    return npos;
+    return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
+        (data(), size(), __c, __pos);
 }
 
 // find_first_of
@@ -3363,16 +3466,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
                                                          size_type __pos,
                                                          size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): recieved nullptr");
-    size_type __sz = size();
-    if (__pos >= __sz || __n == 0)
-        return npos;
-    const value_type* __p = data();
-    const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
-                                            __s + __n, __traits_eq<traits_type>());
-    if (__r == __p + __sz)
-        return npos;
-    return static_cast<size_type>(__r - __p);
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
+    return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3381,7 +3477,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
                                                          size_type __pos) const _NOEXCEPT
 {
-    return find_first_of(__str.data(), __pos, __str.size());
+    return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3390,8 +3487,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
                                                          size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): recieved nullptr");
-    return find_first_of(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
+    return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3411,23 +3509,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
                                                         size_type __pos,
                                                         size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): recieved nullptr");
-    if (__n != 0)
-    {
-        size_type __sz = size();
-        if (__pos < __sz)
-            ++__pos;
-        else
-            __pos = __sz;
-        const value_type* __p = data();
-        for (const value_type* __ps = __p + __pos; __ps != __p;)
-        {
-            const value_type* __r = traits_type::find(__s, __n, *--__ps);
-            if (__r)
-                return static_cast<size_type>(__ps - __p);
-        }
-    }
-    return npos;
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
+    return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3436,7 +3520,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
                                                         size_type __pos) const _NOEXCEPT
 {
-    return find_last_of(__str.data(), __pos, __str.size());
+    return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3445,8 +3530,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
                                                         size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): recieved nullptr");
-    return find_last_of(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
+    return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3466,17 +3552,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _
                                                              size_type __pos,
                                                              size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): recieved nullptr");
-    size_type __sz = size();
-    if (__pos < __sz)
-    {
-        const value_type* __p = data();
-        const value_type* __pe = __p + __sz;
-        for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
-            if (traits_type::find(__s, __n, *__ps) == 0)
-                return static_cast<size_type>(__ps - __p);
-    }
-    return npos;
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
+    return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3485,7 +3563,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
                                                              size_type __pos) const _NOEXCEPT
 {
-    return find_first_not_of(__str.data(), __pos, __str.size());
+    return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3494,8 +3573,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
                                                              size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): recieved nullptr");
-    return find_first_not_of(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
+    return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3504,16 +3584,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
                                                              size_type __pos) const _NOEXCEPT
 {
-    size_type __sz = size();
-    if (__pos < __sz)
-    {
-        const value_type* __p = data();
-        const value_type* __pe = __p + __sz;
-        for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
-            if (!traits_type::eq(*__ps, __c))
-                return static_cast<size_type>(__ps - __p);
-    }
-    return npos;
+    return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __c, __pos);
 }
 
 // find_last_not_of
@@ -3524,17 +3596,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __
                                                             size_type __pos,
                                                             size_type __n) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): recieved nullptr");
-    size_type __sz = size();
-    if (__pos < __sz)
-        ++__pos;
-    else
-        __pos = __sz;
-    const value_type* __p = data();
-    for (const value_type* __ps = __p + __pos; __ps != __p;)
-        if (traits_type::find(__s, __n, *--__ps) == 0)
-            return static_cast<size_type>(__ps - __p);
-    return npos;
+    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
+    return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, __n);
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3543,7 +3607,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
                                                             size_type __pos) const _NOEXCEPT
 {
-    return find_last_not_of(__str.data(), __pos, __str.size());
+    return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __str.data(), __pos, __str.size());
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3552,8 +3617,9 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
                                                             size_type __pos) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): recieved nullptr");
-    return find_last_not_of(__s, __pos, traits_type::length(__s));
+    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
+    return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __s, __pos, traits_type::length(__s));
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3562,16 +3628,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
                                                             size_type __pos) const _NOEXCEPT
 {
-    size_type __sz = size();
-    if (__pos < __sz)
-        ++__pos;
-    else
-        __pos = __sz;
-    const value_type* __p = data();
-    for (const value_type* __ps = __p + __pos; __ps != __p;)
-        if (!traits_type::eq(*--__ps, __c))
-            return static_cast<size_type>(__ps - __p);
-    return npos;
+    return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
+        (data(), size(), __c, __pos);
 }
 
 // compare
@@ -3623,7 +3681,7 @@ template <class _CharT, class _Traits, class _Allocator>
 int
 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
     return compare(0, npos, __s, traits_type::length(__s));
 }
 
@@ -3633,7 +3691,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
                                                    size_type __n1,
                                                    const value_type* __s) const
 {
-    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
+    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
     return compare(__pos1, __n1, __s, traits_type::length(__s));
 }
 
@@ -3644,7 +3702,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
                                                    const value_type* __s,
                                                    size_type __n2) const
 {
-    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): recieved nullptr");
+    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
     size_type __sz = size();
     if (__pos1 > __sz || __n2 == npos)
         this->__throw_out_of_range();
@@ -4060,13 +4118,6 @@ template<class _CharT, class _Traits, class _Allocator>
     const typename basic_string<_CharT, _Traits, _Allocator>::size_type
                    basic_string<_CharT, _Traits, _Allocator>::npos;
 
-template<class _Ptr>
-size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
-{
-    typedef typename iterator_traits<_Ptr>::value_type value_type;
-    return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
-}
-
 template<class _CharT, class _Traits, class _Allocator>
 struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
     : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
diff --git a/system/include/libcxx/support/android/locale_bionic.h b/system/include/libcxx/support/android/locale_bionic.h
new file mode 100644
index 0000000000000..3a020da67e6bd
--- /dev/null
+++ b/system/include/libcxx/support/android/locale_bionic.h
@@ -0,0 +1,31 @@
+// -*- C++ -*-
+//===------------------- support/android/locale_bionic.h ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
+#define _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
+
+#if defined(__ANDROID__)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdlib.h>
+#include <xlocale.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+// Share implementation with Newlib
+#include <support/xlocale/xlocale.h>
+
+#endif // defined(__ANDROID__)
+#endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
diff --git a/system/include/libcxx/support/newlib/xlocale.h b/system/include/libcxx/support/newlib/xlocale.h
new file mode 100644
index 0000000000000..d067cf85a3bcb
--- /dev/null
+++ b/system/include/libcxx/support/newlib/xlocale.h
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
+#define _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
+
+#if defined(_NEWLIB_VERSION)
+
+#include <cstdlib>
+#include <clocale>
+#include <cwctype>
+#include <ctype.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Patch over newlib's lack of extended locale support
+typedef void *locale_t;
+static inline locale_t duplocale(locale_t) {
+  return NULL;
+}
+
+static inline void freelocale(locale_t) {
+}
+
+static inline locale_t newlocale(int, const char *, locale_t) {
+  return NULL;
+}
+
+static inline locale_t uselocale(locale_t) {
+  return NULL;
+}
+
+#define LC_COLLATE_MASK  (1 << LC_COLLATE)
+#define LC_CTYPE_MASK    (1 << LC_CTYPE)
+#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
+#define LC_MONETARY_MASK (1 << LC_MONETARY)
+#define LC_NUMERIC_MASK  (1 << LC_NUMERIC)
+#define LC_TIME_MASK     (1 << LC_TIME)
+#define LC_ALL_MASK (LC_COLLATE_MASK|\
+                     LC_CTYPE_MASK|\
+                     LC_MONETARY_MASK|\
+                     LC_NUMERIC_MASK|\
+                     LC_TIME_MASK|\
+                     LC_MESSAGES_MASK)
+
+// Share implementation with Android's Bionic
+#include <support/xlocale/xlocale.h>
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NEWLIB_VERSION
+
+#endif
diff --git a/system/include/libcxx/support/solaris/floatingpoint.h b/system/include/libcxx/support/solaris/floatingpoint.h
index 21b0349aa593b..999d144b1f2e5 100644
--- a/system/include/libcxx/support/solaris/floatingpoint.h
+++ b/system/include/libcxx/support/solaris/floatingpoint.h
@@ -1,3 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #define atof sun_atof
 #define strtod sun_strtod
 #include_next "floatingpoint.h"
diff --git a/system/include/libcxx/support/solaris/wchar.h b/system/include/libcxx/support/solaris/wchar.h
index 05a7241789d35..0e8e660c8bd4f 100644
--- a/system/include/libcxx/support/solaris/wchar.h
+++ b/system/include/libcxx/support/solaris/wchar.h
@@ -1,3 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 #define iswalpha sun_iswalpha
 #define iswupper sun_iswupper
 #define iswlower sun_iswlower
diff --git a/system/include/libcxx/support/solaris/xlocale.h b/system/include/libcxx/support/solaris/xlocale.h
index 359508d9f8f0b..875a39add760f 100644
--- a/system/include/libcxx/support/solaris/xlocale.h
+++ b/system/include/libcxx/support/solaris/xlocale.h
@@ -1,3 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
 ////////////////////////////////////////////////////////////////////////////////
 // Minimal xlocale implementation for Solaris.  This implements the subset of
 // the xlocale APIs that libc++ depends on.
diff --git a/system/include/libcxx/support/win32/support.h b/system/include/libcxx/support/win32/support.h
index ed1986e6954ac..bc96587f58c41 100644
--- a/system/include/libcxx/support/win32/support.h
+++ b/system/include/libcxx/support/win32/support.h
@@ -11,12 +11,19 @@
 #ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
 #define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
 
-/*
-   Functions and constants used in libc++ that are missing from the Windows C library.
-  */
+// Functions and constants used in libc++ that
+// are missing from the Windows C library.
 
-#include <wchar.h>  // mbstate_t
+#include <wchar.h> // mbstate_t
 #include <cstdarg> // va_ macros
+// "builtins" not implemented here for Clang or GCC as they provide
+// implementations. Assuming required for elsewhere else, certainly MSVC.
+#if defined(_LIBCPP_MSVC)
+#include <intrin.h>
+#endif
+#if defined(_LIBCPP_MSVCRT)
+#include <xlocinfo.h>
+#endif
 #define swprintf _snwprintf
 #define vswprintf _vsnwprintf
 
@@ -26,93 +33,171 @@
 
 extern "C" {
 
-int vasprintf( char **sptr, const char *__restrict fmt, va_list ap );
-int asprintf( char **sptr, const char *__restrict fmt, ...);
-size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
-                   size_t nmc, size_t len, mbstate_t *__restrict ps );
-size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
-                   size_t nwc, size_t len, mbstate_t *__restrict ps );
+int vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
+int asprintf(char **sptr, const char *__restrict fmt, ...);
+size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
+                  size_t nmc, size_t len, mbstate_t *__restrict ps);
+size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
+                  size_t nwc, size_t len, mbstate_t *__restrict ps);
 }
 
 #if defined(_LIBCPP_MSVCRT)
 #define snprintf _snprintf
-#include <xlocinfo.h>
 #define atoll _atoi64
 #define strtoll _strtoi64
 #define strtoull _strtoui64
 #define wcstoll _wcstoi64
 #define wcstoull _wcstoui64
-_LIBCPP_ALWAYS_INLINE float strtof( const char *nptr, char **endptr )
-{ return _Stof(nptr, endptr, 0); }
-_LIBCPP_ALWAYS_INLINE double strtod( const char *nptr, char **endptr )
-{ return _Stod(nptr, endptr, 0); }
-_LIBCPP_ALWAYS_INLINE long double strtold( const char *nptr, char **endptr )
-{ return _Stold(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE float strtof(const char *nptr, char **endptr)
+{
+  return _Stof(nptr, endptr, 0);
+}
+_LIBCPP_ALWAYS_INLINE double strtod(const char *nptr, char **endptr)
+{
+  return _Stod(nptr, endptr, 0);
+}
+_LIBCPP_ALWAYS_INLINE long double strtold(const char *nptr, char **endptr)
+{
+  return _Stold(nptr, endptr, 0);
+}
 
 #define _Exit _exit
+#endif
 
-#ifndef __clang__ // MSVC-based Clang also defines _MSC_VER
-#include <intrin.h>
+#if defined(_LIBCPP_MSVC)
 
-_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
-   static const unsigned int m1 = 0x55555555; //binary: 0101...
-   static const unsigned int m2 = 0x33333333; //binary: 00110011..
-   static const unsigned int m4 = 0x0f0f0f0f; //binary:  4 zeros,  4 ones ...
-   static const unsigned int h01= 0x01010101; //the sum of 256 to the power of 0,1,2,3...
-   x -= (x >> 1) & m1;             //put count of each 2 bits into those 2 bits
-   x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
-   x = (x + (x >> 4)) & m4;        //put count of each 8 bits into those 8 bits
-   return (x * h01) >> 24;  //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24)
+// Bit builtin's make these assumptions when calling _BitScanForward/Reverse
+// etc. These assumptions are expected to be true for Win32/Win64 which this
+// file supports.
+static_assert(sizeof(unsigned long long) == 8, "");
+static_assert(sizeof(unsigned long) == 4, "");
+static_assert(sizeof(unsigned int) == 4, "");
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x)
+{
+  // Binary: 0101...
+  static const unsigned int m1 = 0x55555555;
+  // Binary: 00110011..
+  static const unsigned int m2 = 0x33333333;
+  // Binary:  4 zeros,  4 ones ...
+  static const unsigned int m4 = 0x0f0f0f0f;
+  // The sum of 256 to the power of 0,1,2,3...
+  static const unsigned int h01 = 0x01010101;
+  // Put count of each 2 bits into those 2 bits.
+  x -= (x >> 1) & m1;
+  // Put count of each 4 bits into those 4 bits.
+  x = (x & m2) + ((x >> 2) & m2);
+  // Put count of each 8 bits into those 8 bits.
+  x = (x + (x >> 4)) & m4;
+  // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24).
+  return (x * h01) >> 24;
 }
 
-_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x) {
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x)
+{
   return __builtin_popcount(static_cast<int>(x));
 }
 
-_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
-   static const unsigned long long m1  = 0x5555555555555555; //binary: 0101...
-   static const unsigned long long m2  = 0x3333333333333333; //binary: 00110011..
-   static const unsigned long long m4  = 0x0f0f0f0f0f0f0f0f; //binary:  4 zeros,  4 ones ...
-   static const unsigned long long h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3...
-   x -= (x >> 1) & m1;             //put count of each 2 bits into those 2 bits
-   x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
-   x = (x + (x >> 4)) & m4;        //put count of each 8 bits into those 8 bits
-   return static_cast<int>((x * h01)>>56);  //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x)
+{
+  // Binary: 0101...
+  static const unsigned long long m1 = 0x5555555555555555;
+  // Binary: 00110011..
+  static const unsigned long long m2 = 0x3333333333333333;
+  // Binary:  4 zeros,  4 ones ...
+  static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
+  // The sum of 256 to the power of 0,1,2,3...
+  static const unsigned long long h01 = 0x0101010101010101;
+  // Put count of each 2 bits into those 2 bits.
+  x -= (x >> 1) & m1;
+  // Put count of each 4 bits into those 4 bits.
+  x = (x & m2) + ((x >> 2) & m2);
+  // Put count of each 8 bits into those 8 bits.
+  x = (x + (x >> 4)) & m4;
+  // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
+  return static_cast<int>((x * h01) >> 56);
 }
 
-_LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int x )
+// Returns the number of trailing 0-bits in x, starting at the least significant
+// bit position. If x is 0, the result is undefined.
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
 {
-   DWORD r = 0;
-   _BitScanReverse(&r, x);
-   return static_cast<int>(r);
+  unsigned long where;
+// Search from LSB to MSB for first set bit.
+// Returns zero if no set bit is found.
+#if defined(_WIN64)
+  if (_BitScanForward64(&where, mask))
+    return static_cast<int>(where);
+#elif defined(_WIN32)
+  // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
+  // Scan the Low Word.
+  if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
+    return static_cast<int>(where);
+  // Scan the High Word.
+  if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
+    return static_cast<int>(where + 32); // Create a bit offset from the LSB.
+#else
+#error "Implementation of __builtin_ctzll required"
+#endif
+  return 64;
 }
 
-// sizeof(long) == sizeof(int) on Windows
-_LIBCPP_ALWAYS_INLINE int __builtin_ctzl( unsigned long x )
-{ return __builtin_ctz( static_cast<int>(x) ); }
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzl(unsigned long mask)
+{
+  unsigned long where;
+  // Search from LSB to MSB for first set bit.
+  // Returns zero if no set bit is found.
+  if (_BitScanForward(&where, mask))
+    return static_cast<int>(where);
+  return 32;
+}
 
-_LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long x )
+_LIBCPP_ALWAYS_INLINE int __builtin_ctz(unsigned int mask)
 {
-    DWORD r = 0;
-    _BitScanReverse64(&r, x);
-    return static_cast<int>(r);
+  // Win32 and Win64 expectations.
+  static_assert(sizeof(mask) == 4, "");
+  static_assert(sizeof(unsigned long) == 4, "");
+  return __builtin_ctzl(static_cast<unsigned long>(mask));
 }
-_LIBCPP_ALWAYS_INLINE int __builtin_clz( unsigned int x )
+
+// Returns the number of leading 0-bits in x, starting at the most significant
+// bit position. If x is 0, the result is undefined.
+_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
+{
+  unsigned long where;
+// BitScanReverse scans from MSB to LSB for first set bit.
+// Returns 0 if no set bit is found.
+#if defined(_WIN64)
+  if (_BitScanReverse64(&where, mask))
+    return static_cast<int>(63 - where);
+#elif defined(_WIN32)
+  // Scan the high 32 bits.
+  if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
+    return static_cast<int>(63 -
+                            (where + 32)); // Create a bit offset from the MSB.
+  // Scan the low 32 bits.
+  if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
+    return static_cast<int>(63 - where);
+#else
+#error "Implementation of __builtin_clzll required"
+#endif
+  return 64; // Undefined Behavior.
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_clzl(unsigned long mask)
 {
-   DWORD r = 0;
-   _BitScanForward(&r, x);
-   return static_cast<int>(r);
+  unsigned long where;
+  // Search from LSB to MSB for first set bit.
+  // Returns zero if no set bit is found.
+  if (_BitScanReverse(&where, mask))
+    return static_cast<int>(31 - where);
+  return 32; // Undefined Behavior.
 }
-// sizeof(long) == sizeof(int) on Windows
-_LIBCPP_ALWAYS_INLINE int __builtin_clzl( unsigned long x )
-{ return __builtin_clz( static_cast<int>(x) ); }
-_LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x )
+
+_LIBCPP_ALWAYS_INLINE int __builtin_clz(unsigned int x)
 {
-    DWORD r = 0;
-    _BitScanForward64(&r, x);
-    return static_cast<int>(r);
+  return __builtin_clzl(x);
 }
-#endif // !__clang__
-#endif // _LIBCPP_MSVCRT
+#endif // _LIBCPP_MSVC
 
 #endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
diff --git a/system/include/libcxx/support/xlocale/xlocale.h b/system/include/libcxx/support/xlocale/xlocale.h
new file mode 100644
index 0000000000000..99f710e8f44ea
--- /dev/null
+++ b/system/include/libcxx/support/xlocale/xlocale.h
@@ -0,0 +1,194 @@
+// -*- C++ -*-
+//===------------------- support/xlocale/xlocale.h ------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// This is a shared implementation of a shim to provide extended locale support
+// on top of libc's that don't support it (like Android's bionic, and Newlib).
+//
+// The 'illusion' only works when the specified locale is "C" or "POSIX", but
+// that's about as good as we can do without implementing full xlocale support
+// in the underlying libc.
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
+#define _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline int isalnum_l(int c, locale_t) {
+  return isalnum(c);
+}
+
+static inline int isalpha_l(int c, locale_t) {
+  return isalpha(c);
+}
+
+static inline int isblank_l(int c, locale_t) {
+  return isblank(c);
+}
+
+static inline int iscntrl_l(int c, locale_t) {
+  return iscntrl(c);
+}
+
+static inline int isdigit_l(int c, locale_t) {
+  return isdigit(c);
+}
+
+static inline int isgraph_l(int c, locale_t) {
+  return isgraph(c);
+}
+
+static inline int islower_l(int c, locale_t) {
+  return islower(c);
+}
+
+static inline int isprint_l(int c, locale_t) {
+  return isprint(c);
+}
+
+static inline int ispunct_l(int c, locale_t) {
+  return ispunct(c);
+}
+
+static inline int isspace_l(int c, locale_t) {
+  return isspace(c);
+}
+
+static inline int isupper_l(int c, locale_t) {
+  return isupper(c);
+}
+
+static inline int isxdigit_l(int c, locale_t) {
+  return isxdigit(c);
+}
+
+static inline int iswalnum_l(wint_t c, locale_t) {
+  return iswalnum(c);
+}
+
+static inline int iswalpha_l(wint_t c, locale_t) {
+  return iswalpha(c);
+}
+
+static inline int iswblank_l(wint_t c, locale_t) {
+  return iswblank(c);
+}
+
+static inline int iswcntrl_l(wint_t c, locale_t) {
+  return iswcntrl(c);
+}
+
+static inline int iswdigit_l(wint_t c, locale_t) {
+  return iswdigit(c);
+}
+
+static inline int iswgraph_l(wint_t c, locale_t) {
+  return iswgraph(c);
+}
+
+static inline int iswlower_l(wint_t c, locale_t) {
+  return iswlower(c);
+}
+
+static inline int iswprint_l(wint_t c, locale_t) {
+  return iswprint(c);
+}
+
+static inline int iswpunct_l(wint_t c, locale_t) {
+  return iswpunct(c);
+}
+
+static inline int iswspace_l(wint_t c, locale_t) {
+  return iswspace(c);
+}
+
+static inline int iswupper_l(wint_t c, locale_t) {
+  return iswupper(c);
+}
+
+static inline int iswxdigit_l(wint_t c, locale_t) {
+  return iswxdigit(c);
+}
+
+static inline int toupper_l(int c, locale_t) {
+  return toupper(c);
+}
+
+static inline int tolower_l(int c, locale_t) {
+  return tolower(c);
+}
+
+static inline int towupper_l(int c, locale_t) {
+  return towupper(c);
+}
+
+static inline int towlower_l(int c, locale_t) {
+  return towlower(c);
+}
+
+static inline int strcoll_l(const char *s1, const char *s2, locale_t) {
+  return strcoll(s1, s2);
+}
+
+static inline size_t strxfrm_l(char *dest, const char *src, size_t n,
+                               locale_t) {
+  return strxfrm(dest, src, n);
+}
+
+static inline size_t strftime_l(char *s, size_t max, const char *format,
+                                const struct tm *tm, locale_t) {
+  return strftime(s, max, format, tm);
+}
+
+static inline int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t) {
+  return wcscoll(ws1, ws2);
+}
+
+static inline size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n,
+                               locale_t) {
+  return wcsxfrm(dest, src, n);
+}
+
+static inline long double strtold_l(const char *nptr, char **endptr, locale_t) {
+  return strtold(nptr, endptr);
+}
+
+static inline long long strtoll_l(const char *nptr, char **endptr, int base,
+                                  locale_t) {
+  return strtoll(nptr, endptr, base);
+}
+
+static inline unsigned long long strtoull_l(const char *nptr, char **endptr,
+                                            int base, locale_t) {
+  return strtoull(nptr, endptr, base);
+}
+
+static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr,
+                                  int base, locale_t) {
+  return wcstoll(nptr, endptr, base);
+}
+
+static inline unsigned long long wcstoull_l(const wchar_t *nptr,
+                                            wchar_t **endptr, int base,
+                                            locale_t) {
+  return wcstoull(nptr, endptr, base);
+}
+
+static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr,
+                                    locale_t) {
+  return wcstold(nptr, endptr);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
diff --git a/system/include/libcxx/thread b/system/include/libcxx/thread
index 1f1e4a2b9459c..808d76b82a093 100644
--- a/system/include/libcxx/thread
+++ b/system/include/libcxx/thread
@@ -106,6 +106,10 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
 
 #define __STDCPP_THREADS__ __cplusplus
 
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <thread> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
@@ -455,4 +459,6 @@ void yield() _NOEXCEPT {sched_yield();}
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_THREAD
diff --git a/system/include/libcxx/tuple b/system/include/libcxx/tuple
index a1a7bcf0b5e73..1463170fe1c70 100644
--- a/system/include/libcxx/tuple
+++ b/system/include/libcxx/tuple
@@ -74,7 +74,7 @@ const unspecified ignore;
 
 template <class... T> tuple<V...>  make_tuple(T&&...); // constexpr in C++14
 template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
-template <class... T> tuple<T&...> tie(T&...) noexcept;
+template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
 template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
   
 // 20.4.1.4, tuple helper classes:
@@ -82,13 +82,15 @@ template <class T> class tuple_size; // undefined
 template <class... T> class tuple_size<tuple<T...>>;
 template <intsize_t I, class T> class tuple_element; // undefined
 template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
+template <size_t _Ip, class ..._Tp>
+  using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; // C++14
 
 // 20.4.1.5, element access:
 template <intsize_t I, class... T>
     typename tuple_element<I, tuple<T...>>::type&
     get(tuple<T...>&) noexcept; // constexpr in C++14
 template <intsize_t I, class... T>
-    typename tuple_element<I, tuple<T...>>::type const&
+    typename const tuple_element<I, tuple<T...>>::type &
     get(const tuple<T...>&) noexcept; // constexpr in C++14
 template <intsize_t I, class... T>
     typename tuple_element<I, tuple<T...>>::type&&
@@ -152,6 +154,11 @@ public:
     typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
 };
 
+#if _LIBCPP_STD_VER > 11
+template <size_t _Ip, class ..._Tp>
+using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
+#endif
+
 // __tuple_leaf
 
 template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value
@@ -203,7 +210,13 @@ public:
               "Attempted to default construct a reference element in a tuple");}
 
     template <class _Tp,
-              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
+              class = typename enable_if<
+                  __lazy_and<
+                      __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
+                    , is_constructible<_Hp, _Tp>
+                    >::value
+                >::type
+            >
         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
         explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
             : value(_VSTD::forward<_Tp>(__t))
@@ -261,17 +274,8 @@ public:
                                 >::value)),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR_AFTER_CXX11
-    __tuple_leaf(const __tuple_leaf& __t) _NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value)
-        : value(__t.get())
-        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
-
-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR_AFTER_CXX11
-    __tuple_leaf(__tuple_leaf&& __t) _NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value)
-        : value(_VSTD::forward<_Hp>(__t.get()))
-        {}
+    __tuple_leaf(const __tuple_leaf& __t) = default;
+    __tuple_leaf(__tuple_leaf&& __t) = default;
 
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
@@ -318,7 +322,13 @@ public:
             : _Hp(__a) {}
 
     template <class _Tp,
-              class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
+              class = typename enable_if<
+                  __lazy_and<
+                        __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
+                      , is_constructible<_Hp, _Tp>
+                    >::value
+                >::type
+            >
         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
         explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
             : _Hp(_VSTD::forward<_Tp>(__t)) {}
@@ -338,6 +348,9 @@ public:
         explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
             : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
 
+    __tuple_leaf(__tuple_leaf const &) = default;
+    __tuple_leaf(__tuple_leaf &&) = default;
+
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         __tuple_leaf&
@@ -541,7 +554,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
         tuple(_Up&&... __u)
             _NOEXCEPT_((
-                is_nothrow_constructible<
+                is_nothrow_constructible<base,
                     typename __make_tuple_indices<sizeof...(_Up)>::type,
                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
@@ -582,7 +595,7 @@ public:
         explicit
         tuple(_Up&&... __u)
             _NOEXCEPT_((
-                is_nothrow_constructible<
+                is_nothrow_constructible<base,
                     typename __make_tuple_indices<sizeof...(_Up)>::type,
                     typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
                     typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
@@ -796,7 +809,7 @@ constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
 // tie
 
 template <class ..._Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 tuple<_Tp&...>
 tie(_Tp&... __t) _NOEXCEPT
 {
@@ -816,13 +829,13 @@ namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>()
 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
 
 template <class _Tp>
-struct ___make_tuple_return
+struct __make_tuple_return_impl
 {
     typedef _Tp type;
 };
 
 template <class _Tp>
-struct ___make_tuple_return<reference_wrapper<_Tp> >
+struct __make_tuple_return_impl<reference_wrapper<_Tp> >
 {
     typedef _Tp& type;
 };
@@ -830,7 +843,7 @@ struct ___make_tuple_return<reference_wrapper<_Tp> >
 template <class _Tp>
 struct __make_tuple_return
 {
-    typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
+    typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
 };
 
 template <class... _Tp>
@@ -856,7 +869,7 @@ struct __tuple_equal
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     bool operator()(const _Tp& __x, const _Up& __y)
     {
-        return __tuple_equal<_Ip - 1>()(__x, __y) && get<_Ip-1>(__x) == get<_Ip-1>(__y);
+        return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
     }
 };
 
@@ -895,7 +908,7 @@ struct __tuple_less
     bool operator()(const _Tp& __x, const _Up& __y)
     {
         return __tuple_less<_Ip-1>()(__x, __y) ||
-             (!__tuple_less<_Ip-1>()(__y, __x) && get<_Ip-1>(__x) < get<_Ip-1>(__y));
+             (!__tuple_less<_Ip-1>()(__y, __x) && _VSTD::get<_Ip-1>(__x) < _VSTD::get<_Ip-1>(__y));
     }
 };
 
@@ -1044,8 +1057,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
     typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
     operator()(tuple<_Types...> __t, _Tuple0&& __t0)
     {
-        return forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))...,
-                                      get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
+        return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
+                                      _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
     }
 
     template <class _Tuple0, class _Tuple1, class ..._Tuples>
@@ -1060,8 +1073,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
            typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
            typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
                            (forward_as_tuple(
-                              _VSTD::forward<_Types>(get<_I0>(__t))...,
-                              get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
+                              _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
+                              _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
                             ),
                             _VSTD::forward<_Tuple1>(__t1),
                             _VSTD::forward<_Tuples>(__tpls)...);
@@ -1090,8 +1103,8 @@ inline _LIBCPP_INLINE_VISIBILITY
 pair<_T1, _T2>::pair(piecewise_construct_t,
                      tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
                      __tuple_indices<_I1...>, __tuple_indices<_I2...>)
-    :  first(_VSTD::forward<_Args1>(get<_I1>( __first_args))...),
-      second(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+    :  first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
+      second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
 {
 }
 
diff --git a/system/include/libcxx/type_traits b/system/include/libcxx/type_traits
index 0ad7b7f29d143..bd10697cae795 100644
--- a/system/include/libcxx/type_traits
+++ b/system/include/libcxx/type_traits
@@ -91,6 +91,7 @@ namespace std
     template <class T> struct is_empty;
     template <class T> struct is_polymorphic;
     template <class T> struct is_abstract;
+    template <class T> struct is_final; // C++14
 
     template <class T, class... Args> struct is_constructible;
     template <class T>                struct is_default_constructible;
@@ -236,10 +237,10 @@ struct _LIBCPP_TYPE_VIS_ONLY integral_constant
     typedef _Tp               value_type;
     typedef integral_constant type;
     _LIBCPP_INLINE_VISIBILITY
-        _LIBCPP_CONSTEXPR operator value_type() const {return value;}
+        _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
 #if _LIBCPP_STD_VER > 11
     _LIBCPP_INLINE_VISIBILITY
-         constexpr value_type operator ()() const {return value;}
+         constexpr value_type operator ()() const _NOEXCEPT {return value;}
 #endif
 };
 
@@ -285,58 +286,62 @@ template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
 
 // is_void
 
-template <class _Tp> struct __is_void       : public false_type {};
-template <>          struct __is_void<void> : public true_type {};
+template <class _Tp> struct __libcpp_is_void       : public false_type {};
+template <>          struct __libcpp_is_void<void> : public true_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void
-    : public __is_void<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
 
 // __is_nullptr_t
 
-template <class _Tp> struct ____is_nullptr_t       : public false_type {};
-template <>          struct ____is_nullptr_t<nullptr_t> : public true_type {};
+template <class _Tp> struct __is_nullptr_t_impl       : public false_type {};
+template <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __is_nullptr_t
-    : public ____is_nullptr_t<typename remove_cv<_Tp>::type> {};
+    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_null_pointer
-    : public ____is_nullptr_t<typename remove_cv<_Tp>::type> {};
+    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
 #endif
 
 // is_integral
 
-template <class _Tp> struct __is_integral                     : public false_type {};
-template <>          struct __is_integral<bool>               : public true_type {};
-template <>          struct __is_integral<char>               : public true_type {};
-template <>          struct __is_integral<signed char>        : public true_type {};
-template <>          struct __is_integral<unsigned char>      : public true_type {};
-template <>          struct __is_integral<wchar_t>            : public true_type {};
+template <class _Tp> struct __libcpp_is_integral                     : public false_type {};
+template <>          struct __libcpp_is_integral<bool>               : public true_type {};
+template <>          struct __libcpp_is_integral<char>               : public true_type {};
+template <>          struct __libcpp_is_integral<signed char>        : public true_type {};
+template <>          struct __libcpp_is_integral<unsigned char>      : public true_type {};
+template <>          struct __libcpp_is_integral<wchar_t>            : public true_type {};
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
-template <>          struct __is_integral<char16_t>           : public true_type {};
-template <>          struct __is_integral<char32_t>           : public true_type {};
+template <>          struct __libcpp_is_integral<char16_t>           : public true_type {};
+template <>          struct __libcpp_is_integral<char32_t>           : public true_type {};
 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
-template <>          struct __is_integral<short>              : public true_type {};
-template <>          struct __is_integral<unsigned short>     : public true_type {};
-template <>          struct __is_integral<int>                : public true_type {};
-template <>          struct __is_integral<unsigned int>       : public true_type {};
-template <>          struct __is_integral<long>               : public true_type {};
-template <>          struct __is_integral<unsigned long>      : public true_type {};
-template <>          struct __is_integral<long long>          : public true_type {};
-template <>          struct __is_integral<unsigned long long> : public true_type {};
+template <>          struct __libcpp_is_integral<short>              : public true_type {};
+template <>          struct __libcpp_is_integral<unsigned short>     : public true_type {};
+template <>          struct __libcpp_is_integral<int>                : public true_type {};
+template <>          struct __libcpp_is_integral<unsigned int>       : public true_type {};
+template <>          struct __libcpp_is_integral<long>               : public true_type {};
+template <>          struct __libcpp_is_integral<unsigned long>      : public true_type {};
+template <>          struct __libcpp_is_integral<long long>          : public true_type {};
+template <>          struct __libcpp_is_integral<unsigned long long> : public true_type {};
+#ifndef _LIBCPP_HAS_NO_INT128
+template <>          struct __libcpp_is_integral<__int128_t>         : public true_type {};
+template <>          struct __libcpp_is_integral<__uint128_t>        : public true_type {};
+#endif
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral
-    : public __is_integral<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
 
 // is_floating_point
 
-template <class _Tp> struct __is_floating_point              : public false_type {};
-template <>          struct __is_floating_point<float>       : public true_type {};
-template <>          struct __is_floating_point<double>      : public true_type {};
-template <>          struct __is_floating_point<long double> : public true_type {};
+template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
+template <>          struct __libcpp_is_floating_point<float>       : public true_type {};
+template <>          struct __libcpp_is_floating_point<double>      : public true_type {};
+template <>          struct __libcpp_is_floating_point<long double> : public true_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_floating_point
-    : public __is_floating_point<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
 
 // is_array
 
@@ -349,11 +354,11 @@ template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[_Np]>
 
 // is_pointer
 
-template <class _Tp> struct __is_pointer       : public false_type {};
-template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
+template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
+template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pointer
-    : public __is_pointer<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_reference
 
@@ -371,13 +376,9 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&>  : public t
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {};
 #endif
 
-#if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-#define _LIBCPP_HAS_TYPE_TRAITS
-#endif
-
 // is_union
 
-#if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(is_union) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
     : public integral_constant<bool, __is_union(_Tp)> {};
@@ -392,7 +393,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
 
 // is_class
 
-#if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(is_class) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
     : public integral_constant<bool, __is_class(_Tp)> {};
@@ -417,7 +418,7 @@ template <class _Tp>            struct _LIBCPP_TYPE_VIS_ONLY is_same<_Tp, _Tp> :
 
 // is_function
 
-namespace __is_function_imp
+namespace __libcpp_is_function_imp
 {
 template <class _Tp> char  __test(_Tp*);
 template <class _Tp> __two __test(...);
@@ -429,29 +430,47 @@ template <class _Tp, bool = is_class<_Tp>::value ||
                             is_void<_Tp>::value  ||
                             is_reference<_Tp>::value ||
                             __is_nullptr_t<_Tp>::value >
-struct __is_function
-    : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
+struct __libcpp_is_function
+    : public integral_constant<bool, sizeof(__libcpp_is_function_imp::__test<_Tp>(__libcpp_is_function_imp::__source<_Tp>())) == 1>
     {};
-template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
+template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_function
-    : public __is_function<_Tp> {};
+    : public __libcpp_is_function<_Tp> {};
 
 // is_member_function_pointer
 
-template <class _Tp> struct            __is_member_function_pointer             : public false_type {};
-template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
+// template <class _Tp> struct            __libcpp_is_member_function_pointer             : public false_type {};
+// template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
+// 
+
+template <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
+struct __member_pointer_traits_imp
+{  // forward declaration; specializations later
+};
+
+
+namespace __libcpp_is_member_function_pointer_imp {
+    template <typename _Tp>
+    char __test(typename std::__member_pointer_traits_imp<_Tp, true, false>::_FnType *);
+
+    template <typename>
+    std::__two __test(...);
+};
+    
+template <class _Tp> struct __libcpp_is_member_function_pointer
+    : public integral_constant<bool, sizeof(__libcpp_is_member_function_pointer_imp::__test<_Tp>(nullptr)) == 1> {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_function_pointer
-    : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_member_pointer
 
-template <class _Tp>            struct __is_member_pointer             : public false_type {};
-template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};
+template <class _Tp>            struct __libcpp_is_member_pointer             : public false_type {};
+template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {};
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_pointer
-    : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
+    : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_member_object_pointer
 
@@ -461,7 +480,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer
 
 // is_enum
 
-#if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(is_enum) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum
     : public integral_constant<bool, __is_enum(_Tp)> {};
@@ -644,32 +663,32 @@ template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
 // is_signed
 
 template <class _Tp, bool = is_integral<_Tp>::value>
-struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
+struct __libcpp_is_signed_impl : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
 
 template <class _Tp>
-struct ___is_signed<_Tp, false> : public true_type {};  // floating point
+struct __libcpp_is_signed_impl<_Tp, false> : public true_type {};  // floating point
 
 template <class _Tp, bool = is_arithmetic<_Tp>::value>
-struct __is_signed : public ___is_signed<_Tp> {};
+struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
 
-template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
+template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __is_signed<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __libcpp_is_signed<_Tp> {};
 
 // is_unsigned
 
 template <class _Tp, bool = is_integral<_Tp>::value>
-struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
+struct __libcpp_is_unsigned_impl : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
 
 template <class _Tp>
-struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point
+struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {};  // floating point
 
 template <class _Tp, bool = is_arithmetic<_Tp>::value>
-struct __is_unsigned : public ___is_unsigned<_Tp> {};
+struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
 
-template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
+template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __is_unsigned<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __libcpp_is_unsigned<_Tp> {};
 
 // rank
 
@@ -759,6 +778,13 @@ template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {}
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_abstract<_Tp> {};
 
+// is_final
+
+#if _LIBCPP_STD_VER > 11 && __has_feature(is_final)
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY 
+is_final : public integral_constant<bool, __is_final(_Tp)> {};
+#endif
+
 // is_base_of
 
 #ifdef _LIBCPP_HAS_IS_BASE_OF
@@ -767,7 +793,7 @@ template <class _Bp, class _Dp>
 struct _LIBCPP_TYPE_VIS_ONLY is_base_of
     : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
 
-#else  // __has_feature(is_base_of)
+#else  // _LIBCPP_HAS_IS_BASE_OF
 
 namespace __is_base_of_imp
 {
@@ -792,7 +818,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_base_of
     : public integral_constant<bool, is_class<_Bp>::value &&
                                      sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
 
-#endif  // __has_feature(is_base_of)
+#endif  // _LIBCPP_HAS_IS_BASE_OF
 
 // is_convertible
 
@@ -915,7 +941,7 @@ template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
 
 // is_empty
 
-#if __has_feature(is_empty)
+#if __has_feature(is_empty) || (_GNUC_VER >= 407)
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_empty
@@ -946,7 +972,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_empty : public __libcpp_emp
 
 // is_polymorphic
 
-#if __has_feature(is_polymorphic)
+#if __has_feature(is_polymorphic) || defined(_LIBCPP_MSVC)
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
@@ -966,17 +992,17 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
 
 // has_virtual_destructor
 
-#if __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
     : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
 
-#else  // _LIBCPP_HAS_TYPE_TRAITS
+#else
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
     : public false_type {};
 
-#endif  // _LIBCPP_HAS_TYPE_TRAITS
+#endif
 
 // alignment_of
 
@@ -1151,13 +1177,41 @@ template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
+template <class _Tp>
+struct __numeric_type
+{
+   static void __test(...);
+   static float __test(float);
+   static double __test(char);
+   static double __test(int);
+   static double __test(unsigned);
+   static double __test(long);
+   static double __test(unsigned long);
+   static double __test(long long);
+   static double __test(unsigned long long);
+   static double __test(double);
+   static long double __test(long double);
+
+   typedef decltype(__test(declval<_Tp>())) type;
+   static const bool value = !is_same<type, void>::value;
+};
+
+template <>
+struct __numeric_type<void>
+{
+   static const bool value = true;
+};
+
 // __promote
 
 template <class _A1, class _A2 = void, class _A3 = void,
-          bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
-                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
-                 (is_arithmetic<_A3>::value || is_void<_A3>::value)>
-class __promote {};
+          bool = __numeric_type<_A1>::value &&
+                 __numeric_type<_A2>::value &&
+                 __numeric_type<_A3>::value>
+class __promote
+{
+    static const bool value = false;
+};
 
 template <class _A1, class _A2, class _A3>
 class __promote<_A1, _A2, _A3, true>
@@ -1168,6 +1222,7 @@ private:
     typedef typename __promote<_A3>::type __type3;
 public:
     typedef decltype(__type1() + __type2() + __type3()) type;
+    static const bool value = true;
 };
 
 template <class _A1, class _A2>
@@ -1178,16 +1233,16 @@ private:
     typedef typename __promote<_A2>::type __type2;
 public:
     typedef decltype(__type1() + __type2()) type;
+    static const bool value = true;
 };
 
 template <class _A1>
 class __promote<_A1, void, void, true>
 {
 public:
-    typedef typename conditional<is_arithmetic<_A1>::value,
-                     typename conditional<is_integral<_A1>::value, double, _A1>::type,
-                     void
-            >::type type;
+    typedef typename __numeric_type<_A1>::type type;
+    static const bool value = true;
+    static const bool __does_not_throw = _NOEXCEPT_OR_FALSE(static_cast<type>(declval<_A1>()));
 };
 
 #ifdef _LIBCPP_STORE_AS_OPTIMIZATION
@@ -1210,7 +1265,13 @@ typedef
     __type_list<signed int,
     __type_list<signed long,
     __type_list<signed long long,
+#ifndef _LIBCPP_HAS_NO_INT128
+    __type_list<__int128_t,
+#endif
     __nat
+#ifndef _LIBCPP_HAS_NO_INT128
+    >
+#endif
     > > > > > __signed_types;
 
 typedef
@@ -1219,7 +1280,13 @@ typedef
     __type_list<unsigned int,
     __type_list<unsigned long,
     __type_list<unsigned long long,
+#ifndef _LIBCPP_HAS_NO_INT128
+    __type_list<__uint128_t,
+#endif
     __nat
+#ifndef _LIBCPP_HAS_NO_INT128
+    >
+#endif
     > > > > > __unsigned_types;
 
 template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
@@ -1303,6 +1370,10 @@ template <> struct __make_signed<  signed long,      true> {typedef long      ty
 template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
 template <> struct __make_signed<  signed long long, true> {typedef long long type;};
 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
+#ifndef _LIBCPP_HAS_NO_INT128
+template <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
+template <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
+#endif
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY make_signed
@@ -1332,6 +1403,10 @@ template <> struct __make_unsigned<  signed long,      true> {typedef unsigned l
 template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
 template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
 template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
+#ifndef _LIBCPP_HAS_NO_INT128
+template <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
+template <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
+#endif
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY make_unsigned
@@ -1356,7 +1431,7 @@ template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, void, void>
 {
 public:
-    typedef _Tp type;
+    typedef typename decay<_Tp>::type type;
 };
 
 template <class _Tp, class _Up>
@@ -1448,7 +1523,7 @@ struct is_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
-                     const typename add_lvalue_reference<_Tp>::type> {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_move_assignable
 
@@ -1462,42 +1537,61 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_move_assignable
 
 // is_destructible
 
-template <class _Tp>
-struct __destructible_test
-{
-    _Tp __t;
+//	if it's a reference, return true
+//	if it's a function, return false
+//	if it's   void,     return false
+//	if it's an array of unknown bound, return false
+//	Otherwise, return "std::declval<_Up&>().~_Up()" is well-formed
+//    where _Up is remove_all_extents<_Tp>::type
+
+template <class>
+struct __is_destructible_apply { typedef int type; };
+
+template <typename _Tp>
+struct __is_destructor_wellformed {
+	template <typename _Tp1>
+	static char  __test (
+        typename __is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
+    );
+
+	template <typename _Tp1>
+	static __two __test (...);
+	
+	static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
 };
 
+template <class _Tp, bool>
+struct __destructible_imp;
+
 template <class _Tp>
-decltype((_VSTD::declval<__destructible_test<_Tp> >().~__destructible_test<_Tp>(), true_type()))
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-__is_destructible_test(_Tp&&);
-#else
-__is_destructible_test(_Tp&);
-#endif
+struct __destructible_imp<_Tp, false> 
+   : public _VSTD::integral_constant<bool, 
+        __is_destructor_wellformed<typename _VSTD::remove_all_extents<_Tp>::type>::value> {};
 
-false_type
-__is_destructible_test(__any);
+template <class _Tp>
+struct __destructible_imp<_Tp, true>
+    : public _VSTD::true_type {};
 
-template <class _Tp, bool = is_void<_Tp>::value || is_abstract<_Tp>::value
-                                                || is_function<_Tp>::value>
-struct __destructible_imp
-    : public common_type
-        <
-            decltype(__is_destructible_test(declval<_Tp>()))
-        >::type {};
+template <class _Tp, bool>
+struct __destructible_false;
 
 template <class _Tp>
-struct __destructible_imp<_Tp, true>
-    : public false_type {};
+struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, _VSTD::is_reference<_Tp>::value> {};
+
+template <class _Tp>
+struct __destructible_false<_Tp, true> : public _VSTD::false_type {};
 
 template <class _Tp>
 struct is_destructible
-    : public __destructible_imp<_Tp> {};
+    : public __destructible_false<_Tp, _VSTD::is_function<_Tp>::value> {};
 
 template <class _Tp>
 struct is_destructible<_Tp[]>
-    : public false_type {};
+    : public _VSTD::false_type {};
+
+template <>
+struct is_destructible<void>
+    : public _VSTD::false_type {};
 
 // move
 
@@ -1593,11 +1687,6 @@ __decay_copy(const _Tp& __t)
 
 #endif
 
-template <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
-struct __member_pointer_traits_imp
-{
-};
-
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1605,6 +1694,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
 {
     typedef _Class _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
+{
+    typedef _Class _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1612,6 +1710,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false
 {
     typedef _Class const _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
+{
+    typedef _Class const _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1619,6 +1726,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, fa
 {
     typedef _Class volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
+{
+    typedef _Class volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1626,6 +1742,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, tr
 {
     typedef _Class const volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
+{
+    typedef _Class const volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 #if __has_feature(cxx_reference_qualified_functions)
@@ -1635,6 +1760,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
 {
     typedef _Class& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
+{
+    typedef _Class& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1642,6 +1776,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, fals
 {
     typedef _Class const& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
+{
+    typedef _Class const& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1649,6 +1792,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, f
 {
     typedef _Class volatile& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
+{
+    typedef _Class volatile& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1656,6 +1808,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, t
 {
     typedef _Class const volatile& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
+{
+    typedef _Class const volatile& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1663,6 +1824,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
 {
     typedef _Class&& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
+{
+    typedef _Class&& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1670,6 +1840,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, fal
 {
     typedef _Class const&& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
+{
+    typedef _Class const&& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1677,6 +1856,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true,
 {
     typedef _Class volatile&& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
+{
+    typedef _Class volatile&& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 template <class _Rp, class _Class, class ..._Param>
@@ -1684,6 +1872,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&,
 {
     typedef _Class const volatile&& _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param...);
+};
+
+template <class _Rp, class _Class, class ..._Param>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
+{
+    typedef _Class const volatile&& _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_Param..., ...);
 };
 
 #endif  // __has_feature(cxx_reference_qualified_functions)
@@ -1695,6 +1892,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false>
 {
     typedef _Class _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) ();
+};
+
+template <class _Rp, class _Class>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(...), true, false>
+{
+    typedef _Class _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (...);
 };
 
 template <class _Rp, class _Class, class _P0>
@@ -1702,6 +1908,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false>
 {
     typedef _Class _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0);
+};
+
+template <class _Rp, class _Class, class _P0>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...), true, false>
+{
+    typedef _Class _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1>
@@ -1709,6 +1924,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false>
 {
     typedef _Class _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...), true, false>
+{
+    typedef _Class _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
@@ -1716,6 +1940,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false>
 {
     typedef _Class _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1, class _P2>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...), true, false>
+{
+    typedef _Class _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
 };
 
 template <class _Rp, class _Class>
@@ -1723,6 +1956,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false>
 {
     typedef _Class const _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) ();
+};
+
+template <class _Rp, class _Class>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const, true, false>
+{
+    typedef _Class const _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (...);
 };
 
 template <class _Rp, class _Class, class _P0>
@@ -1730,6 +1972,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false>
 {
     typedef _Class const _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0);
+};
+
+template <class _Rp, class _Class, class _P0>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const, true, false>
+{
+    typedef _Class const _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1>
@@ -1737,6 +1988,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false>
 {
     typedef _Class const _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const, true, false>
+{
+    typedef _Class const _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
@@ -1744,6 +2004,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, f
 {
     typedef _Class const _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1, class _P2>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const, true, false>
+{
+    typedef _Class const _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
 };
 
 template <class _Rp, class _Class>
@@ -1751,6 +2020,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false>
 {
     typedef _Class volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) ();
+};
+
+template <class _Rp, class _Class>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(...) volatile, true, false>
+{
+    typedef _Class volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (...);
 };
 
 template <class _Rp, class _Class, class _P0>
@@ -1758,6 +2036,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false>
 {
     typedef _Class volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0);
+};
+
+template <class _Rp, class _Class, class _P0>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) volatile, true, false>
+{
+    typedef _Class volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1>
@@ -1765,6 +2052,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, fal
 {
     typedef _Class volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) volatile, true, false>
+{
+    typedef _Class volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
@@ -1772,6 +2068,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true
 {
     typedef _Class volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1, class _P2>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) volatile, true, false>
+{
+    typedef _Class volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
 };
 
 template <class _Rp, class _Class>
@@ -1779,6 +2084,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false
 {
     typedef _Class const volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) ();
+};
+
+template <class _Rp, class _Class>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const volatile, true, false>
+{
+    typedef _Class const volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (...);
 };
 
 template <class _Rp, class _Class, class _P0>
@@ -1786,6 +2100,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, fa
 {
     typedef _Class const volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0);
+};
+
+template <class _Rp, class _Class, class _P0>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const volatile, true, false>
+{
+    typedef _Class const volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1>
@@ -1793,6 +2116,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, tru
 {
     typedef _Class const volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const volatile, true, false>
+{
+    typedef _Class const volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, ...);
 };
 
 template <class _Rp, class _Class, class _P0, class _P1, class _P2>
@@ -1800,6 +2132,15 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile
 {
     typedef _Class const volatile _ClassType;
     typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2);
+};
+
+template <class _Rp, class _Class, class _P0, class _P1, class _P2>
+struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const volatile, true, false>
+{
+    typedef _Class const volatile _ClassType;
+    typedef _Rp _ReturnType;
+    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
 };
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
@@ -1819,6 +2160,7 @@ struct __member_pointer_traits
 {
 //     typedef ... _ClassType;
 //     typedef ... _ReturnType;
+//     typedef ... _FnType;
 };
 
 // result_of
@@ -1973,10 +2315,24 @@ class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1, _A2)>
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
 // template <class T, class... Args> struct is_constructible;
 
+namespace __is_construct
+{
+struct __nat {};
+}
+
+#if __has_feature(is_constructible)
+
+template <class _Tp, class ..._Args>
+struct _LIBCPP_TYPE_VIS_ONLY is_constructible
+    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
+    {};
+
+#else
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
 //      main is_constructible test
 
 template <class _Tp, class ..._Args>
@@ -1988,7 +2344,7 @@ false_type
 __is_constructible_test(__any, _Args&& ...);
 
 template <bool, class _Tp, class... _Args>
-struct __is_constructible // false, _Tp is not a scalar
+struct __libcpp_is_constructible // false, _Tp is not a scalar
     : public common_type
              <
                  decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
@@ -1998,7 +2354,7 @@ struct __is_constructible // false, _Tp is not a scalar
 //      function types are not constructible
 
 template <class _Rp, class... _A1, class... _A2>
-struct __is_constructible<false, _Rp(_A1...), _A2...>
+struct __libcpp_is_constructible<false, _Rp(_A1...), _A2...>
     : public false_type
     {};
 
@@ -2007,7 +2363,7 @@ struct __is_constructible<false, _Rp(_A1...), _A2...>
 //      Scalars are default constructible, references are not
 
 template <class _Tp>
-struct __is_constructible<true, _Tp>
+struct __libcpp_is_constructible<true, _Tp>
     : public is_scalar<_Tp>
     {};
 
@@ -2022,7 +2378,7 @@ struct __is_constructible_ref
 };
 
 template <class _Tp, class _A0>
-struct __is_constructible<true, _Tp, _A0>
+struct __libcpp_is_constructible<true, _Tp, _A0>
     : public common_type
              <
                  decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>()))
@@ -2032,7 +2388,7 @@ struct __is_constructible<true, _Tp, _A0>
 //      Scalars and references are not constructible from multiple args.
 
 template <class _Tp, class _A0, class ..._Args>
-struct __is_constructible<true, _Tp, _A0, _Args...>
+struct __libcpp_is_constructible<true, _Tp, _A0, _Args...>
     : public false_type
     {};
 
@@ -2040,7 +2396,7 @@ struct __is_constructible<true, _Tp, _A0, _Args...>
 
 template <bool, class _Tp, class... _Args>
 struct __is_constructible_void_check
-    : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
+    : public __libcpp_is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
                                 _Tp, _Args...>
     {};
 
@@ -2075,21 +2431,21 @@ struct _LIBCPP_TYPE_VIS_ONLY is_constructible
 //      is default constructible
 
 template <class _Ap, size_t _Np>
-struct __is_constructible<false, _Ap[_Np]>
+struct __libcpp_is_constructible<false, _Ap[_Np]>
     : public is_constructible<typename remove_all_extents<_Ap>::type>
     {};
 
 //      Otherwise array types are not constructible by this syntax
 
 template <class _Ap, size_t _Np, class ..._Args>
-struct __is_constructible<false, _Ap[_Np], _Args...>
+struct __libcpp_is_constructible<false, _Ap[_Np], _Args...>
     : public false_type
     {};
 
 //      Incomplete array types are not constructible
 
 template <class _Ap, class ..._Args>
-struct __is_constructible<false, _Ap[], _Args...>
+struct __libcpp_is_constructible<false, _Ap[], _Args...>
     : public false_type
     {};
 
@@ -2204,13 +2560,6 @@ struct __is_constructible2_void_check<true, _Tp, _A0, _A1>
 
 //      is_constructible entry point
 
-namespace __is_construct
-{
-
-struct __nat {};
-
-}
-
 template <class _Tp, class _A0 = __is_construct::__nat,
                      class _A1 = __is_construct::__nat>
 struct _LIBCPP_TYPE_VIS_ONLY is_constructible
@@ -2275,6 +2624,7 @@ struct __is_constructible2_imp<false, _Ap[], _A0, _A1>
     {};
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // __has_feature(is_constructible)
 
 // is_default_constructible
 
@@ -2287,8 +2637,8 @@ struct _LIBCPP_TYPE_VIS_ONLY is_default_constructible
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible
-    : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
-    {};
+    : public is_constructible<_Tp, 
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_move_constructible
 
@@ -2323,7 +2673,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp>
-#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_trivial_constructor(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2452,7 +2802,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructibl
 
 // is_trivially_assignable
 
-#if __has_feature(is_trivially_constructible)
+#if __has_feature(is_trivially_assignable)
 
 template <class _Tp, class _Arg>
 struct is_trivially_assignable
@@ -2460,7 +2810,7 @@ struct is_trivially_assignable
 {
 };
 
-#else  // !__has_feature(is_trivially_constructible)
+#else  // !__has_feature(is_trivially_assignable)
 
 template <class _Tp, class _Arg>
 struct is_trivially_assignable
@@ -2486,14 +2836,13 @@ struct is_trivially_assignable<_Tp&, _Tp&&>
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#endif  // !__has_feature(is_trivially_constructible)
+#endif  // !__has_feature(is_trivially_assignable)
 
 // is_trivially_copy_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
-                               const typename add_lvalue_reference<_Tp>::type>
-    {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_trivially_move_assignable
 
@@ -2508,12 +2857,12 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable
 
 // is_trivially_destructible
 
-#if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
-    : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
+    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
 
-#else  // _LIBCPP_HAS_TYPE_TRAITS
+#else
 
 template <class _Tp> struct __libcpp_trivial_destructor
     : public integral_constant<bool, is_scalar<_Tp>::value ||
@@ -2522,37 +2871,46 @@ template <class _Tp> struct __libcpp_trivial_destructor
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
 
-#endif  // _LIBCPP_HAS_TYPE_TRAITS
+#endif
 
 // is_nothrow_constructible
 
+#if 0
+template <class _Tp, class... _Args>
+struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
+    : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))>
+{
+};
+
+#else
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-#if __has_feature(cxx_noexcept)
+#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
 
-template <bool, class _Tp, class... _Args> struct __is_nothrow_constructible;
+template <bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
 
 template <class _Tp, class... _Args>
-struct __is_nothrow_constructible<true, _Tp, _Args...>
+struct __libcpp_is_nothrow_constructible<true, _Tp, _Args...>
     : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
 {
 };
 
 template <class _Tp, class... _Args>
-struct __is_nothrow_constructible<false, _Tp, _Args...>
+struct __libcpp_is_nothrow_constructible<false, _Tp, _Args...>
     : public false_type
 {
 };
 
 template <class _Tp, class... _Args>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
-    : __is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
+    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
 {
 };
 
 template <class _Tp, size_t _Ns>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp[_Ns]>
-    : __is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
+    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
 {
 };
 
@@ -2566,7 +2924,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp>
-#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2580,7 +2938,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&&>
 #else
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp>
 #endif
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2590,7 +2948,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp>
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&>
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2600,7 +2958,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&>
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&>
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2622,7 +2980,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat,
                                                        __is_construct::__nat>
-#if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2633,7 +2991,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp,
                                                        __is_construct::__nat>
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2644,7 +3002,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp,
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&,
                                                        __is_construct::__nat>
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2655,7 +3013,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&,
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&,
                                                        __is_construct::__nat>
-#if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
     : integral_constant<bool, is_scalar<_Tp>::value>
@@ -2664,6 +3022,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&,
 };
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // __has_feature(is_nothrow_constructible)
 
 // is_nothrow_default_constructible
 
@@ -2674,8 +3033,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructib
 // is_nothrow_copy_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
-    : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
-    {};
+    : public is_nothrow_constructible<_Tp,
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_nothrow_move_constructible
 
@@ -2689,25 +3048,25 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible
 
 // is_nothrow_assignable
 
-#if __has_feature(cxx_noexcept)
+#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
 
-template <bool, class _Tp, class _Arg> struct __is_nothrow_assignable;
+template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
 
 template <class _Tp, class _Arg>
-struct __is_nothrow_assignable<false, _Tp, _Arg>
+struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
     : public false_type
 {
 };
 
 template <class _Tp, class _Arg>
-struct __is_nothrow_assignable<true, _Tp, _Arg>
+struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
 {
 };
 
 template <class _Tp, class _Arg>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
-    : public __is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
+    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
 {
 };
 
@@ -2719,7 +3078,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp>
-#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
     : integral_constant<bool, is_scalar<_Tp>::value> {};
@@ -2727,7 +3086,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp>
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&>
-#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
     : integral_constant<bool, is_scalar<_Tp>::value> {};
@@ -2735,7 +3094,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&>
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&>
-#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
     : integral_constant<bool, is_scalar<_Tp>::value> {};
@@ -2745,7 +3104,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&>
 
 template <class _Tp>
 struct is_nothrow_assignable<_Tp&, _Tp&&>
-#if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
     : integral_constant<bool, is_scalar<_Tp>::value> {};
@@ -2759,8 +3118,7 @@ struct is_nothrow_assignable<_Tp&, _Tp&&>
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
-                               const typename add_lvalue_reference<_Tp>::type>
-    {};
+                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
 // is_nothrow_move_assignable
 
@@ -2775,25 +3133,25 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable
 
 // is_nothrow_destructible
 
-#if __has_feature(cxx_noexcept)
+#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
 
-template <bool, class _Tp> struct __is_nothrow_destructible;
+template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
 
 template <class _Tp>
-struct __is_nothrow_destructible<false, _Tp>
+struct __libcpp_is_nothrow_destructible<false, _Tp>
     : public false_type
 {
 };
 
 template <class _Tp>
-struct __is_nothrow_destructible<true, _Tp>
+struct __libcpp_is_nothrow_destructible<true, _Tp>
     : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
 {
 };
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
-    : public __is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
+    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
 {
 };
 
@@ -2832,12 +3190,12 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
 
 // is_pod
 
-#if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if __has_feature(is_pod) || (_GNUC_VER >= 403)
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
     : public integral_constant<bool, __is_pod(_Tp)> {};
 
-#else  // _LIBCPP_HAS_TYPE_TRAITS
+#else
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
     : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
@@ -2845,13 +3203,13 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
                                      is_trivially_copy_assignable<_Tp>::value    &&
                                      is_trivially_destructible<_Tp>::value> {};
 
-#endif  // _LIBCPP_HAS_TYPE_TRAITS
+#endif
 
 // is_literal_type;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type
-#if __has_feature(is_literal)
-    : public integral_constant<bool, __is_literal(_Tp)>
+#ifdef _LIBCPP_IS_LITERAL
+    : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)>
 #else
     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
                               is_reference<typename remove_all_extents<_Tp>::type>::value>
@@ -2861,7 +3219,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type
 // is_standard_layout;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout
-#if __has_feature(is_standard_layout)
+#if __has_feature(is_standard_layout) || (_GNUC_VER >= 407)
     : public integral_constant<bool, __is_standard_layout(_Tp)>
 #else
     : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
@@ -2881,7 +3239,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable
 // is_trivial;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial
-#if __has_feature(is_trivial)
+#if __has_feature(is_trivial) || (_GNUC_VER >= 407)
     : public integral_constant<bool, __is_trivial(_Tp)>
 #else
     : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
@@ -3050,7 +3408,7 @@ template <class _Fp, class _A0, class ..._Args,
             class = typename enable_if
             <
                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
-                is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
                            typename remove_reference<_A0>::type>::value
             >::type
          >
@@ -3063,7 +3421,7 @@ template <class _Fp, class _A0, class ..._Args,
             class = typename enable_if
             <
                 is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
-                !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                !is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
                            typename remove_reference<_A0>::type>::value
             >::type
          >
@@ -3211,7 +3569,7 @@ struct __is_swappable
 {
 };
 
-#if __has_feature(cxx_noexcept)
+#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
 
 template <bool, class _Tp>
 struct __is_nothrow_swappable_imp
@@ -3242,19 +3600,19 @@ struct __is_nothrow_swappable
 
 #endif  // __has_feature(cxx_noexcept)
 
-#ifdef _LIBCXX_UNDERLYING_TYPE
+#ifdef _LIBCPP_UNDERLYING_TYPE
 
 template <class _Tp>
 struct underlying_type
 {
-    typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type;
+    typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type;
 };
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
 #endif
 
-#else  // _LIBCXX_UNDERLYING_TYPE
+#else  // _LIBCPP_UNDERLYING_TYPE
 
 template <class _Tp, bool _Support = false>
 struct underlying_type
@@ -3264,7 +3622,7 @@ struct underlying_type
                             "libc++ does not know how to use it.");
 };
 
-#endif // _LIBCXX_UNDERLYING_TYPE
+#endif // _LIBCPP_UNDERLYING_TYPE
 
 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
 
diff --git a/system/include/libcxx/typeinfo b/system/include/libcxx/typeinfo
index 6ffee0f8a3c61..14ef77b31c3f6 100644
--- a/system/include/libcxx/typeinfo
+++ b/system/include/libcxx/typeinfo
@@ -60,6 +60,7 @@ public:
 #include <__config>
 #include <exception>
 #include <cstddef>
+#include <cstdint>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -73,32 +74,75 @@ class _LIBCPP_EXCEPTION_ABI type_info
     type_info& operator=(const type_info&);
     type_info(const type_info&);
 protected:
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
     const char* __type_name;
+#else
+    // A const char* with the non-unique RTTI bit possibly set.
+    uintptr_t __type_name;
+#endif
 
     _LIBCPP_INLINE_VISIBILITY
     explicit type_info(const char* __n)
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
         : __type_name(__n) {}
+#else
+        : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
+#endif
 
 public:
     virtual ~type_info();
 
     _LIBCPP_INLINE_VISIBILITY
-    const char* name() const _NOEXCEPT {return __type_name;}
+    const char* name() const _NOEXCEPT
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
+        {return __type_name;}
+#else
+        {return reinterpret_cast<const char*>(__type_name & ~_LIBCPP_NONUNIQUE_RTTI_BIT);}
+#endif
 
     _LIBCPP_INLINE_VISIBILITY
     bool before(const type_info& __arg) const _NOEXCEPT
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
         {return __type_name < __arg.__type_name;}
+#else
+        {if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
+           return __type_name < __arg.__type_name;
+         return __compare_nonunique_names(__arg) < 0;}
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     size_t hash_code() const _NOEXCEPT
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
         {return *reinterpret_cast<const size_t*>(&__type_name);}
+#else
+        {if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name;
+         const char *__ptr = name();
+         size_t __hash = 5381;
+         while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
+           __hash = (__hash * 33) ^ __c;
+         return __hash;}
+#endif
 
     _LIBCPP_INLINE_VISIBILITY
     bool operator==(const type_info& __arg) const _NOEXCEPT
+#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
         {return __type_name == __arg.__type_name;}
+#else
+        {if (__type_name == __arg.__type_name) return true;
+         if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
+           return false;
+         return __compare_nonunique_names(__arg) == 0;}
+#endif
     _LIBCPP_INLINE_VISIBILITY
     bool operator!=(const type_info& __arg) const _NOEXCEPT
         {return !operator==(__arg);}
 
+#ifdef _LIBCPP_NONUNIQUE_RTTI_BIT
+  private:
+    _LIBCPP_INLINE_VISIBILITY
+    int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
+        {return __builtin_strcmp(name(), __arg.name());}
+#endif
 };
 
 class _LIBCPP_EXCEPTION_ABI bad_cast
diff --git a/system/include/libcxx/unordered_map b/system/include/libcxx/unordered_map
index 4e2298bf9b2f3..0fa87d19ad035 100644
--- a/system/include/libcxx/unordered_map
+++ b/system/include/libcxx/unordered_map
@@ -351,6 +351,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
 #include <functional>
 #include <stdexcept>
 
+#include <__debug>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
diff --git a/system/include/libcxx/unordered_set b/system/include/libcxx/unordered_set
index fd378fa071457..d06629fdcd47f 100644
--- a/system/include/libcxx/unordered_set
+++ b/system/include/libcxx/unordered_set
@@ -325,6 +325,8 @@ template <class Value, class Hash, class Pred, class Alloc>
 #include <__hash_table>
 #include <functional>
 
+#include <__debug>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
diff --git a/system/include/libcxx/utility b/system/include/libcxx/utility
index 2c1f62ccbe956..4eafda41696b9 100644
--- a/system/include/libcxx/utility
+++ b/system/include/libcxx/utility
@@ -101,30 +101,30 @@ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
 template <class T> class tuple_size;
 template <size_t I, class T> class tuple_element;
 
-template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >;
-template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >;
-template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >;
+template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
+template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
+template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
 
 template<size_t I, class T1, class T2>
-    typename tuple_element<I, std::pair<T1, T2> >::type&
-    get(std::pair<T1, T2>&) noexcept; // constexpr in C++14
+    typename tuple_element<I, pair<T1, T2> >::type&
+    get(pair<T1, T2>&) noexcept; // constexpr in C++14
 
 template<size_t I, class T1, class T2>
-    const typename const tuple_element<I, std::pair<T1, T2> >::type&
-    get(const std::pair<T1, T2>&) noexcept; // constexpr in C++14
+    const typename const tuple_element<I, pair<T1, T2> >::type&
+    get(const pair<T1, T2>&) noexcept; // constexpr in C++14
 
 template<size_t I, class T1, class T2>
-    typename tuple_element<I, std::pair<T1, T2> >::type&&
-    get(std::pair<T1, T2>&&) noexcept; // constexpr in C++14
+    typename tuple_element<I, pair<T1, T2> >::type&&
+    get(pair<T1, T2>&&) noexcept; // constexpr in C++14
 
 template<class T1, class T2>
-    constexpr T1& get(std::pair<T1, T2>&) noexcept; // C++14
+    constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
 
 template<size_t I, class T1, class T2>
-    constexpr T1 const& get(std::pair<T1, T2> const &) noexcept; // C++14
+    constexpr T1 const& get(pair<T1, T2> const &) noexcept; // C++14
 
 template<size_t I, class T1, class T2>
-    constexpr T1&& get(std::pair<T1, T2>&&) noexcept; // C++14
+    constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
 
 // C++14
 
@@ -345,9 +345,9 @@ struct _LIBCPP_TYPE_VIS_ONLY pair
         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
         pair(_Tuple&& __p)
             : first(_VSTD::forward<typename tuple_element<0,
-                                  typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))),
+                                  typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))),
               second(_VSTD::forward<typename tuple_element<1,
-                                   typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p)))
+                                   typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p)))
             {}
 
 
@@ -465,13 +465,13 @@ swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
 
 template <class _Tp>
-struct ___make_pair_return
+struct __make_pair_return_impl
 {
     typedef _Tp type;
 };
 
 template <class _Tp>
-struct ___make_pair_return<reference_wrapper<_Tp>>
+struct __make_pair_return_impl<reference_wrapper<_Tp>>
 {
     typedef _Tp& type;
 };
@@ -479,7 +479,7 @@ struct ___make_pair_return<reference_wrapper<_Tp>>
 template <class _Tp>
 struct __make_pair_return
 {
-    typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
+    typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
 };
 
 template <class _T1, class _T2>
diff --git a/system/include/libcxx/valarray b/system/include/libcxx/valarray
index 5113516e9b767..2b942046db9df 100644
--- a/system/include/libcxx/valarray
+++ b/system/include/libcxx/valarray
@@ -345,6 +345,7 @@ template <class T> unspecified2 end(const valarray<T>& v);
 #include <initializer_list>
 #include <algorithm>
 #include <functional>
+#include <new>
 
 #include <__undef_min_max>
 
@@ -1219,6 +1220,7 @@ slice_array<_Tp>::operator=(const slice_array& __sa) const
     const value_type* __s = __sa.__vp_;
     for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
         *__t = *__s;
+    return *this;
 }
 
 template <class _Tp>
@@ -2089,6 +2091,7 @@ mask_array<_Tp>::operator=(const mask_array& __ma) const
     size_t __n = __1d_.size();
     for (size_t __i = 0; __i < __n; ++__i)
         __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
+    return *this;
 }
 
 template <class _Tp>
@@ -2636,7 +2639,7 @@ __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
+                static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
         for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
             ::new (__r.__end_) result_type(__expr_[__i]);
     }
@@ -2670,7 +2673,7 @@ valarray<_Tp>::valarray(const value_type* __p, size_t __n)
 {
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2695,7 +2698,7 @@ valarray<_Tp>::valarray(const valarray& __v)
 {
     if (__v.size())
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2736,7 +2739,7 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il)
     size_t __n = __il.size();
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2764,7 +2767,7 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
     size_t __n = __sa.__size_;
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2790,7 +2793,7 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
     size_t __n = __ga.__1d_.size();
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2819,7 +2822,7 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
     size_t __n = __ma.__1d_.size();
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -2848,7 +2851,7 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
     size_t __n = __ia.__1d_.size();
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
@@ -3133,7 +3136,7 @@ valarray<_Tp>::operator+() const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) value_type(+*__p);
     }
@@ -3150,7 +3153,7 @@ valarray<_Tp>::operator-() const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) value_type(-*__p);
     }
@@ -3167,7 +3170,7 @@ valarray<_Tp>::operator~() const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) value_type(~*__p);
     }
@@ -3184,7 +3187,7 @@ valarray<_Tp>::operator!() const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<bool*>(::operator new(__n * sizeof(bool)));
+                static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) bool(!*__p);
     }
@@ -3504,7 +3507,7 @@ valarray<_Tp>::shift(int __i) const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         const value_type* __sb;
         value_type* __tb;
         value_type* __te;
@@ -3542,7 +3545,7 @@ valarray<_Tp>::cshift(int __i) const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         __i %= static_cast<int>(__n);
         const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
         for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
@@ -3563,7 +3566,7 @@ valarray<_Tp>::apply(value_type __f(value_type)) const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) value_type(__f(*__p));
     }
@@ -3580,7 +3583,7 @@ valarray<_Tp>::apply(value_type __f(const value_type&)) const
     {
         __r.__begin_ =
             __r.__end_ =
-                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+                static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
         for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
             ::new (__r.__end_) value_type(__f(*__p));
     }
@@ -3595,12 +3598,12 @@ valarray<_Tp>::resize(size_t __n, value_type __x)
     {
         while (__end_ != __begin_)
             (--__end_)->~value_type();
-        ::operator delete(__begin_);
+        _VSTD::__deallocate(__begin_);
         __begin_ = __end_ = nullptr;
     }
     if (__n)
     {
-        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
diff --git a/system/include/libcxx/vector b/system/include/libcxx/vector
index 6ac78d5d50b5b..cd9aab3246536 100644
--- a/system/include/libcxx/vector
+++ b/system/include/libcxx/vector
@@ -276,11 +276,7 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
 
 #include <__undef_min_max>
 
-#ifdef _LIBCPP_DEBUG
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
+#include <__debug>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -483,6 +479,7 @@ class _LIBCPP_TYPE_VIS_ONLY vector
 {
 private:
     typedef __vector_base<_Tp, _Allocator>           __base;
+    typedef allocator<_Tp>                           __default_allocator_type;
 public:
     typedef vector                                   __self;
     typedef _Tp                                      value_type;
@@ -749,7 +746,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     void clear() _NOEXCEPT
     {
+        size_type __old_size = size();
         __base::clear();
+        __annotate_shrink(__old_size);
         __invalidate_all_iterators();
     }
 
@@ -785,7 +784,6 @@ private:
             void
         >::type
         __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
-    void __move_construct_at_end(pointer __first, pointer __last);
     void __append(size_type __n);
     void __append(size_type __n, const_reference __x);
     _LIBCPP_INLINE_VISIBILITY
@@ -816,7 +814,9 @@ private:
         }
         __get_db()->unlock();
 #endif
+        size_type __old_size = size();
         __base::__destruct_at_end(__new_last);
+        __annotate_shrink(__old_size);
     }
     template <class _Up>
         void
@@ -830,17 +830,76 @@ private:
         void
         __emplace_back_slow_path(_Args&&... __args);
 #endif
+    // The following functions are no-ops outside of AddressSanitizer mode.
+    // We call annotatations only for the default Allocator because other allocators
+    // may not meet the AddressSanitizer alignment constraints.
+    // See the documentation for __sanitizer_annotate_contiguous_container for more details.
+    void __annotate_contiguous_container
+    (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
+    {
+#ifndef _LIBCPP_HAS_NO_ASAN
+      if (__beg && is_same<allocator_type, __default_allocator_type>::value)
+        __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
+#endif
+    }
+
+    void __annotate_new(size_type __current_size) const
+    {
+      __annotate_contiguous_container(data(), data() + capacity(),
+                                      data() + capacity(), data() + __current_size);
+    }
+    void __annotate_delete() const
+    {
+      __annotate_contiguous_container(data(), data() + capacity(),
+                                      data() + size(), data() + capacity());
+    }
+    void __annotate_increase(size_type __n) const
+    {
+      __annotate_contiguous_container(data(), data() + capacity(),
+                                      data() + size(), data() + size() + __n);
+    }
+    void __annotate_shrink(size_type __old_size) const
+    {
+      __annotate_contiguous_container(data(), data() + capacity(),
+                                      data() + __old_size, data() + size());
+    }
+#ifndef _LIBCPP_HAS_NO_ASAN
+    // The annotation for size increase should happen before the actual increase,
+    // but if an exception is thrown after that the annotation has to be undone.
+    struct __RAII_IncreaseAnnotator {
+      __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
+        : __commit(false), __v(__v), __n(__n) {
+        __v.__annotate_increase(__n);
+      }
+      void __done() { __commit = true; }
+      ~__RAII_IncreaseAnnotator() {
+        if (__commit) return;
+        __v.__annotate_shrink(__v.size() + __n);
+      }
+      bool __commit;
+      size_type __n;
+      const vector &__v;
+    };
+#else
+    struct __RAII_IncreaseAnnotator {
+      inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
+      inline void __done() {}
+    };
+#endif
+
 };
 
 template <class _Tp, class _Allocator>
 void
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
 {
+    __annotate_delete();
     __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
     _VSTD::swap(this->__begin_, __v.__begin_);
     _VSTD::swap(this->__end_, __v.__end_);
     _VSTD::swap(this->__end_cap(), __v.__end_cap());
     __v.__first_ = __v.__begin_;
+    __annotate_new(size());
     __invalidate_all_iterators();
 }
 
@@ -848,6 +907,7 @@ template <class _Tp, class _Allocator>
 typename vector<_Tp, _Allocator>::pointer
 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
 {
+    __annotate_delete();
     pointer __r = __v.__begin_;
     __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
     __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
@@ -855,6 +915,7 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
     _VSTD::swap(this->__end_, __v.__end_);
     _VSTD::swap(this->__end_cap(), __v.__end_cap());
     __v.__first_ = __v.__begin_;
+    __annotate_new(size());
     __invalidate_all_iterators();
     return __r;
 }
@@ -874,6 +935,7 @@ vector<_Tp, _Allocator>::allocate(size_type __n)
         this->__throw_length_error();
     this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
     this->__end_cap() = this->__begin_ + __n;
+    __annotate_new(0);
 }
 
 template <class _Tp, class _Allocator>
@@ -922,9 +984,11 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
     allocator_type& __a = this->__alloc();
     do
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
         ++this->__end_;
         --__n;
+        __annotator.__done();
     } while (__n > 0);
 }
 
@@ -942,9 +1006,11 @@ vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
     allocator_type& __a = this->__alloc();
     do
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
         ++this->__end_;
         --__n;
+        __annotator.__done();
     } while (__n > 0);
 }
 
@@ -960,20 +1026,9 @@ vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIt
     allocator_type& __a = this->__alloc();
     for (; __first != __last; ++__first)
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
-        ++this->__end_;
-    }
-}
-
-template <class _Tp, class _Allocator>
-void
-vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
-{
-    allocator_type& __a = this->__alloc();
-    for (; __first != __last; ++__first)
-    {
-        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
-                                  _VSTD::move(*__first));
+        __annotator.__done();
         ++this->__end_;
     }
 }
@@ -1284,10 +1339,10 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
 {
     deallocate();
+    __base::__move_assign_alloc(__c); // this can throw
     this->__begin_ = __c.__begin_;
     this->__end_ = __c.__end_;
     this->__end_cap() = __c.__end_cap();
-    __base::__move_assign_alloc(__c);
     __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->swap(this, &__c);
@@ -1535,8 +1590,10 @@ vector<_Tp, _Allocator>::push_back(const_reference __x)
 {
     if (this->__end_ != this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(this->__alloc(),
                                   _VSTD::__to_raw_pointer(this->__end_), __x);
+        __annotator.__done();
         ++this->__end_;
     }
     else
@@ -1552,9 +1609,11 @@ vector<_Tp, _Allocator>::push_back(value_type&& __x)
 {
     if (this->__end_ < this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(this->__alloc(),
                                   _VSTD::__to_raw_pointer(this->__end_),
                                   _VSTD::move(__x));
+        __annotator.__done();
         ++this->__end_;
     }
     else
@@ -1584,9 +1643,11 @@ vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
 {
     if (this->__end_ < this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         __alloc_traits::construct(this->__alloc(),
                                   _VSTD::__to_raw_pointer(this->__end_),
                                   _VSTD::forward<_Args>(__args)...);
+        __annotator.__done();
         ++this->__end_;
     }
     else
@@ -1666,6 +1727,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         if (__p == this->__end_)
         {
             __alloc_traits::construct(this->__alloc(),
@@ -1680,6 +1742,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
                 ++__xr;
             *__p = *__xr;
         }
+        __annotator.__done();
     }
     else
     {
@@ -1705,6 +1768,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         if (__p == this->__end_)
         {
             __alloc_traits::construct(this->__alloc(),
@@ -1717,6 +1781,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
             __move_range(__p, this->__end_, __p + 1);
             *__p = _VSTD::move(__x);
         }
+        __annotator.__done();
     }
     else
     {
@@ -1743,6 +1808,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
     pointer __p = this->__begin_ + (__position - begin());
     if (this->__end_ < this->__end_cap())
     {
+        __RAII_IncreaseAnnotator __annotator(*this);
         if (__p == this->__end_)
         {
             __alloc_traits::construct(this->__alloc(),
@@ -1756,6 +1822,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
             __move_range(__p, this->__end_, __p + 1);
             *__p = _VSTD::move(__tmp);
         }
+        __annotator.__done();
     }
     else
     {
@@ -1794,7 +1861,9 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
             }
             if (__n > 0)
             {
+                __RAII_IncreaseAnnotator __annotator(*this);
                 __move_range(__p, __old_last, __p + __old_n);
+                __annotator.__done();
                 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
                 if (__p <= __xr && __xr < this->__end_)
                     __xr += __old_n;
@@ -1904,7 +1973,9 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __fi
             }
             if (__n > 0)
             {
+                __RAII_IncreaseAnnotator __annotator(*this, __n);
                 __move_range(__p, __old_last, __p + __old_n);
+                __annotator.__done();
                 _VSTD::copy(__first, __m, __p);
             }
         }
@@ -2297,7 +2368,7 @@ private:
     void deallocate() _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     static size_type __align_it(size_type __new_size) _NOEXCEPT
-        {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
+        {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
     _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
     _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
     template <class _ForwardIterator>
@@ -2796,10 +2867,10 @@ vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
 {
     deallocate();
+    __move_assign_alloc(__c);
     this->__begin_ = __c.__begin_;
     this->__size_ = __c.__size_;
     this->__cap() = __c.__cap();
-    __move_assign_alloc(__c);
     __c.__begin_ = nullptr;
     __c.__cap() = __c.__size_ = 0;
 }
diff --git a/system/lib/libcxx/CREDITS.TXT b/system/lib/libcxx/CREDITS.TXT
index 368b526fcc1b5..7a28adae09659 100644
--- a/system/lib/libcxx/CREDITS.TXT
+++ b/system/lib/libcxx/CREDITS.TXT
@@ -33,6 +33,10 @@ E: mclow.lists@gmail.com
 E: marshall@idio.com
 D: C++14 support, patches and bug fixes.
 
+N: Eric Fiselier
+E: eric@efcs.ca
+D: LFTS support, patches and bug fixes.
+
 N: Bill Fisher
 E: william.w.fisher@gmail.com
 D: Regex bug fixes.
diff --git a/system/lib/libcxx/LICENSE.txt b/system/lib/libcxx/LICENSE.TXT
similarity index 96%
rename from system/lib/libcxx/LICENSE.txt
rename to system/lib/libcxx/LICENSE.TXT
index 5ed8ec2248352..41ca5d19cc658 100644
--- a/system/lib/libcxx/LICENSE.txt
+++ b/system/lib/libcxx/LICENSE.TXT
@@ -14,7 +14,7 @@ Full text of the relevant licenses is included below.
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 
@@ -55,7 +55,7 @@ SOFTWARE.
 
 ==============================================================================
 
-Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/system/lib/libcxx/algorithm.cpp b/system/lib/libcxx/algorithm.cpp
index 10c4c3312599d..e548856ff6e14 100644
--- a/system/lib/libcxx/algorithm.cpp
+++ b/system/lib/libcxx/algorithm.cpp
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
 #include "algorithm"
 #include "random"
 #include "mutex"
@@ -48,12 +47,16 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo
 
 template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
 
+#ifndef _LIBCPP_HAS_NO_THREADS
 static pthread_mutex_t __rs_mut = PTHREAD_MUTEX_INITIALIZER;
+#endif
 unsigned __rs_default::__c_ = 0;
 
 __rs_default::__rs_default()
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     pthread_mutex_lock(&__rs_mut);
+#endif
     __c_ = 1;
 }
 
@@ -64,8 +67,12 @@ __rs_default::__rs_default(const __rs_default&)
 
 __rs_default::~__rs_default()
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     if (--__c_ == 0)
         pthread_mutex_unlock(&__rs_mut);
+#else
+    --__c_;
+#endif
 }
 
 __rs_default::result_type
diff --git a/system/lib/libcxx/chrono.cpp b/system/lib/libcxx/chrono.cpp
index 15a6f466a77d0..456941144e011 100644
--- a/system/lib/libcxx/chrono.cpp
+++ b/system/lib/libcxx/chrono.cpp
@@ -46,6 +46,7 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
     return system_clock::time_point(seconds(t));
 }
 
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
 // steady_clock
 
 const bool steady_clock::is_steady;
@@ -108,10 +109,8 @@ steady_clock::now() _NOEXCEPT
 }
 
 #else  // __APPLE__
-// FIXME: We assume that clock_gettime(CLOCK_MONOTONIC) works on
-// non-apple systems.  Instead, we should check _POSIX_TIMERS and
-// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
-// don't exist.
+// FIXME: if _LIBCPP_HAS_NO_MONOTONIC_CLOCK, then clock_gettime isn't going to
+// work. It may be possible to fall back on something else, depending on the system.
 
 // Warning:  If this is not truly steady, then it is non-conforming.  It is
 //  better for it to not exist and have the rest of libc++ use system_clock
@@ -127,6 +126,8 @@ steady_clock::now() _NOEXCEPT
 }
 #endif  // __APPLE__
 
+#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
+
 }
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/system/lib/libcxx/condition_variable.cpp b/system/lib/libcxx/condition_variable.cpp
index de0f6f47dd1b8..5fd5fc891c160 100644
--- a/system/lib/libcxx/condition_variable.cpp
+++ b/system/lib/libcxx/condition_variable.cpp
@@ -7,6 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "__config"
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 #include "condition_variable"
 #include "thread"
 #include "system_error"
@@ -32,7 +36,7 @@ condition_variable::notify_all() _NOEXCEPT
 }
 
 void
-condition_variable::wait(unique_lock<mutex>& lk)
+condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
 {
     if (!lk.owns_lock())
         __throw_system_error(EPERM,
@@ -44,7 +48,7 @@ condition_variable::wait(unique_lock<mutex>& lk)
 
 void
 condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
-               chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp)
+     chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) _NOEXCEPT
 {
     using namespace chrono;
     if (!lk.owns_lock())
@@ -79,3 +83,5 @@ notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
 }
 
 _LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/system/lib/libcxx/debug.cpp b/system/lib/libcxx/debug.cpp
index d0e867957dc01..60694a3bdb0ea 100644
--- a/system/lib/libcxx/debug.cpp
+++ b/system/lib/libcxx/debug.cpp
@@ -35,6 +35,7 @@ __get_const_db()
 namespace
 {
 
+#ifndef _LIBCPP_HAS_NO_THREADS
 typedef mutex mutex_type;
 typedef lock_guard<mutex_type> WLock;
 typedef lock_guard<mutex_type> RLock;
@@ -45,6 +46,7 @@ mut()
     static mutex_type m;
     return m;
 }
+#endif // !_LIBCPP_HAS_NO_THREADS
 
 }  // unnamed namespace
 
@@ -108,7 +110,9 @@ __libcpp_db::~__libcpp_db()
 void*
 __libcpp_db::__find_c_from_i(void* __i) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
     return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
@@ -117,7 +121,9 @@ __libcpp_db::__find_c_from_i(void* __i) const
 void
 __libcpp_db::__insert_ic(void* __i, const void* __c)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     if (__cbeg_ == __cend_)
         return;
     size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -138,7 +144,9 @@ __libcpp_db::__insert_ic(void* __i, const void* __c)
 __c_node*
 __libcpp_db::__insert_c(void* __c)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
     {
         size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
@@ -184,7 +192,9 @@ __libcpp_db::__insert_c(void* __c)
 void
 __libcpp_db::__erase_i(void* __i)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     if (__ibeg_ != __iend_)
     {
         size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
@@ -215,7 +225,9 @@ __libcpp_db::__erase_i(void* __i)
 void
 __libcpp_db::__invalidate_all(void* __c)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     if (__cend_ != __cbeg_)
     {
         size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -239,17 +251,23 @@ __libcpp_db::__invalidate_all(void* __c)
 __c_node*
 __libcpp_db::__find_c_and_lock(void* __c) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     mut().lock();
+#endif
     if (__cend_ == __cbeg_)
     {
+#ifndef _LIBCPP_HAS_NO_THREADS
         mut().unlock();
+#endif
         return nullptr;
     }
     size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
     __c_node* p = __cbeg_[hc];
     if (p == nullptr)
     {
+#ifndef _LIBCPP_HAS_NO_THREADS
         mut().unlock();
+#endif
         return nullptr;
     }
     while (p->__c_ != __c)
@@ -257,7 +275,9 @@ __libcpp_db::__find_c_and_lock(void* __c) const
         p = p->__next_;
         if (p == nullptr)
         {
+#ifndef _LIBCPP_HAS_NO_THREADS
             mut().unlock();
+#endif
             return nullptr;
         }
     }
@@ -281,13 +301,17 @@ __libcpp_db::__find_c(void* __c) const
 void
 __libcpp_db::unlock() const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     mut().unlock();
+#endif
 }
 
 void
 __libcpp_db::__erase_c(void* __c)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     if (__cend_ != __cbeg_)
     {
         size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -322,7 +346,9 @@ __libcpp_db::__erase_c(void* __c)
 void
 __libcpp_db::__iterator_copy(void* __i, const void* __i0)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     __i_node* i0 = __find_iterator(__i0);
     __c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
@@ -348,7 +374,9 @@ __libcpp_db::__iterator_copy(void* __i, const void* __i0)
 bool
 __libcpp_db::__dereferenceable(const void* __i) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     return i != nullptr && i->__c_ != nullptr && i->__c_->__dereferenceable(__i);
 }
@@ -356,7 +384,9 @@ __libcpp_db::__dereferenceable(const void* __i) const
 bool
 __libcpp_db::__decrementable(const void* __i) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     return i != nullptr && i->__c_ != nullptr && i->__c_->__decrementable(__i);
 }
@@ -364,7 +394,9 @@ __libcpp_db::__decrementable(const void* __i) const
 bool
 __libcpp_db::__addable(const void* __i, ptrdiff_t __n) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     return i != nullptr && i->__c_ != nullptr && i->__c_->__addable(__i, __n);
 }
@@ -372,7 +404,9 @@ __libcpp_db::__addable(const void* __i, ptrdiff_t __n) const
 bool
 __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     return i != nullptr && i->__c_ != nullptr && i->__c_->__subscriptable(__i, __n);
 }
@@ -380,7 +414,9 @@ __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
 bool
 __libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     RLock _(mut());
+#endif
     __i_node* i = __find_iterator(__i);
     __i_node* j = __find_iterator(__j);
     __c_node* ci = i != nullptr ? i->__c_ : nullptr;
@@ -391,7 +427,9 @@ __libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
 void
 __libcpp_db::swap(void* c1, void* c2)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_);
     __c_node* p1 = __cbeg_[hc];
     _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A");
@@ -420,7 +458,9 @@ __libcpp_db::swap(void* c1, void* c2)
 void
 __libcpp_db::__insert_i(void* __i)
 {
+#ifndef _LIBCPP_HAS_NO_THREADS
     WLock _(mut());
+#endif
     __insert_iterator(__i);
 }
 
diff --git a/system/lib/libcxx/future.cpp b/system/lib/libcxx/future.cpp
index 70919ab7df84a..0c5c2c4488d2d 100644
--- a/system/lib/libcxx/future.cpp
+++ b/system/lib/libcxx/future.cpp
@@ -7,6 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "__config"
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 #include "future"
 #include "string"
 
@@ -26,8 +30,13 @@ __future_error_category::name() const _NOEXCEPT
     return "future";
 }
 
+#if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wswitch"
+#elif defined(__GNUC__) || defined(__GNUG__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+#endif
 
 string
 __future_error_category::message(int ev) const
@@ -50,7 +59,11 @@ __future_error_category::message(int ev) const
     return string("unspecified future_errc value\n");
 }
 
+#if defined(__clang__)
 #pragma clang diagnostic pop
+#elif defined(__GNUC__) || defined(__GNUG__)
+#pragma GCC diagnostic pop
+#endif
 
 const error_category&
 future_category() _NOEXCEPT
@@ -289,3 +302,5 @@ shared_future<void>::operator=(const shared_future& __rhs)
 }
 
 _LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/system/lib/libcxx/hash.cpp b/system/lib/libcxx/hash.cpp
index 388ab2ebe1757..dc90f789c6b81 100644
--- a/system/lib/libcxx/hash.cpp
+++ b/system/lib/libcxx/hash.cpp
@@ -136,7 +136,7 @@ const unsigned indices[] =
 // The algorithm creates a list of small primes, plus an open-ended list of
 // potential primes.  All prime numbers are potential prime numbers.  However
 // some potential prime numbers are not prime.  In an ideal world, all potential
-// prime numbers would be prime.  Candiate prime numbers are chosen as the next
+// prime numbers would be prime.  Candidate prime numbers are chosen as the next
 // highest potential prime.  Then this number is tested for prime by dividing it
 // by all potential prime numbers less than the sqrt of the candidate.
 //
diff --git a/system/lib/libcxx/ios.cpp b/system/lib/libcxx/ios.cpp
index 004d318320c05..06426c7b60427 100644
--- a/system/lib/libcxx/ios.cpp
+++ b/system/lib/libcxx/ios.cpp
@@ -7,8 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
+#include "__config"
 #include "ios"
 #include "streambuf"
 #include "istream"
@@ -54,9 +53,9 @@ string
 __iostream_category::message(int ev) const
 {
     if (ev != static_cast<int>(io_errc::stream)
-#ifdef ELAST
-        && ev <= ELAST
-#endif
+#ifdef _LIBCPP_ELAST
+        && ev <= _LIBCPP_ELAST
+#endif  // _LIBCPP_ELAST
         )
         return __do_message::message(ev);
     return string("unspecified iostream_category error");
@@ -134,7 +133,7 @@ locale
 ios_base::imbue(const locale& newloc)
 {
     static_assert(sizeof(locale) == sizeof(__loc_), "");
-    locale& loc_storage = *(locale*)&__loc_;
+    locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
     locale oldloc = loc_storage;
     loc_storage = newloc;
     __call_callbacks(imbue_event);
@@ -144,12 +143,12 @@ ios_base::imbue(const locale& newloc)
 locale
 ios_base::getloc() const
 {
-    const locale& loc_storage = *(locale*)&__loc_;
+    const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
     return loc_storage;
 }
 
 // xalloc
-#if __has_feature(cxx_atomic) && !defined(__EMSCRIPTEN__)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
 #else
 int ios_base::__xindex_ = 0;
@@ -173,7 +172,8 @@ ios_base::iword(int index)
             newcap = _VSTD::max(2 * __iarray_cap_, req_size);
         else
             newcap = mx;
-        long* iarray = (long*)realloc(__iarray_, newcap * sizeof(long));
+        size_t newsize = newcap * sizeof(long);
+        long* iarray = static_cast<long*>(realloc(__iarray_, newsize));
         if (iarray == 0)
         {
             setstate(badbit);
@@ -201,7 +201,8 @@ ios_base::pword(int index)
             newcap = _VSTD::max(2 * __parray_cap_, req_size);
         else
             newcap = mx;
-        void** parray = (void**)realloc(__parray_, newcap * sizeof(void*));
+        size_t newsize = newcap * sizeof(void*);
+        void** parray = static_cast<void**>(realloc(__parray_, newsize));
         if (parray == 0)
         {
             setstate(badbit);
@@ -231,11 +232,13 @@ ios_base::register_callback(event_callback fn, int index)
             newcap = _VSTD::max(2 * __event_cap_, req_size);
         else
             newcap = mx;
-        event_callback* fns = (event_callback*)realloc(__fn_, newcap * sizeof(event_callback));
+        size_t newesize = newcap * sizeof(event_callback);
+        event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newesize));
         if (fns == 0)
             setstate(badbit);
         __fn_ = fns;
-        int* indxs = (int*)realloc(__index_, newcap * sizeof(int));
+        size_t newisize = newcap * sizeof(int);
+        int* indxs = static_cast<int *>(realloc(__index_, newisize));
         if (indxs == 0)
             setstate(badbit);
         __index_ = indxs;
@@ -248,7 +251,7 @@ ios_base::register_callback(event_callback fn, int index)
 ios_base::~ios_base()
 {
     __call_callbacks(erase_event);
-    locale& loc_storage = *(locale*)&__loc_;
+    locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
     loc_storage.~locale();
     free(__fn_);
     free(__index_);
@@ -299,19 +302,22 @@ void
 ios_base::copyfmt(const ios_base& rhs)
 {
     // If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
-    // Don't alter *this until all needed resources are aquired
+    // Don't alter *this until all needed resources are acquired
     unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
     unique_ptr<int, void (*)(void*)> new_ints(0, free);
     unique_ptr<long, void (*)(void*)> new_longs(0, free);
     unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
     if (__event_cap_ < rhs.__event_size_)
     {
-        new_callbacks.reset((event_callback*)malloc(sizeof(event_callback) * rhs.__event_size_));
+        size_t newesize = sizeof(event_callback) * rhs.__event_size_;
+        new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_callbacks)
             throw bad_alloc();
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        new_ints.reset((int*)malloc(sizeof(int) * rhs.__event_size_));
+
+        size_t newisize = sizeof(int) * rhs.__event_size_;
+        new_ints.reset(static_cast<int *>(malloc(newisize)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_ints)
             throw bad_alloc();
@@ -319,7 +325,8 @@ ios_base::copyfmt(const ios_base& rhs)
     }
     if (__iarray_cap_ < rhs.__iarray_size_)
     {
-        new_longs.reset((long*)malloc(sizeof(long) * rhs.__iarray_size_));
+        size_t newsize = sizeof(long) * rhs.__iarray_size_;
+        new_longs.reset(static_cast<long*>(malloc(newsize)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_longs)
             throw bad_alloc();
@@ -327,7 +334,8 @@ ios_base::copyfmt(const ios_base& rhs)
     }
     if (__parray_cap_ < rhs.__parray_size_)
     {
-        new_pointers.reset((void**)malloc(sizeof(void*) * rhs.__parray_size_));
+        size_t newsize = sizeof(void*) * rhs.__parray_size_;
+        new_pointers.reset(static_cast<void**>(malloc(newsize)));
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_pointers)
             throw bad_alloc();
@@ -337,8 +345,8 @@ ios_base::copyfmt(const ios_base& rhs)
     __fmtflags_ = rhs.__fmtflags_;
     __precision_ = rhs.__precision_;
     __width_ = rhs.__width_;
-    locale& lhs_loc = *(locale*)&__loc_;
-    locale& rhs_loc = *(locale*)&rhs.__loc_;
+    locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+    const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
     lhs_loc = rhs_loc;
     if (__event_cap_ < rhs.__event_size_)
     {
@@ -381,7 +389,7 @@ ios_base::move(ios_base& rhs)
     __rdstate_ = rhs.__rdstate_;
     __exceptions_ = rhs.__exceptions_;
     __rdbuf_ = 0;
-    locale& rhs_loc = *(locale*)&rhs.__loc_;
+    locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
     ::new(&__loc_) locale(rhs_loc);
     __fn_ = rhs.__fn_;
     rhs.__fn_ = 0;
@@ -413,8 +421,8 @@ ios_base::swap(ios_base& rhs) _NOEXCEPT
     _VSTD::swap(__width_, rhs.__width_);
     _VSTD::swap(__rdstate_, rhs.__rdstate_);
     _VSTD::swap(__exceptions_, rhs.__exceptions_);
-    locale& lhs_loc = *(locale*)&__loc_;
-    locale& rhs_loc = *(locale*)&rhs.__loc_;
+    locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+    locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
     _VSTD::swap(lhs_loc, rhs_loc);
     _VSTD::swap(__fn_, rhs.__fn_);
     _VSTD::swap(__index_, rhs.__index_);
diff --git a/system/lib/libcxx/locale.cpp b/system/lib/libcxx/locale.cpp
index 8e7fdb43189ce..f21e35dd540a1 100644
--- a/system/lib/libcxx/locale.cpp
+++ b/system/lib/libcxx/locale.cpp
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
 // On Solaris, we need to define something to make the C99 parts of localeconv
 // visible.
 #ifdef __sun__
@@ -30,9 +28,9 @@
 #include "__sso_allocator"
 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
 #include <support/win32/locale_win32.h>
-#else // _LIBCPP_MSVCRT
+#elif !defined(__ANDROID__)
 #include <langinfo.h>
-#endif // !_LIBCPP_MSVCRT
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -68,7 +66,7 @@ make(A0 a0)
 {
     static typename aligned_storage<sizeof(T)>::type buf;
     ::new (&buf) T(a0);
-    return *(T*)&buf;
+    return *reinterpret_cast<T*>(&buf);
 }
 
 template <class T, class A0, class A1>
@@ -78,7 +76,7 @@ make(A0 a0, A1 a1)
 {
     static typename aligned_storage<sizeof(T)>::type buf;
     ::new (&buf) T(a0, a1);
-    return *(T*)&buf;
+    return *reinterpret_cast<T*>(&buf);
 }
 
 template <class T, class A0, class A1, class A2>
@@ -88,7 +86,7 @@ make(A0 a0, A1 a1, A2 a2)
 {
     static typename aligned_storage<sizeof(T)>::type buf;
     ::new (&buf) T(a0, a1, a2);
-    return *(T*)&buf;
+    return *reinterpret_cast<T*>(&buf);
 }
 
 template <typename T, size_t N>
@@ -177,7 +175,7 @@ locale::__imp::__imp(size_t refs)
     facets_.clear();
     install(&make<_VSTD::collate<char> >(1u));
     install(&make<_VSTD::collate<wchar_t> >(1u));
-    install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
+    install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
     install(&make<_VSTD::ctype<wchar_t> >(1u));
     install(&make<codecvt<char, char, mbstate_t> >(1u));
     install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
@@ -461,7 +459,7 @@ locale::__imp::make_classic()
 {
     // only one thread can get in here and it only gets in once
     static aligned_storage<sizeof(locale)>::type buf;
-    locale* c = (locale*)&buf;
+    locale* c = reinterpret_cast<locale*>(&buf);
     c->__locale_ = &make<__imp>(1u);
     return *c;
 }
@@ -479,7 +477,7 @@ locale::__imp::make_global()
     // only one thread can get in here and it only gets in once
     static aligned_storage<sizeof(locale)>::type buf;
     ::new (&buf) locale(locale::classic());
-    return *(locale*)&buf;
+    return *reinterpret_cast<locale*>(&buf);
 }
 
 locale&
@@ -1037,6 +1035,8 @@ ctype<char>::classic_table()  _NOEXCEPT
     return *__ctype_b_loc();
 #elif defined(_AIX)
     return (const unsigned int *)__lc_ctype_ptr->obj->mask;
+#elif defined(__ANDROID__)
+    return reinterpret_cast<const unsigned char*>(_ctype_) + 1;
 #else
     // Platform not supported: abort so the person doing the port knows what to
     // fix
@@ -1615,9 +1615,9 @@ int
 codecvt<wchar_t, char, mbstate_t>::do_encoding() const  _NOEXCEPT
 {
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+    if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
 #else
-    if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+    if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
 #endif
     {
         // stateless encoding
@@ -1743,8 +1743,8 @@ utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm
                 return codecvt_base::error;
             if (to_end-to_nxt < 4)
                 return codecvt_base::partial;
-            if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
-                (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
+            if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
+                ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
                 return codecvt_base::error;
             ++frm_nxt;
             uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
@@ -1820,8 +1820,8 @@ utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm
                 return codecvt_base::error;
             if (to_end-to_nxt < 4)
                 return codecvt_base::partial;
-            if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
-                (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
+            if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
+                ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
                 return codecvt_base::error;
             ++frm_nxt;
             uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
@@ -1944,9 +1944,9 @@ utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nx
                 return codecvt_base::error;
             if (to_end-to_nxt < 2)
                 return codecvt_base::partial;
-            if (((((unsigned long)c1 & 7) << 18) +
-                (((unsigned long)c2 & 0x3F) << 12) +
-                (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+            if ((((c1 & 7UL) << 18) +
+                ((c2 & 0x3FUL) << 12) +
+                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
                 return codecvt_base::error;
             *to_nxt = static_cast<uint16_t>(
                     0xD800
@@ -2065,9 +2065,9 @@ utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nx
                 return codecvt_base::error;
             if (to_end-to_nxt < 2)
                 return codecvt_base::partial;
-            if (((((unsigned long)c1 & 7) << 18) +
-                (((unsigned long)c2 & 0x3F) << 12) +
-                (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+            if ((((c1 & 7UL) << 18) +
+                ((c2 & 0x3FUL) << 12) +
+                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
                 return codecvt_base::error;
             *to_nxt = static_cast<uint32_t>(
                     0xD800
@@ -2174,9 +2174,9 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
             }
             if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
                 break;
-            if (((((unsigned long)c1 & 7) << 18) +
-                (((unsigned long)c2 & 0x3F) << 12) +
-                (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+            if ((((c1 & 7UL) << 18) +
+                ((c2 & 0x3FUL) << 12) +
+                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
                 break;
             ++nchar16_t;
             frm_nxt += 4;
diff --git a/system/lib/libcxx/memory.cpp b/system/lib/libcxx/memory.cpp
index 98bcc864eeb00..c56d031adfbf3 100644
--- a/system/lib/libcxx/memory.cpp
+++ b/system/lib/libcxx/memory.cpp
@@ -9,8 +9,10 @@
 
 #define _LIBCPP_BUILDING_MEMORY
 #include "memory"
+#ifndef _LIBCPP_HAS_NO_THREADS
 #include "mutex"
 #include "thread"
+#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -119,7 +121,7 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
 
 #endif  // _LIBCPP_NO_RTTI
 
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 
 static const std::size_t __sp_mut_count = 16;
 static pthread_mutex_t mut_back_imp[__sp_mut_count] =
@@ -172,7 +174,7 @@ __get_sp_mut(const void* p)
     return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
 }
 
-#endif // __has_feature(cxx_atomic)
+#endif // __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS
 
 void
 declare_reachable(void*)
@@ -208,7 +210,7 @@ align(size_t alignment, size_t size, void*& ptr, size_t& space)
     if (size <= space)
     {
         char* p1 = static_cast<char*>(ptr);
-        char* p2 = (char*)((size_t)(p1 + (alignment - 1)) & -alignment);
+        char* p2 = reinterpret_cast<char*>(reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
         size_t d = static_cast<size_t>(p2 - p1);
         if (d <= space - size)
         {
diff --git a/system/lib/libcxx/mutex.cpp b/system/lib/libcxx/mutex.cpp
index 07678978a6788..e56271d308e6f 100644
--- a/system/lib/libcxx/mutex.cpp
+++ b/system/lib/libcxx/mutex.cpp
@@ -14,6 +14,7 @@
 #include "cassert"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
+#ifndef _LIBCPP_HAS_NO_THREADS
 
 const defer_lock_t  defer_lock = {};
 const try_to_lock_t try_to_lock = {};
@@ -206,18 +207,42 @@ recursive_timed_mutex::unlock() _NOEXCEPT
     }
 }
 
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 // If dispatch_once_f ever handles C++ exceptions, and if one can get to it
 // without illegal macros (unexpected macros not beginning with _UpperCase or
 // __lowercase), and if it stops spinning waiting threads, then call_once should
 // call into dispatch_once_f instead of here. Relevant radar this code needs to
 // keep in sync with:  7741191.
 
+#ifndef _LIBCPP_HAS_NO_THREADS
 static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t  cv  = PTHREAD_COND_INITIALIZER;
+#endif
 
 void
 __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
 {
+#if defined(_LIBCPP_HAS_NO_THREADS)
+    if (flag == 0)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            flag = 1;
+            func(arg);
+            flag = ~0ul;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            flag = 0ul;
+            throw;
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    }
+#else // !_LIBCPP_HAS_NO_THREADS
     pthread_mutex_lock(&mut);
     while (flag == 1)
         pthread_cond_wait(&cv, &mut);
@@ -248,6 +273,8 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
     }
     else
         pthread_mutex_unlock(&mut);
+#endif // !_LIBCPP_HAS_NO_THREADS
+
 }
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/system/lib/libcxx/new.cpp b/system/lib/libcxx/new.cpp
index f4998cfb2a472..3b7c34138df97 100644
--- a/system/lib/libcxx/new.cpp
+++ b/system/lib/libcxx/new.cpp
@@ -167,7 +167,7 @@ set_new_handler(new_handler handler) _NOEXCEPT
 new_handler
 get_new_handler() _NOEXCEPT
 {
-    return __sync_fetch_and_add(&__new_handler, (new_handler)0);
+    return __sync_fetch_and_add(&__new_handler, nullptr);
 }
 
 #endif // !__GLIBCXX__
diff --git a/system/lib/libcxx/random.cpp b/system/lib/libcxx/random.cpp
index bd24f2e50c1ab..86017ef0d46ba 100644
--- a/system/lib/libcxx/random.cpp
+++ b/system/lib/libcxx/random.cpp
@@ -49,7 +49,7 @@ random_device::operator()()
 random_device::random_device(const string& __token)
     : __f_(open(__token.c_str(), O_RDONLY))
 {
-    if (__f_ <= 0)
+    if (__f_ < 0)
         __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
 }
 
@@ -62,7 +62,22 @@ unsigned
 random_device::operator()()
 {
     unsigned r;
-    read(__f_, &r, sizeof(r));
+    size_t n = sizeof(r);
+    char* p = reinterpret_cast<char*>(&r);
+    while (n > 0)
+    {
+        ssize_t s = read(__f_, p, n);
+        if (s == 0)
+            __throw_system_error(ENODATA, "random_device got EOF");
+        if (s == -1)
+        {
+            if (errno != EINTR)
+                __throw_system_error(errno, "random_device got an unexpected error");
+            continue;
+        }
+        n -= static_cast<size_t>(s);
+        p += static_cast<size_t>(s);
+    }
     return r;
 }
 #endif // defined(_WIN32)
diff --git a/system/lib/libcxx/readme.txt b/system/lib/libcxx/readme.txt
index ae99316df3d1b..7487d2914bb80 100644
--- a/system/lib/libcxx/readme.txt
+++ b/system/lib/libcxx/readme.txt
@@ -1,3 +1 @@
-These files are from libc++, svn revision 195693, 2013-11-26. See http://libcxx.llvm.org
-
-A fix to http://llvm.org/bugs/show_bug.cgi?id=18735 is backported on top of the above svn revision. See https://github.com/kripken/emscripten/pull/2688
+These files are from libc++, svn revision 218372, 2014-09-24. See http://libcxx.llvm.org
diff --git a/system/lib/libcxx/regex.cpp b/system/lib/libcxx/regex.cpp
index e3ec2810c7746..17dd6eaa60a7e 100644
--- a/system/lib/libcxx/regex.cpp
+++ b/system/lib/libcxx/regex.cpp
@@ -69,8 +69,10 @@ regex_error::~regex_error() throw() {}
 
 namespace {
 
+#if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wpadded"
+#endif
 
 struct collationnames
 {
@@ -78,7 +80,9 @@ struct collationnames
     char char_;
 };
 
+#if defined(__clang__)
 #pragma clang diagnostic pop
+#endif
 
 const collationnames collatenames[] =
 {
@@ -195,16 +199,20 @@ const collationnames collatenames[] =
     {"zero", 0x30}
 };
 
+#if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wpadded"
+#endif
 
 struct classnames
 {
     const char* elem_;
-    ctype_base::mask mask_;
+    regex_traits<char>::char_class_type mask_;
 };
 
+#if defined(__clang__)
 #pragma clang diagnostic pop
+#endif
 
 const classnames ClassNames[] =
 {
@@ -246,12 +254,12 @@ __get_collation_name(const char* s)
     return r;
 }
 
-ctype_base::mask
+regex_traits<char>::char_class_type
 __get_classname(const char* s, bool __icase)
 {
     const classnames* i =
             _VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
-    ctype_base::mask r = 0;
+    regex_traits<char>::char_class_type r = 0;
     if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
     {
         r = i->mask_;
diff --git a/system/lib/libcxx/shared_mutex.cpp b/system/lib/libcxx/shared_mutex.cpp
index 5fb22e44544df..2b78c1feb9f53 100644
--- a/system/lib/libcxx/shared_mutex.cpp
+++ b/system/lib/libcxx/shared_mutex.cpp
@@ -7,12 +7,15 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "__config"
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 #define _LIBCPP_BUILDING_SHARED_MUTEX
 #include "shared_mutex"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-shared_mutex::shared_mutex()
+shared_timed_mutex::shared_timed_mutex()
     : __state_(0)
 {
 }
@@ -20,7 +23,7 @@ shared_mutex::shared_mutex()
 // Exclusive ownership
 
 void
-shared_mutex::lock()
+shared_timed_mutex::lock()
 {
     unique_lock<mutex> lk(__mut_);
     while (__state_ & __write_entered_)
@@ -31,7 +34,7 @@ shared_mutex::lock()
 }
 
 bool
-shared_mutex::try_lock()
+shared_timed_mutex::try_lock()
 {
     unique_lock<mutex> lk(__mut_);
     if (__state_ == 0)
@@ -43,7 +46,7 @@ shared_mutex::try_lock()
 }
 
 void
-shared_mutex::unlock()
+shared_timed_mutex::unlock()
 {
     lock_guard<mutex> _(__mut_);
     __state_ = 0;
@@ -53,7 +56,7 @@ shared_mutex::unlock()
 // Shared ownership
 
 void
-shared_mutex::lock_shared()
+shared_timed_mutex::lock_shared()
 {
     unique_lock<mutex> lk(__mut_);
     while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
@@ -64,7 +67,7 @@ shared_mutex::lock_shared()
 }
 
 bool
-shared_mutex::try_lock_shared()
+shared_timed_mutex::try_lock_shared()
 {
     unique_lock<mutex> lk(__mut_);
     unsigned num_readers = __state_ & __n_readers_;
@@ -79,7 +82,7 @@ shared_mutex::try_lock_shared()
 }
 
 void
-shared_mutex::unlock_shared()
+shared_timed_mutex::unlock_shared()
 {
     lock_guard<mutex> _(__mut_);
     unsigned num_readers = (__state_ & __n_readers_) - 1;
@@ -99,3 +102,5 @@ shared_mutex::unlock_shared()
 
 
 _LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/system/lib/libcxx/stdexcept.cpp b/system/lib/libcxx/stdexcept.cpp
index a4207d6058ff9..aff4b1850d36b 100644
--- a/system/lib/libcxx/stdexcept.cpp
+++ b/system/lib/libcxx/stdexcept.cpp
@@ -7,123 +7,42 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "__refstring"
 #include "stdexcept"
 #include "new"
 #include "string"
-#include <cstdlib>
-#include <cstring>
-#include <cstdint>
-#include <cstddef>
 #include "system_error"
 
 #ifndef __has_include
 #define __has_include(inc) 0
 #endif
 
-#ifdef __APPLE__
+/* For _LIBCPPABI_VERSION */
+#if __has_include(<cxxabi.h>) || defined(__APPLE_) || defined(LIBCXXRT)
 #include <cxxabi.h>
-#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
-#include <cxxabi.h>
-#endif
-
-// Note:  optimize for size
-
-#if ! defined(_LIBCPP_MSVC)
-#pragma GCC visibility push(hidden)
 #endif
 
-namespace
-{
-
-class __libcpp_nmstr
-{
-private:
-    const char* str_;
-
-    typedef std::size_t unused_t;
-    typedef std::ptrdiff_t count_t;
-
-    static const std::ptrdiff_t offset = static_cast<std::ptrdiff_t>(2*sizeof(unused_t) +
-                                                                       sizeof(count_t));
-
-    count_t& count() const _NOEXCEPT {return (count_t&)(*(str_ - sizeof(count_t)));}
-public:
-    explicit __libcpp_nmstr(const char* msg);
-    __libcpp_nmstr(const __libcpp_nmstr& s) _NOEXCEPT;
-    __libcpp_nmstr& operator=(const __libcpp_nmstr& s) _NOEXCEPT;
-    ~__libcpp_nmstr();
-    const char* c_str() const _NOEXCEPT {return str_;}
-};
-
-__libcpp_nmstr::__libcpp_nmstr(const char* msg)
-{
-    std::size_t len = strlen(msg);
-    str_ = new char[len + 1 + offset];
-    unused_t* c = (unused_t*)str_;
-    c[0] = c[1] = len;
-    str_ += offset;
-    count() = 0;
-    std::memcpy(const_cast<char*>(c_str()), msg, len + 1);
-}
-
-inline
-__libcpp_nmstr::__libcpp_nmstr(const __libcpp_nmstr& s) _NOEXCEPT
-    : str_(s.str_)
-{
-    __sync_add_and_fetch(&count(), 1);
-}
-
-__libcpp_nmstr&
-__libcpp_nmstr::operator=(const __libcpp_nmstr& s) _NOEXCEPT
-{
-    const char* p = str_;
-    str_ = s.str_;
-    __sync_add_and_fetch(&count(), 1);
-    if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), count_t(-1)) < 0)
-        delete [] (p-offset);
-    return *this;
-}
-
-inline
-__libcpp_nmstr::~__libcpp_nmstr()
-{
-    if (__sync_add_and_fetch(&count(), count_t(-1)) < 0)
-        delete [] (str_ - offset);
-}
-
-}
-
-#if ! defined(_LIBCPP_MSVC)
-#pragma GCC visibility pop
-#endif
+static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char *), "");
 
 namespace std  // purposefully not using versioning namespace
 {
 
-logic_error::logic_error(const string& msg)
+logic_error::logic_error(const string& msg) : __imp_(msg.c_str())
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr(msg.c_str());
 }
 
-logic_error::logic_error(const char* msg)
+logic_error::logic_error(const char* msg) : __imp_(msg)
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr(msg);
 }
 
-logic_error::logic_error(const logic_error& le) _NOEXCEPT
+logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_)
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
 }
 
 logic_error&
 logic_error::operator=(const logic_error& le) _NOEXCEPT
 {
-    __libcpp_nmstr& s1 = (__libcpp_nmstr&)__imp_;
-    const __libcpp_nmstr& s2 = (const __libcpp_nmstr&)le.__imp_;
-    s1 = s2;
+    __imp_ = le.__imp_;
     return *this;
 }
 
@@ -131,43 +50,33 @@ logic_error::operator=(const logic_error& le) _NOEXCEPT
 
 logic_error::~logic_error() _NOEXCEPT
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    s.~__libcpp_nmstr();
 }
 
 const char*
 logic_error::what() const _NOEXCEPT
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    return s.c_str();
+    return __imp_.c_str();
 }
 
 #endif
 
-runtime_error::runtime_error(const string& msg)
+runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str())
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr(msg.c_str());
 }
 
-runtime_error::runtime_error(const char* msg)
+runtime_error::runtime_error(const char* msg) : __imp_(msg)
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr(msg);
 }
 
 runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT
+  : __imp_(le.__imp_)
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
 }
 
 runtime_error&
 runtime_error::operator=(const runtime_error& le) _NOEXCEPT
 {
-    __libcpp_nmstr& s1 = (__libcpp_nmstr&)__imp_;
-    const __libcpp_nmstr& s2 = (const __libcpp_nmstr&)le.__imp_;
-    s1 = s2;
+    __imp_ = le.__imp_;
     return *this;
 }
 
@@ -175,15 +84,12 @@ runtime_error::operator=(const runtime_error& le) _NOEXCEPT
 
 runtime_error::~runtime_error() _NOEXCEPT
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    s.~__libcpp_nmstr();
 }
 
 const char*
 runtime_error::what() const _NOEXCEPT
 {
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    return s.c_str();
+    return __imp_.c_str();
 }
 
 domain_error::~domain_error() _NOEXCEPT {}
diff --git a/system/lib/libcxx/string.cpp b/system/lib/libcxx/string.cpp
index fde52129e9fbb..fdaad2927340b 100644
--- a/system/lib/libcxx/string.cpp
+++ b/system/lib/libcxx/string.cpp
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
 #include "string"
 #include "cstdlib"
 #include "cwchar"
diff --git a/system/lib/libcxx/strstream.cpp b/system/lib/libcxx/strstream.cpp
index c1965ea3762a3..ea728138db66c 100644
--- a/system/lib/libcxx/strstream.cpp
+++ b/system/lib/libcxx/strstream.cpp
@@ -61,7 +61,7 @@ strstreambuf::strstreambuf(const char* __gnext, streamsize __n)
       __palloc_(nullptr),
       __pfree_(nullptr)
 {
-    __init((char*)__gnext, __n, nullptr);
+    __init(const_cast<char *>(__gnext), __n, nullptr);
 }
 
 strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg)
@@ -70,7 +70,7 @@ strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __
       __palloc_(nullptr),
       __pfree_(nullptr)
 {
-    __init((char*)__gnext, __n, (char*)__pbeg);
+    __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
 }
 
 strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
@@ -79,7 +79,7 @@ strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
       __palloc_(nullptr),
       __pfree_(nullptr)
 {
-    __init((char*)__gnext, __n, nullptr);
+    __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
 }
 
 strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg)
@@ -88,7 +88,7 @@ strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char
       __palloc_(nullptr),
       __pfree_(nullptr)
 {
-    __init((char*)__gnext, __n, (char*)__pbeg);
+    __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
 }
 
 strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
@@ -97,7 +97,7 @@ strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
       __palloc_(nullptr),
       __pfree_(nullptr)
 {
-    __init((char*)__gnext, __n, nullptr);
+    __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
 }
 
 strstreambuf::~strstreambuf()
@@ -186,7 +186,7 @@ strstreambuf::overflow(int_type __c)
     }
     *pptr() = static_cast<char>(__c);
     pbump(1);
-    return int_type((unsigned char)__c);
+    return int_type(static_cast<unsigned char>(__c));
 }
 
 strstreambuf::int_type
@@ -222,7 +222,7 @@ strstreambuf::underflow()
             return EOF;
         setg(eback(), gptr(), pptr());
     }
-    return int_type((unsigned char)*gptr());
+    return int_type(static_cast<unsigned char>(*gptr()));
 }
 
 strstreambuf::pos_type
diff --git a/system/lib/libcxx/support/solaris/xlocale.c b/system/lib/libcxx/support/solaris/xlocale.c
index a2c1fa905cccc..39dd8e36835e0 100644
--- a/system/lib/libcxx/support/solaris/xlocale.c
+++ b/system/lib/libcxx/support/solaris/xlocale.c
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
 
 #ifdef __sun__
       
diff --git a/system/lib/libcxx/support/win32/support.cpp b/system/lib/libcxx/support/win32/support.cpp
index 6ee31e0cb329b..e989681a6d5f2 100644
--- a/system/lib/libcxx/support/win32/support.cpp
+++ b/system/lib/libcxx/support/win32/support.cpp
@@ -107,8 +107,8 @@ size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
 // Converts max_source_chars from the wide character buffer pointer to by *src,
 // into the multi byte character sequence buffer stored at dst which must be
 // dst_size_bytes bytes in size.
-// Returns >= 0: the number of bytes in the sequence sequence 
-// converted frome *src, excluding the null terminator.
+// Returns >= 0: the number of bytes in the sequence
+// converted from *src, excluding the null terminator.
 // Returns size_t(-1) if an error occurs, also sets errno.
 // If dst is NULL dst_size_bytes is ignored and no bytes are copied to dst 
 // and no "out" parameters are updated.
diff --git a/system/lib/libcxx/symbols b/system/lib/libcxx/symbols
index 2c026b0fbfe05..9384940b2bb14 100644
--- a/system/lib/libcxx/symbols
+++ b/system/lib/libcxx/symbols
@@ -1,6 +1,3 @@
-         T _ZNKSt11logic_error4whatEv
-         T _ZNKSt13bad_exception4whatEv
-         T _ZNKSt13runtime_error4whatEv
          T _ZNKSt16nested_exception14rethrow_nestedEv
          T _ZNKSt3__110__time_put8__do_putEPcRS1_PK2tmcc
          T _ZNKSt3__110__time_put8__do_putEPwRS1_PK2tmcc
@@ -446,6 +443,7 @@
          T _ZNKSt3__15ctypeIwE9do_narrowEPKwS3_cPc
          T _ZNKSt3__15ctypeIwE9do_narrowEwc
          T _ZNKSt3__16locale4nameEv
+         C _ZNKSt3__16locale5__imp9has_facetEl
          T _ZNKSt3__16locale5__imp9use_facetEl
          T _ZNKSt3__16locale9has_facetERNS0_2idE
          T _ZNKSt3__16locale9use_facetERNS0_2idE
@@ -721,25 +719,7 @@
          T _ZNSt11logic_errorC2EPKc
          T _ZNSt11logic_errorC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE
          T _ZNSt11logic_errorC2ERKS_
-         T _ZNSt11logic_errorD0Ev
-         T _ZNSt11logic_errorD1Ev
-         T _ZNSt11logic_errorD2Ev
          T _ZNSt11logic_erroraSERKS_
-         T _ZNSt11range_errorD0Ev
-         T _ZNSt11range_errorD1Ev
-         T _ZNSt11range_errorD2Ev
-         T _ZNSt12domain_errorD0Ev
-         T _ZNSt12domain_errorD1Ev
-         T _ZNSt12domain_errorD2Ev
-         T _ZNSt12length_errorD0Ev
-         T _ZNSt12length_errorD1Ev
-         T _ZNSt12length_errorD2Ev
-         T _ZNSt12out_of_rangeD0Ev
-         T _ZNSt12out_of_rangeD1Ev
-         T _ZNSt12out_of_rangeD2Ev
-         T _ZNSt13bad_exceptionD0Ev
-         T _ZNSt13bad_exceptionD1Ev
-         T _ZNSt13bad_exceptionD2Ev
          T _ZNSt13exception_ptrC1ERKS_
          T _ZNSt13exception_ptrC2ERKS_
          T _ZNSt13exception_ptrD1Ev
@@ -751,24 +731,13 @@
          T _ZNSt13runtime_errorC2EPKc
          T _ZNSt13runtime_errorC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE
          T _ZNSt13runtime_errorC2ERKS_
-         T _ZNSt13runtime_errorD0Ev
-         T _ZNSt13runtime_errorD1Ev
-         T _ZNSt13runtime_errorD2Ev
          T _ZNSt13runtime_erroraSERKS_
-         T _ZNSt14overflow_errorD0Ev
-         T _ZNSt14overflow_errorD1Ev
-         T _ZNSt14overflow_errorD2Ev
-         T _ZNSt15underflow_errorD0Ev
-         T _ZNSt15underflow_errorD1Ev
-         T _ZNSt15underflow_errorD2Ev
-         T _ZNSt16invalid_argumentD0Ev
-         T _ZNSt16invalid_argumentD1Ev
-         T _ZNSt16invalid_argumentD2Ev
          T _ZNSt16nested_exceptionC1Ev
          T _ZNSt16nested_exceptionC2Ev
          T _ZNSt16nested_exceptionD0Ev
          T _ZNSt16nested_exceptionD1Ev
          T _ZNSt16nested_exceptionD2Ev
+         C _ZNSt3__110__find_endIPFbwwEPKwS4_EET0_S5_S5_T1_S6_T_NS_26random_access_iterator_tagES8_
          C _ZNSt3__110__sscanf_lEPKcP15__locale_structS1_z
          C _ZNSt3__110__stdinbufIcE5imbueERKNS_6localeE
          C _ZNSt3__110__stdinbufIcE5uflowEv
@@ -887,14 +856,18 @@
          C _ZNSt3__111__stdoutbufIcE5imbueERKNS_6localeE
          C _ZNSt3__111__stdoutbufIcE6xsputnEPKci
          C _ZNSt3__111__stdoutbufIcE8overflowEi
+         C _ZNSt3__111__stdoutbufIcEC2EP8_IO_FILEP11__mbstate_t
          C _ZNSt3__111__stdoutbufIcED0Ev
          C _ZNSt3__111__stdoutbufIcED1Ev
          C _ZNSt3__111__stdoutbufIwE4syncEv
          C _ZNSt3__111__stdoutbufIwE5imbueERKNS_6localeE
          C _ZNSt3__111__stdoutbufIwE6xsputnEPKwi
          C _ZNSt3__111__stdoutbufIwE8overflowEj
+         C _ZNSt3__111__stdoutbufIwEC2EP8_IO_FILEP11__mbstate_t
          C _ZNSt3__111__stdoutbufIwED0Ev
          C _ZNSt3__111__stdoutbufIwED1Ev
+         C _ZNSt3__111char_traitsIcE4findEPKcjRS2_
+         C _ZNSt3__111char_traitsIwE2eqEww
          T _ZNSt3__111regex_errorC1ENS_15regex_constants10error_typeE
          T _ZNSt3__111regex_errorC2ENS_15regex_constants10error_typeE
          T _ZNSt3__111regex_errorD0Ev
@@ -909,12 +882,15 @@
          T _ZNSt3__111timed_mutexD1Ev
          T _ZNSt3__111timed_mutexD2Ev
          D _ZNSt3__111try_to_lockE
+         C _ZNSt3__111unique_lockINS_5mutexEE6unlockEv
          C _ZNSt3__112__asprintf_lEPPcP15__locale_structPKcz
          C _ZNSt3__112__do_messageD0Ev
          C _ZNSt3__112__do_messageD1Ev
          T _ZNSt3__112__do_nothingEPv
          T _ZNSt3__112__get_sp_mutEPKv
          T _ZNSt3__112__next_primeEj
+         C _ZNSt3__112__rotate_gcdINS_11__wrap_iterIPcEEEET_S4_S4_S4_
+         C _ZNSt3__112__rotate_gcdINS_11__wrap_iterIPwEEEET_S4_S4_S4_
          D _ZNSt3__112__rs_default4__c_E
          T _ZNSt3__112__rs_defaultC1ERKS0_
          T _ZNSt3__112__rs_defaultC1Ev
@@ -967,6 +943,7 @@
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcjj
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEjc
+         C _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__zeroEv
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcj
@@ -1005,6 +982,7 @@
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7replaceEjjRKS5_
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7replaceEjjRKS5_jj
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7replaceEjjjc
+         C _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7replaceIPKcEENS_9enable_ifIXsr19__is_input_iteratorIT_EE5valueERS5_E4typeENS_11__wrap_iterIS8_EESF_SA_SA_
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEj
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE8pop_backEv
          W _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj
@@ -1091,6 +1069,7 @@
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEPKwj
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEPKwjj
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEjw
+         C _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initIPKwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__zeroEv
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6appendEPKw
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6appendEPKwj
@@ -1130,6 +1109,7 @@
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE7replaceEjjRKS5_
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE7replaceEjjRKS5_jj
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE7replaceEjjjw
+         C _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE7replaceIPKwEENS_9enable_ifIXsr19__is_input_iteratorIT_EE5valueERS5_E4typeENS_11__wrap_iterIS8_EESF_SA_SA_
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE7reserveEj
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE8pop_backEv
          W _ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9__grow_byEjjjjjj
@@ -1192,6 +1172,7 @@
          T _ZNSt3__112ctype_bynameIwED2Ev
          T _ZNSt3__112future_errorC1ENS_10error_codeE
          T _ZNSt3__112future_errorC2ENS_10error_codeE
+         C _ZNSt3__112future_errorC2ERKS0_
          T _ZNSt3__112future_errorD0Ev
          T _ZNSt3__112future_errorD1Ev
          T _ZNSt3__112future_errorD2Ev
@@ -1249,6 +1230,10 @@
          T _ZNSt3__112system_errorD0Ev
          T _ZNSt3__112system_errorD1Ev
          T _ZNSt3__112system_errorD2Ev
+         C _ZNSt3__113__lower_boundIRNS_6__lessIjjEEPKjjEET0_S6_S6_RKT1_T_
+         C _ZNSt3__113__vector_baseINS_4pairIPNS_18condition_variableEPNS_5mutexEEENS_18__hidden_allocatorIS6_EEED2Ev
+         C _ZNSt3__113__vector_baseIPNS_17__assoc_sub_stateENS_18__hidden_allocatorIS2_EEED2Ev
+         C _ZNSt3__113__vector_baseIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEED2Ev
          D _ZNSt3__113allocator_argE
          W _ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getEPci
          W _ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getEPcic
@@ -1447,6 +1432,13 @@
          T _ZNSt3__114__shared_countD0Ev
          T _ZNSt3__114__shared_countD1Ev
          T _ZNSt3__114__shared_countD2Ev
+         C _ZNSt3__114__split_bufferINS_4pairIPNS_18condition_variableEPNS_5mutexEEERNS_18__hidden_allocatorIS6_EEEC2EjjS9_
+         C _ZNSt3__114__split_bufferINS_4pairIPNS_18condition_variableEPNS_5mutexEEERNS_18__hidden_allocatorIS6_EEED2Ev
+         C _ZNSt3__114__split_bufferIPNS_17__assoc_sub_stateERNS_18__hidden_allocatorIS2_EEEC2EjjS5_
+         C _ZNSt3__114__split_bufferIPNS_17__assoc_sub_stateERNS_18__hidden_allocatorIS2_EEED2Ev
+         C _ZNSt3__114__split_bufferIPNS_6locale5facetERNS_15__sso_allocatorIS3_Lj28EEEE18__construct_at_endEj
+         C _ZNSt3__114__split_bufferIPNS_6locale5facetERNS_15__sso_allocatorIS3_Lj28EEEEC2EjjS6_
+         C _ZNSt3__114__split_bufferIPNS_6locale5facetERNS_15__sso_allocatorIS3_Lj28EEEED2Ev
          W _ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEE4swapERS3_
          W _ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEEC1EOS3_
          W _ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEEC1EPNS_15basic_streambufIcS2_EE
@@ -1524,8 +1516,12 @@
          T _ZNSt3__115__thread_structC2Ev
          T _ZNSt3__115__thread_structD1Ev
          T _ZNSt3__115__thread_structD2Ev
+         C _ZNSt3__115__time_get_tempIcEC2EPKc
+         C _ZNSt3__115__time_get_tempIcEC2ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
          C _ZNSt3__115__time_get_tempIcED0Ev
          C _ZNSt3__115__time_get_tempIcED1Ev
+         C _ZNSt3__115__time_get_tempIwEC2EPKc
+         C _ZNSt3__115__time_get_tempIwEC2ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
          C _ZNSt3__115__time_get_tempIwED0Ev
          C _ZNSt3__115__time_get_tempIwED1Ev
          W _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE10pubseekoffExNS_8ios_base7seekdirEj
@@ -1695,6 +1691,7 @@
          T _ZNSt3__117__assoc_sub_state9set_valueEv
          C _ZNSt3__117__assoc_sub_stateD0Ev
          C _ZNSt3__117__assoc_sub_stateD1Ev
+         C _ZNSt3__117__assoc_sub_stateD2Ev
          T _ZNSt3__117__widen_from_utf8ILj16EED0Ev
          T _ZNSt3__117__widen_from_utf8ILj16EED1Ev
          T _ZNSt3__117__widen_from_utf8ILj16EED2Ev
@@ -1735,6 +1732,23 @@
          W _ZNSt3__117moneypunct_bynameIwLb1EED0Ev
          W _ZNSt3__117moneypunct_bynameIwLb1EED1Ev
          W _ZNSt3__117moneypunct_bynameIwLb1EED2Ev
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIaaEEPaEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIccEEPcEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIddEEPdEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIeeEEPeEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIffEEPfEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIhhEEPhEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIiiEEPiEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIjjEEPjEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIllEEPlEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessImmEEPmEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIssEEPsEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIttEEPtEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIwwEEPwEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIxxEEPxEEvT0_S5_T_
+         C _ZNSt3__118__insertion_sort_3IRNS_6__lessIyyEEPyEEvT0_S5_T_
+         C _ZNSt3__118__libcpp_refstringC2EPKc
+         C _ZNSt3__118__libcpp_refstringaSERKS0_
          T _ZNSt3__118__time_get_storageIcE4initERKNS_5ctypeIcEE
          T _ZNSt3__118__time_get_storageIcE9__analyzeEcRKNS_5ctypeIcEE
          T _ZNSt3__118__time_get_storageIcEC1EPKc
@@ -1754,6 +1768,8 @@
          T _ZNSt3__118condition_variableD1Ev
          T _ZNSt3__118condition_variableD2Ev
          T _ZNSt3__118get_pointer_safetyEv
+         C _ZNSt3__119__double_or_nothingIcEEvRNS_10unique_ptrIT_PFvPvEEERPS2_S9_
+         C _ZNSt3__119__double_or_nothingIjEEvRNS_10unique_ptrIT_PFvPvEEERPS2_S9_
          C _ZNSt3__119__double_or_nothingIwEEvRNS_10unique_ptrIT_PFvPvEEERPS2_S9_
          C _ZNSt3__119__iostream_categoryD0Ev
          C _ZNSt3__119__iostream_categoryD1Ev
@@ -1783,11 +1799,15 @@
          C _ZNSt3__120__get_up_to_n_digitsIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEiRT0_S5_RjRKNS_5ctypeIT_EEi
          C _ZNSt3__120__get_up_to_n_digitsIcPcEEiRT0_S2_RjRKNS_5ctypeIT_EEi
          C _ZNSt3__120__get_up_to_n_digitsIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEiRT0_S5_RjRKNS_5ctypeIT_EEi
+         C _ZNSt3__120__get_up_to_n_digitsIwPwEEiRT0_S2_RjRKNS_5ctypeIT_EEi
          T _ZNSt3__120__throw_system_errorEiPKc
          W _ZNSt3__120__vector_base_commonILb1EEC1Ev
          W _ZNSt3__120__vector_base_commonILb1EEC2Ev
+         C _ZNSt3__121__murmur2_or_cityhashIjLj32EEclEPKvj
          C _ZNSt3__121__thread_specific_ptrINS_15__thread_structEE16__at_thread_exitEPv
+         C _ZNSt3__121__thread_specific_ptrINS_15__thread_structEEC2Ev
          C _ZNSt3__121__thread_specific_ptrINS_15__thread_structEED1Ev
+         C _ZNSt3__121__thread_specific_ptrINS_15__thread_structEED2Ev
          T _ZNSt3__121__throw_runtime_errorEPKc
          T _ZNSt3__121__undeclare_reachableEPv
          T _ZNSt3__121recursive_timed_mutex4lockEv
@@ -1802,6 +1822,8 @@
          C _ZNSt3__123__future_error_categoryD1Ev
          C _ZNSt3__123__system_error_categoryD0Ev
          C _ZNSt3__123__system_error_categoryD1Ev
+         C _ZNSt3__123mersenne_twister_engineIjLj32ELj624ELj397ELj31ELj2567483615ELj11ELj4294967295ELj7ELj2636928640ELj15ELj4022730752ELj18ELj1812433253EE4seedEj
+         C _ZNSt3__123mersenne_twister_engineIjLj32ELj624ELj397ELj31ELj2567483615ELj11ELj4294967295ELj7ELj2636928640ELj15ELj4022730752ELj18ELj1812433253EEclEv
          C _ZNSt3__124__generic_error_categoryD0Ev
          C _ZNSt3__124__generic_error_categoryD1Ev
          C _ZNSt3__125__num_get_signed_integralIlEET_PKcS3_Rji
@@ -1903,8 +1925,84 @@
          D _ZNSt3__16locale4noneE
          D _ZNSt3__16locale4timeE
          T _ZNSt3__16locale5__imp11make_globalEv
+         C _ZNSt3__16locale5__imp12install_fromINS_10moneypunctIcLb0EEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_10moneypunctIcLb1EEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_10moneypunctIwLb0EEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_10moneypunctIwLb1EEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_5ctypeIcEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_5ctypeIwEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7codecvtIDic11__mbstate_tEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7codecvtIDsc11__mbstate_tEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7codecvtIcc11__mbstate_tEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7codecvtIwc11__mbstate_tEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7collateIcEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7collateIwEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7num_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7num_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7num_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_7num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8messagesIcEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8messagesIwEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8numpunctIcEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8numpunctIwEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8time_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8time_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8time_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_8time_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_9money_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_9money_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_9money_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvRKS1_
+         C _ZNSt3__16locale5__imp12install_fromINS_9money_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvRKS1_
          T _ZNSt3__16locale5__imp12make_classicEv
          T _ZNSt3__16locale5__imp7installEPNS0_5facetEl
+         C _ZNSt3__16locale5__imp7installINS_10moneypunctIcLb0EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_10moneypunctIcLb1EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_10moneypunctIwLb0EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_10moneypunctIwLb1EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_12ctype_bynameIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_12ctype_bynameIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14codecvt_bynameIDic11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14codecvt_bynameIDsc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14codecvt_bynameIcc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14codecvt_bynameIwc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14collate_bynameIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_14collate_bynameIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15messages_bynameIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15messages_bynameIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15numpunct_bynameIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15numpunct_bynameIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15time_get_bynameIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15time_get_bynameIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15time_put_bynameIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_15time_put_bynameIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_17moneypunct_bynameIcLb0EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_17moneypunct_bynameIcLb1EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_17moneypunct_bynameIwLb0EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_17moneypunct_bynameIwLb1EEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_5ctypeIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_5ctypeIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7codecvtIDic11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7codecvtIDsc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7codecvtIcc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7codecvtIwc11__mbstate_tEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7collateIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7collateIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7num_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7num_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7num_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_7num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8messagesIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8messagesIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8numpunctIcEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8numpunctIwEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8time_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8time_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8time_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_8time_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_9money_getIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_9money_getIwNS_19istreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_9money_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEEEEvPT_
+         C _ZNSt3__16locale5__imp7installINS_9money_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEEEEvPT_
          T _ZNSt3__16locale5__impC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEj
          T _ZNSt3__16locale5__impC1ERKS1_
          T _ZNSt3__16locale5__impC1ERKS1_PNS0_5facetEl
@@ -1957,10 +2055,48 @@
          T _ZNSt3__16threadD1Ev
          T _ZNSt3__16threadD2Ev
          C _ZNSt3__16vectorINS_4pairIPNS_18condition_variableEPNS_5mutexEEENS_18__hidden_allocatorIS6_EEE21__push_back_slow_pathIS6_EEvOT_
+         C _ZNSt3__16vectorINS_4pairIPNS_18condition_variableEPNS_5mutexEEENS_18__hidden_allocatorIS6_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS6_RS8_EE
          C _ZNSt3__16vectorIPNS_17__assoc_sub_stateENS_18__hidden_allocatorIS2_EEE21__push_back_slow_pathIRKS2_EEvOT_
+         C _ZNSt3__16vectorIPNS_17__assoc_sub_stateENS_18__hidden_allocatorIS2_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS2_RS4_EE
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE10deallocateEv
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE18__construct_at_endEj
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE18__construct_at_endIPS3_EENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE26__swap_out_circular_bufferERNS_14__split_bufferIS3_RS5_EE
          C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE6assignIPS3_EENS_9enable_ifIXaasr21__is_forward_iteratorIT_EE5valuesr16is_constructibleIS3_NS_15iterator_traitsISA_E9referenceEEE5valueEvE4typeESA_SA_
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE6resizeEj
          C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE8__appendEj
+         C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEE8allocateEj
          C _ZNSt3__16vectorIPNS_6locale5facetENS_15__sso_allocatorIS3_Lj28EEEEC2Ej
+         C _ZNSt3__17__sort3IRNS_6__lessIaaEEPaEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIccEEPcEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIddEEPdEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIeeEEPeEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIffEEPfEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIhhEEPhEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIiiEEPiEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIjjEEPjEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIllEEPlEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessImmEEPmEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIssEEPsEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIttEEPtEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIwwEEPwEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIxxEEPxEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort3IRNS_6__lessIyyEEPyEEjT0_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIaaEEPaEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIccEEPcEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIddEEPdEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIeeEEPeEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIffEEPfEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIhhEEPhEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIiiEEPiEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIjjEEPjEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIllEEPlEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessImmEEPmEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIssEEPsEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIttEEPtEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIwwEEPwEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIxxEEPxEEjT0_S5_S5_S5_T_
+         C _ZNSt3__17__sort4IRNS_6__lessIyyEEPyEEjT0_S5_S5_S5_T_
          C _ZNSt3__17__sort5IRNS_6__lessIaaEEPaEEjT0_S5_S5_S5_S5_T_
          C _ZNSt3__17__sort5IRNS_6__lessIccEEPcEEjT0_S5_S5_S5_S5_T_
          C _ZNSt3__17__sort5IRNS_6__lessIddEEPdEEjT0_S5_S5_S5_S5_T_
@@ -2050,6 +2186,7 @@
          T _ZNSt3__18__i_nodeD1Ev
          T _ZNSt3__18__i_nodeD2Ev
          T _ZNSt3__18__rs_getEv
+         C _ZNSt3__18__searchIPFbwwEPKwS4_EET0_S5_S5_T1_S6_T_NS_26random_access_iterator_tagES8_
          T _ZNSt3__18__sp_mut4lockEv
          T _ZNSt3__18__sp_mut6unlockEv
          D _ZNSt3__18ios_base10floatfieldE
@@ -2261,13 +2398,10 @@
          T _ZNSt3__19to_stringEx
          T _ZNSt3__19to_stringEy
          W _ZNSt3__1plIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_12basic_stringIT_T0_T1_EEPKS6_RKS9_
-         T _ZSt10unexpectedv
-         T _ZSt13get_terminatev
-         T _ZSt13set_terminatePFvvE
-         T _ZSt14get_unexpectedv
-         T _ZSt14set_unexpectedPFvvE
+         C _ZNSt3__1plIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_12basic_stringIT_T0_T1_EERKS9_PKS6_
          T _ZSt17current_exceptionv
          T _ZSt17rethrow_exceptionSt13exception_ptr
+         C _ZSt18make_exception_ptrINSt3__112future_errorEESt13exception_ptrT_
          D _ZTCNSt3__110istrstreamE0_NS_13basic_istreamIcNS_11char_traitsIcEEEE
          D _ZTCNSt3__110ostrstreamE0_NS_13basic_ostreamIcNS_11char_traitsIcEEEE
          W _ZTCNSt3__114basic_iostreamIcNS_11char_traitsIcEEEE0_NS_13basic_istreamIcS2_EE
@@ -2397,16 +2531,6 @@
          W _ZTINSt3__19money_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEE
          D _ZTINSt3__19strstreamE
          C _ZTINSt3__19time_baseE
-         D _ZTISt11logic_error
-         D _ZTISt11range_error
-         D _ZTISt12domain_error
-         D _ZTISt12length_error
-         D _ZTISt12out_of_range
-         D _ZTISt13bad_exception
-         D _ZTISt13runtime_error
-         D _ZTISt14overflow_error
-         D _ZTISt15underflow_error
-         D _ZTISt16invalid_argument
          D _ZTISt16nested_exception
          C _ZTSNSt3__110__stdinbufIcEE
          C _ZTSNSt3__110__stdinbufIwEE
@@ -2530,16 +2654,6 @@
          W _ZTSNSt3__19money_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEE
          D _ZTSNSt3__19strstreamE
          C _ZTSNSt3__19time_baseE
-         D _ZTSSt11logic_error
-         D _ZTSSt11range_error
-         D _ZTSSt12domain_error
-         D _ZTSSt12length_error
-         D _ZTSSt12out_of_range
-         D _ZTSSt13bad_exception
-         D _ZTSSt13runtime_error
-         D _ZTSSt14overflow_error
-         D _ZTSSt15underflow_error
-         D _ZTSSt16invalid_argument
          D _ZTSSt16nested_exception
          D _ZTTNSt3__110istrstreamE
          D _ZTTNSt3__110ostrstreamE
@@ -2650,16 +2764,6 @@
          W _ZTVNSt3__19money_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEEE
          W _ZTVNSt3__19money_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEEE
          D _ZTVNSt3__19strstreamE
-         D _ZTVSt11logic_error
-         D _ZTVSt11range_error
-         D _ZTVSt12domain_error
-         D _ZTVSt12length_error
-         D _ZTVSt12out_of_range
-         D _ZTVSt13bad_exception
-         D _ZTVSt13runtime_error
-         D _ZTVSt14overflow_error
-         D _ZTVSt15underflow_error
-         D _ZTVSt16invalid_argument
          D _ZTVSt16nested_exception
          W _ZThn8_NKSt3__115time_get_bynameIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEE3__XEv
          W _ZThn8_NKSt3__115time_get_bynameIcNS_19istreambuf_iteratorIcNS_11char_traitsIcEEEEE3__cEv
@@ -2695,3 +2799,4 @@
          W _ZTv0_n12_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED1Ev
          T _ZTv0_n12_NSt3__19strstreamD0Ev
          T _ZTv0_n12_NSt3__19strstreamD1Ev
+         C __clang_call_terminate
diff --git a/system/lib/libcxx/system_error.cpp b/system/lib/libcxx/system_error.cpp
index b40409f854ab9..9c8adc4f323e4 100644
--- a/system/lib/libcxx/system_error.cpp
+++ b/system/lib/libcxx/system_error.cpp
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define	_LIBCPP_BUILDING_SYSTEM_ERROR
+#define _LIBCPP_BUILDING_SYSTEM_ERROR
+#include "__config"
 #include "system_error"
 #include "string"
 #include "cstring"
@@ -65,10 +66,10 @@ __generic_error_category::name() const _NOEXCEPT
 string
 __generic_error_category::message(int ev) const
 {
-#ifdef ELAST
-    if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+    if (ev > _LIBCPP_ELAST)
       return string("unspecified generic_category error");
-#endif  // ELAST
+#endif  // _LIBCPP_ELAST
     return __do_message::message(ev);
 }
 
@@ -97,20 +98,20 @@ __system_error_category::name() const _NOEXCEPT
 string
 __system_error_category::message(int ev) const
 {
-#ifdef ELAST
-    if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+    if (ev > _LIBCPP_ELAST)
       return string("unspecified system_category error");
-#endif  // ELAST
+#endif  // _LIBCPP_ELAST
     return __do_message::message(ev);
 }
 
 error_condition
 __system_error_category::default_error_condition(int ev) const _NOEXCEPT
 {
-#ifdef ELAST
-    if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+    if (ev > _LIBCPP_ELAST)
       return error_condition(ev, system_category());
-#endif  // ELAST
+#endif  // _LIBCPP_ELAST
     return error_condition(ev, generic_category());
 }
 
diff --git a/system/lib/libcxx/thread.cpp b/system/lib/libcxx/thread.cpp
index 338a8a24cef56..0ced1e3bba1e4 100644
--- a/system/lib/libcxx/thread.cpp
+++ b/system/lib/libcxx/thread.cpp
@@ -7,6 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "__config"
+#ifndef _LIBCPP_HAS_NO_THREADS
+
 #include "thread"
 #include "exception"
 #include "vector"
@@ -121,7 +124,9 @@ sleep_for(const chrono::nanoseconds& ns)
             ts.tv_sec = ts_sec_max;
             ts.tv_nsec = giga::num - 1;
         }
-        nanosleep(&ts, 0);
+
+        while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
+            ;
     }
 }
 
@@ -144,7 +149,7 @@ class _LIBCPP_HIDDEN __hidden_allocator
     
     T* allocate(size_t __n)
         {return static_cast<T*>(::operator new(__n * sizeof(T)));}
-    void deallocate(T* __p, size_t) {::operator delete((void*)__p);}
+    void deallocate(T* __p, size_t) {::operator delete(static_cast<void*>(__p));}
 
     size_t max_size() const {return size_t(~0) / sizeof(T);}
 };
@@ -223,3 +228,5 @@ __thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s)
 }
 
 _LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/system/lib/libcxx/valarray.cpp b/system/lib/libcxx/valarray.cpp
index e4c9ed024620c..2d8db52ac36b2 100644
--- a/system/lib/libcxx/valarray.cpp
+++ b/system/lib/libcxx/valarray.cpp
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
 #include "valarray"
 
 _LIBCPP_BEGIN_NAMESPACE_STD