[Midnightbsd-cvs] src [7405] trunk/contrib/libc++: update libc++

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu Jan 7 12:24:15 EST 2016


Revision: 7405
          http://svnweb.midnightbsd.org/src/?rev=7405
Author:   laffer1
Date:     2016-01-07 12:22:14 -0500 (Thu, 07 Jan 2016)
Log Message:
-----------
update libc++

Modified Paths:
--------------
    trunk/contrib/libc++/include/__bit_reference
    trunk/contrib/libc++/include/__config
    trunk/contrib/libc++/include/__debug
    trunk/contrib/libc++/include/__functional_03
    trunk/contrib/libc++/include/__functional_base
    trunk/contrib/libc++/include/__functional_base_03
    trunk/contrib/libc++/include/__hash_table
    trunk/contrib/libc++/include/__locale
    trunk/contrib/libc++/include/__mutex_base
    trunk/contrib/libc++/include/__split_buffer
    trunk/contrib/libc++/include/__std_stream
    trunk/contrib/libc++/include/__tree
    trunk/contrib/libc++/include/__tuple
    trunk/contrib/libc++/include/__tuple_03
    trunk/contrib/libc++/include/__undef_min_max
    trunk/contrib/libc++/include/algorithm
    trunk/contrib/libc++/include/array
    trunk/contrib/libc++/include/atomic
    trunk/contrib/libc++/include/bitset
    trunk/contrib/libc++/include/chrono
    trunk/contrib/libc++/include/cmath
    trunk/contrib/libc++/include/codecvt
    trunk/contrib/libc++/include/complex
    trunk/contrib/libc++/include/condition_variable
    trunk/contrib/libc++/include/cstddef
    trunk/contrib/libc++/include/cstdio
    trunk/contrib/libc++/include/cstdlib
    trunk/contrib/libc++/include/cstring
    trunk/contrib/libc++/include/cwchar
    trunk/contrib/libc++/include/deque
    trunk/contrib/libc++/include/exception
    trunk/contrib/libc++/include/ext/__hash
    trunk/contrib/libc++/include/ext/hash_map
    trunk/contrib/libc++/include/ext/hash_set
    trunk/contrib/libc++/include/forward_list
    trunk/contrib/libc++/include/fstream
    trunk/contrib/libc++/include/functional
    trunk/contrib/libc++/include/future
    trunk/contrib/libc++/include/initializer_list
    trunk/contrib/libc++/include/ios
    trunk/contrib/libc++/include/iosfwd
    trunk/contrib/libc++/include/iostream
    trunk/contrib/libc++/include/istream
    trunk/contrib/libc++/include/iterator
    trunk/contrib/libc++/include/limits
    trunk/contrib/libc++/include/list
    trunk/contrib/libc++/include/locale
    trunk/contrib/libc++/include/map
    trunk/contrib/libc++/include/memory
    trunk/contrib/libc++/include/mutex
    trunk/contrib/libc++/include/new
    trunk/contrib/libc++/include/ostream
    trunk/contrib/libc++/include/queue
    trunk/contrib/libc++/include/random
    trunk/contrib/libc++/include/ratio
    trunk/contrib/libc++/include/regex
    trunk/contrib/libc++/include/scoped_allocator
    trunk/contrib/libc++/include/set
    trunk/contrib/libc++/include/sstream
    trunk/contrib/libc++/include/stack
    trunk/contrib/libc++/include/streambuf
    trunk/contrib/libc++/include/string
    trunk/contrib/libc++/include/strstream
    trunk/contrib/libc++/include/system_error
    trunk/contrib/libc++/include/thread
    trunk/contrib/libc++/include/tuple
    trunk/contrib/libc++/include/type_traits
    trunk/contrib/libc++/include/typeindex
    trunk/contrib/libc++/include/unordered_map
    trunk/contrib/libc++/include/unordered_set
    trunk/contrib/libc++/include/utility
    trunk/contrib/libc++/include/valarray
    trunk/contrib/libc++/include/vector
    trunk/contrib/libc++/src/chrono.cpp
    trunk/contrib/libc++/src/condition_variable.cpp
    trunk/contrib/libc++/src/debug.cpp
    trunk/contrib/libc++/src/exception.cpp
    trunk/contrib/libc++/src/future.cpp
    trunk/contrib/libc++/src/hash.cpp
    trunk/contrib/libc++/src/ios.cpp
    trunk/contrib/libc++/src/iostream.cpp
    trunk/contrib/libc++/src/locale.cpp
    trunk/contrib/libc++/src/memory.cpp
    trunk/contrib/libc++/src/mutex.cpp
    trunk/contrib/libc++/src/new.cpp
    trunk/contrib/libc++/src/random.cpp
    trunk/contrib/libc++/src/stdexcept.cpp
    trunk/contrib/libc++/src/string.cpp
    trunk/contrib/libc++/src/strstream.cpp
    trunk/contrib/libc++/src/system_error.cpp
    trunk/contrib/libc++/src/thread.cpp
    trunk/contrib/libc++/src/typeinfo.cpp

Added Paths:
-----------
    trunk/contrib/libc++/CREDITS.TXT
    trunk/contrib/libc++/LICENSE.TXT
    trunk/contrib/libc++/MIDNIGHTBSD-upgrade

Removed Paths:
-------------
    trunk/contrib/libc++/FREEBSD-upgrade
    trunk/contrib/libc++/src/support/

Added: trunk/contrib/libc++/CREDITS.TXT
===================================================================
--- trunk/contrib/libc++/CREDITS.TXT	                        (rev 0)
+++ trunk/contrib/libc++/CREDITS.TXT	2016-01-07 17:22:14 UTC (rev 7405)
@@ -0,0 +1,95 @@
+This file is a partial list of people who have contributed to the LLVM/libc++
+project.  If you have contributed a patch or made some other contribution to
+LLVM/libc++, please submit a patch to this file to add yourself, and it will be
+done!
+
+The list is sorted by surname and formatted to allow easy grepping and
+beautification by scripts.  The fields are: name (N), email (E), web-address
+(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
+(S).
+
+N: Saleem Abdulrasool
+E: compnerd at compnerd.org
+D: Minor patches and Linux fixes.
+
+N: Dimitry Andric
+E: dimitry at andric.com
+D: Visibility fixes, minor FreeBSD portability patches.
+
+N: Holger Arnold
+E: holgerar at gmail.com
+D: Minor fix.
+
+N: Ruben Van Boxem
+E: vanboxem dot ruben at gmail dot com
+D: Initial Windows patches.
+
+N: David Chisnall
+E: theraven at theravensnest dot org
+D: FreeBSD and Solaris ports, libcxxrt support, some atomics work.
+
+N: Marshall Clow
+E: mclow.lists at gmail.com
+E: marshall at idio.com
+D: Minor patches and bug fixes.
+
+N: Google Inc.
+D: Copyright owner and contributor of the CityHash algorithm
+
+N: Howard Hinnant
+E: hhinnant at apple.com
+D: Architect and primary author of libc++
+
+N: Hyeon-bin Jeong
+E: tuhertz at gmail.com
+D: Minor patches and bug fixes.
+
+N: Argyrios Kyrtzidis
+E: kyrtzidis at apple.com
+D: Bug fixes.
+
+N: Michel Morin
+E: mimomorin at gmail.com
+D: Minor patches to is_convertible.
+
+N: Andrew Morrow
+E: andrew.c.morrow at gmail.com
+D: Minor patches and Linux fixes.
+
+N: Arvid Picciani
+E: aep at exys dot org
+D: Minor patches and musl port.
+
+N: Bjorn Reese
+E: breese at users.sourceforge.net
+D: Initial regex prototype
+
+N: Jonathan Sauer
+D: Minor patches, mostly related to constexpr
+
+N: Craig Silverstein
+E: csilvers at google.com
+D: Implemented Cityhash as the string hash function on 64-bit machines
+
+N: Richard Smith
+D: Minor patches.
+
+N: Michael van der Westhuizen
+E: r1mikey at gmail dot com
+
+N: Klaas de Vries
+E: klaas at klaasgaaf dot nl
+D: Minor bug fix.
+
+N: Zhang Xiongpang
+E: zhangxiongpang at gmail.com
+D: Minor patches and bug fixes.
+
+N: Jeffrey Yasskin
+E: jyasskin at gmail.com
+E: jyasskin at google.com
+D: Linux fixes.
+
+N: Bruce Mitchener, Jr.
+E: bruce.mitchener at gmail.com
+D: Emscripten-related changes.


Property changes on: trunk/contrib/libc++/CREDITS.TXT
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Deleted: trunk/contrib/libc++/FREEBSD-upgrade
===================================================================
--- trunk/contrib/libc++/FREEBSD-upgrade	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/FREEBSD-upgrade	2016-01-07 17:22:14 UTC (rev 7405)
@@ -1,8 +0,0 @@
-$FreeBSD$
-
-The FreeBSD copy of libc++.  This contains everything from the include and 
-source directories upstream, with the exception of the support/win32 directory, 
-which is only required for building on Windows (FreeBSD is not Windows).
-
-To update, bring in anything new in source or include that is not
-platform-dependent (unless the platform in question is FreeBSD, obviously).

Added: trunk/contrib/libc++/LICENSE.TXT
===================================================================
--- trunk/contrib/libc++/LICENSE.TXT	                        (rev 0)
+++ trunk/contrib/libc++/LICENSE.TXT	2016-01-07 17:22:14 UTC (rev 7405)
@@ -0,0 +1,76 @@
+==============================================================================
+libc++ License
+==============================================================================
+
+The libc++ library is dual licensed under both the University of Illinois
+"BSD-Like" license and the MIT license.  As a user of this code you may choose
+to use it under either license.  As a contributor, you agree to allow your code
+to be used under both.
+
+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
+
+All rights reserved.
+
+Developed by:
+
+    LLVM Team
+
+    University of Illinois at Urbana-Champaign
+
+    http://llvm.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal with
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimers.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimers in the
+      documentation and/or other materials provided with the distribution.
+
+    * Neither the names of the LLVM Team, University of Illinois at
+      Urbana-Champaign, nor the names of its contributors may be used to
+      endorse or promote products derived from this Software without specific
+      prior written permission.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+SOFTWARE.
+
+==============================================================================
+
+Copyright (c) 2009-2013 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
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.


Property changes on: trunk/contrib/libc++/LICENSE.TXT
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Copied: trunk/contrib/libc++/MIDNIGHTBSD-upgrade (from rev 7403, trunk/contrib/libc++/FREEBSD-upgrade)
===================================================================
--- trunk/contrib/libc++/MIDNIGHTBSD-upgrade	                        (rev 0)
+++ trunk/contrib/libc++/MIDNIGHTBSD-upgrade	2016-01-07 17:22:14 UTC (rev 7405)
@@ -0,0 +1,6 @@
+# $MidnightBSD$
+
+The BSD copy of libc++.  
+
+Includes: include and src directories.
+Excludes: support/win32 code

Modified: trunk/contrib/libc++/include/__bit_reference
===================================================================
--- trunk/contrib/libc++/include/__bit_reference	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__bit_reference	2016-01-07 17:22:14 UTC (rev 7405)
@@ -22,7 +22,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Cp, bool _IsConst> class __bit_iterator;
+template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
 template <class _Cp> class __bit_const_reference;
 
 template <class _Tp>
@@ -81,6 +81,16 @@
 {
 };
 
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
 template <class _Cp, class _Dp>
 _LIBCPP_INLINE_VISIBILITY inline
 void
@@ -131,7 +141,7 @@
     __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
         : __seg_(__x.__seg_), __mask_(__x.__mask_) {}
 
-    _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
         {return static_cast<bool>(*__seg_ & __mask_);}
 
     _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
@@ -138,6 +148,7 @@
         {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
 private:
     _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR
     __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
         : __seg_(__s), __mask_(__m) {}
 
@@ -146,11 +157,11 @@
 
 // find
 
-template <class _Cp>
-__bit_iterator<_Cp, false>
-__find_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
     // do first partial word
@@ -180,11 +191,11 @@
     return _It(__first.__seg_, static_cast<unsigned>(__n));
 }
 
-template <class _Cp>
-__bit_iterator<_Cp, false>
-__find_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
     // do first partial word
@@ -193,7 +204,7 @@
         __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
         __storage_type __dn = _VSTD::min(__clz_f, __n);
         __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
-        __storage_type __b = ~(*__first.__seg_ & __m);
+        __storage_type __b = ~*__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         __n -= __dn;
@@ -210,7 +221,7 @@
     if (__n > 0)
     {
         __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
-        __storage_type __b = ~(*__first.__seg_ & __m);
+        __storage_type __b = ~*__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
     }
@@ -217,10 +228,10 @@
     return _It(__first.__seg_, static_cast<unsigned>(__n));
 }
 
-template <class _Cp, class _Tp>
+template <class _Cp, bool _IsConst, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-__bit_iterator<_Cp, false>
-find(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
+__bit_iterator<_Cp, _IsConst>
+find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
 {
     if (static_cast<bool>(__value_))
         return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
@@ -229,11 +240,11 @@
 
 // count
 
-template <class _Cp>
-typename __bit_iterator<_Cp, false>::difference_type
-__count_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     typedef typename _It::difference_type difference_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -260,11 +271,11 @@
     return __r;
 }
 
-template <class _Cp>
-typename __bit_iterator<_Cp, false>::difference_type
-__count_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     typedef typename _It::difference_type difference_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -275,7 +286,7 @@
         __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
         __storage_type __dn = _VSTD::min(__clz_f, __n);
         __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
-        __r = _VSTD::__pop_count(~(*__first.__seg_ & __m));
+        __r = _VSTD::__pop_count(~*__first.__seg_ & __m);
         __n -= __dn;
         ++__first.__seg_;
     }
@@ -286,15 +297,15 @@
     if (__n > 0)
     {
         __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
-        __r += _VSTD::__pop_count(~(*__first.__seg_ & __m));
+        __r += _VSTD::__pop_count(~*__first.__seg_ & __m);
     }
     return __r;
 }
 
-template <class _Cp, class _Tp>
+template <class _Cp, bool _IsConst, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __bit_iterator<_Cp, false>::difference_type
-count(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
 {
     if (static_cast<bool>(__value_))
         return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
@@ -322,7 +333,7 @@
     }
     // do middle whole words
     __storage_type __nw = __n / __bits_per_word;
-    _VSTD::memset(__first.__seg_, 0, __nw * sizeof(__storage_type));
+    _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type));
     __n -= __nw * __bits_per_word;
     // do last partial word
     if (__n > 0)
@@ -352,7 +363,7 @@
     }
     // do middle whole words
     __storage_type __nw = __n / __bits_per_word;
-    _VSTD::memset(__first.__seg_, -1, __nw * sizeof(__storage_type));
+    _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type));
     __n -= __nw * __bits_per_word;
     // do last partial word
     if (__n > 0)
@@ -419,7 +430,9 @@
         // __first.__ctz_ == 0;
         // do middle words
         __storage_type __nw = __n / __bits_per_word;
-        _VSTD::memmove(__result.__seg_, __first.__seg_, __nw * sizeof(__storage_type));
+        _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
+                       _VSTD::__to_raw_pointer(__first.__seg_),
+                       __nw * sizeof(__storage_type));
         __n -= __nw * __bits_per_word;
         __result.__seg_ += __nw;
         // do last word
@@ -558,7 +571,9 @@
         __storage_type __nw = __n / __bits_per_word;
         __result.__seg_ -= __nw;
         __last.__seg_ -= __nw;
-        _VSTD::memmove(__result.__seg_, __last.__seg_, __nw * sizeof(__storage_type));
+        _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
+                       _VSTD::__to_raw_pointer(__last.__seg_),
+                       __nw * sizeof(__storage_type));
         __n -= __nw * __bits_per_word;
         // do last word
         if (__n > 0)
@@ -859,6 +874,7 @@
 {
     typedef typename _Cp::difference_type difference_type;
     typedef typename _Cp::__storage_type  __storage_type;
+    typedef typename _Cp::__storage_pointer __storage_pointer;
     typedef typename _Cp::iterator        iterator;
     static const unsigned __bits_per_word = _Cp::__bits_per_word;
     static const unsigned _Np = 4;
@@ -869,9 +885,15 @@
     _LIBCPP_INLINE_VISIBILITY static difference_type capacity()
         {return static_cast<difference_type>(_Np * __bits_per_word);}
     _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
-    _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(__word_, 0);}
-    _LIBCPP_INLINE_VISIBILITY iterator end()   {return iterator(__word_ + __size_ / __bits_per_word,
-                                                  static_cast<unsigned>(__size_ % __bits_per_word));}
+    _LIBCPP_INLINE_VISIBILITY iterator begin()
+    {
+        return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
+    }
+    _LIBCPP_INLINE_VISIBILITY iterator end()
+    {
+        return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
+                                                  static_cast<unsigned>(__size_ % __bits_per_word));
+    }
 };
 
 template <class _Cp>
@@ -926,12 +948,12 @@
 
 // equal
 
-template <class _Cp>
+template <class _Cp, bool _IC1, bool _IC2>
 bool
-__equal_unaligned(__bit_iterator<_Cp, true> __first1, __bit_iterator<_Cp, true> __last1,
-                  __bit_iterator<_Cp, true> __first2)
+__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
+                  __bit_iterator<_Cp, _IC2> __first2)
 {
-    typedef __bit_iterator<_Cp, true> _It;
+    typedef __bit_iterator<_Cp, _IC1> _It;
     typedef  typename _It::difference_type difference_type;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -1008,12 +1030,12 @@
     return true;
 }
 
-template <class _Cp>
+template <class _Cp, bool _IC1, bool _IC2>
 bool
-__equal_aligned(__bit_iterator<_Cp, true> __first1, __bit_iterator<_Cp, true> __last1,
-                __bit_iterator<_Cp, true> __first2)
+__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
+                __bit_iterator<_Cp, _IC2> __first2)
 {
-    typedef __bit_iterator<_Cp, true> _It;
+    typedef __bit_iterator<_Cp, _IC1> _It;
     typedef  typename _It::difference_type difference_type;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -1061,7 +1083,8 @@
     return __equal_unaligned(__first1, __last1, __first2);
 }
 
-template <class _Cp, bool _IsConst>
+template <class _Cp, bool _IsConst,
+          typename _Cp::__storage_type>
 class __bit_iterator
 {
 public:
@@ -1232,19 +1255,23 @@
     template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
                                                                 __bit_iterator<_Dp, false>,
                                                                 __bit_iterator<_Dp, false>);
-    template <class _Dp> friend bool __equal_aligned(__bit_iterator<_Dp, true>,
-                                                    __bit_iterator<_Dp, true>,
-                                                    __bit_iterator<_Dp, true>);
-    template <class _Dp> friend bool __equal_unaligned(__bit_iterator<_Dp, true>,
-                                                      __bit_iterator<_Dp, true>,
-                                                      __bit_iterator<_Dp, true>);
+    template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
+                                                    __bit_iterator<_Dp, _IC1>,
+                                                    __bit_iterator<_Dp, _IC2>);
+    template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
+                                                      __bit_iterator<_Dp, _IC1>,
+                                                      __bit_iterator<_Dp, _IC2>);
     template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
                                                                 __bit_iterator<_Dp, _IC1>,
                                                                 __bit_iterator<_Dp, _IC2>);
-    template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_true(__bit_iterator<_Dp, false>,
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
                                                                           typename _Dp::size_type);
-    template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_false(__bit_iterator<_Dp, false>,
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
                                                                            typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
 };
 
 _LIBCPP_END_NAMESPACE_STD

Modified: trunk/contrib/libc++/include/__config
===================================================================
--- trunk/contrib/libc++/include/__config	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__config	2016-01-07 17:22:14 UTC (rev 7405)
@@ -11,12 +11,16 @@
 #ifndef _LIBCPP_CONFIG
 #define _LIBCPP_CONFIG
 
-#if !_MSC_VER // explicit macro necessary because it is only defined below in this file
+#ifndef _MSC_VER // explicit macro necessary because it is only defined below in this file
 #pragma GCC system_header
 #endif
 
-#define _LIBCPP_VERSION 1001
+#ifdef __GNUC__
+#define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
+#endif
 
+#define _LIBCPP_VERSION 1101
+
 #define _LIBCPP_ABI_VERSION 1
 
 #define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
@@ -47,17 +51,39 @@
 #   define _LIBCPP_LITTLE_ENDIAN 0
 #   define _LIBCPP_BIG_ENDIAN    1
 # endif  // _BYTE_ORDER == _LITTLE_ENDIAN
+# ifndef __LONG_LONG_SUPPORTED
+#  define _LIBCPP_HAS_NO_LONG_LONG
+# endif  // __LONG_LONG_SUPPORTED
 #endif  // __FreeBSD__
 
+#ifdef __NetBSD__
+# include <sys/endian.h>
+#  if _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 1
+#   define _LIBCPP_BIG_ENDIAN    0
+# else  // _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 0
+#   define _LIBCPP_BIG_ENDIAN    1
+# endif  // _BYTE_ORDER == _LITTLE_ENDIAN
+# define _LIBCPP_HAS_QUICK_EXIT
+#endif  // __NetBSD__
+
 #ifdef _WIN32
 #  define _LIBCPP_LITTLE_ENDIAN 1
 #  define _LIBCPP_BIG_ENDIAN    0
 // Compiler intrinsics (GCC or MSVC)
-#  if (defined(_MSC_VER) && _MSC_VER >= 1400) || (__GNUC__ >= 4 && __GNUC_MINOR__ > 3)
+#  if (defined(_MSC_VER) && _MSC_VER >= 1400) \
+   || (defined(__GNUC__) && _GNUC_VER > 403)
 #    define _LIBCP_HAS_IS_BASE_OF
 #  endif
 #endif  // _WIN32
 
+#ifdef __linux__
+#  if defined(__GNUC__) && _GNUC_VER >= 403
+#    define _LIBCP_HAS_IS_BASE_OF
+#  endif
+#endif
+
 #ifdef __sun__
 # include <sys/isa_defs.h>
 # ifdef _LITTLE_ENDIAN
@@ -82,24 +108,27 @@
 # endif
 #endif  // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
 
-#if _WIN32
+#ifdef _WIN32
 
 // only really useful for a DLL
 #ifdef _LIBCPP_DLL // this should be a compiler builtin define ideally...
 # ifdef cxx_EXPORTS
 #  define _LIBCPP_HIDDEN
-#  define _LIBCPP_VISIBLE __declspec(dllexport)
+#  define _LIBCPP_FUNC_VIS __declspec(dllexport)
+#  define _LIBCPP_TYPE_VIS __declspec(dllexport)
 # else
 #  define _LIBCPP_HIDDEN
-#  define _LIBCPP_VISIBLE __declspec(dllimport)
+#  define _LIBCPP_FUNC_VIS __declspec(dllimport)
+#  define _LIBCPP_TYPE_VIS __declspec(dllimport)
 # endif
 #else
 # define _LIBCPP_HIDDEN
-# define _LIBCPP_VISIBLE
+# define _LIBCPP_FUNC_VIS
+# define _LIBCPP_TYPE_VIS
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-# if _MSC_VER
+# ifdef _MSC_VER
 #  define _LIBCPP_INLINE_VISIBILITY __forceinline
 # else // MinGW GCC and Clang
 #  define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__))
@@ -107,11 +136,11 @@
 #endif
 
 #ifndef _LIBCPP_EXCEPTION_ABI
-#define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBLE
+#define _LIBCPP_EXCEPTION_ABI _LIBCPP_TYPE_VIS
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE
-# if _MSC_VER
+# ifdef _MSC_VER
 #  define _LIBCPP_ALWAYS_INLINE __forceinline
 # endif
 #endif
@@ -118,20 +147,32 @@
 
 #endif // _WIN32
 
+#ifndef __has_attribute
+#define __has_attribute(__x) 0
+#endif
+
 #ifndef _LIBCPP_HIDDEN
 #define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
 #endif
 
-#ifndef _LIBCPP_VISIBLE
-#define _LIBCPP_VISIBLE __attribute__ ((__visibility__("default")))
+#ifndef _LIBCPP_FUNC_VIS
+#define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
 #endif
 
+#ifndef _LIBCPP_TYPE_VIS
+#  if __has_attribute(type_visibility)
+#    define _LIBCPP_TYPE_VIS __attribute__ ((__type_visibility__("default")))
+#  else
+#    define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
+#  endif
+#endif
+
 #ifndef _LIBCPP_INLINE_VISIBILITY
 #define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
 #endif
 
 #ifndef _LIBCPP_EXCEPTION_ABI
-#define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
+#define _LIBCPP_EXCEPTION_ABI _LIBCPP_TYPE_VIS
 #endif
 
 #ifndef _LIBCPP_CANTTHROW
@@ -145,8 +186,10 @@
 #if defined(__clang__)
 
 #if __has_feature(cxx_alignas)
+#  define _ALIGNAS_TYPE(x) alignas(x)
 #  define _ALIGNAS(x) alignas(x)
 #else
+#  define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
 #  define _ALIGNAS(x) __attribute__((__aligned__(x)))
 #endif
 
@@ -180,12 +223,14 @@
 #endif
 
 #if __has_feature(cxx_attributes)
-#  define _ATTRIBUTE(x) [[x]]
+#  define _LIBCPP_NORETURN [[noreturn]]
 #else
-#  define _ATTRIBUTE(x) __attribute__ ((x))
+#  define _LIBCPP_NORETURN __attribute__ ((noreturn))
 #endif
 
+#if !(__has_feature(cxx_defaulted_functions))
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#endif  // !(__has_feature(cxx_defaulted_functions))
 
 #if !(__has_feature(cxx_deleted_functions))
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
@@ -245,9 +290,20 @@
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #endif
 
-#if __FreeBSD__
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
+#if defined(__FreeBSD__)
 #define _LIBCPP_HAS_QUICK_EXIT
+#define _LIBCPP_HAS_C11_FEATURES
+#elif defined(__linux__)
+#include <features.h>
+#if __GLIBC_PREREQ(2, 15)
+#define _LIBCPP_HAS_QUICK_EXIT
 #endif
+#if __GLIBC_PREREQ(2, 17)
+#define _LIBCPP_HAS_C11_FEATURES
+#endif
+#endif
+#endif
 
 #if (__has_feature(cxx_noexcept))
 #  define _NOEXCEPT noexcept
@@ -274,8 +330,9 @@
 #elif defined(__GNUC__)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
+#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
 
-#define _ATTRIBUTE(x) __attribute__((x))
+#define _LIBCPP_NORETURN __attribute__((noreturn))
 
 #if !__EXCEPTIONS
 #define _LIBCPP_NO_EXCEPTIONS
@@ -305,15 +362,15 @@
 #define _LIBCPP_HAS_NO_TRAILING_RETURN
 #define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
 
-#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+#if _GNUC_VER < 403
 #define _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #endif
 
-#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+#if _GNUC_VER < 403
 #define _LIBCPP_HAS_NO_STATIC_ASSERT
 #endif
 
-#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
+#if _GNUC_VER < 404
 #define _LIBCPP_HAS_NO_ADVANCED_SFINAE
 #define _LIBCPP_HAS_NO_DECLTYPE
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -321,9 +378,9 @@
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_VARIADICS
 #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-#endif  // !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
+#endif  // _GNUC_VER < 404
 
-#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
+#if _GNUC_VER < 406
 #define _LIBCPP_HAS_NO_NULLPTR
 #endif
 
@@ -347,7 +404,7 @@
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define __alignof__ __alignof
-#define _ATTRIBUTE __declspec
+#define _LIBCPP_NORETURN __declspec(noreturn)
 #define _ALIGNAS(x) __declspec(align(x))
 #define _LIBCPP_HAS_NO_VARIADICS
 
@@ -389,6 +446,18 @@
 #define _LIBCPP_CONSTEXPR constexpr
 #endif
 
+#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#define _LIBCPP_DEFAULT {}
+#else
+#define _LIBCPP_DEFAULT = default;
+#endif
+
+#ifdef __GNUC__
+#define _NOALIAS __attribute__((__malloc__))
+#else
+#define _NOALIAS
+#endif
+
 #ifndef __has_feature
 #define __has_feature(__x) 0
 #endif
@@ -400,29 +469,34 @@
 #endif
 
 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
-#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_VISIBLE x { enum _
+#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
 #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
-    _ __v_; \
-    _LIBCPP_ALWAYS_INLINE x(_ __v) : __v_(__v) {} \
+    __lx __v_; \
+    _LIBCPP_ALWAYS_INLINE x(__lx __v) : __v_(__v) {} \
+    _LIBCPP_ALWAYS_INLINE explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
     _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \
     };
 #else  // _LIBCPP_HAS_NO_STRONG_ENUMS
-#define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_VISIBLE x
+#define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_TYPE_VIS x
 #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
 #endif  // _LIBCPP_HAS_NO_STRONG_ENUMS
 
-#if __APPLE__ || __FreeBSD__ || _WIN32 || __sun__
+#ifndef _LIBCPP_EXTERN_TEMPLATE
+#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
+#endif
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) || defined(__NetBSD__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
-#if __FreeBSD__
+#ifdef __FreeBSD__
 #define _DECLARE_C99_LDBL_MATH 1
 #endif
 
-#if __APPLE__ || __FreeBSD__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #define _LIBCPP_HAS_DEFAULTRUNELOCALE
 #endif
 
-#if __APPLE__ || __FreeBSD__ || __sun__
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
 #define _LIBCPP_WCTYPE_IS_MASK
 #endif
 
@@ -436,6 +510,14 @@
 #   endif
 #endif
 
+#ifndef _LIBCPP_STD_VER
+#  if  __cplusplus <= 201103L
+#    define _LIBCPP_STD_VER 11
+#  else
+#    define _LIBCPP_STD_VER 13  // current year, or date of c++14 ratification
+#  endif
+#endif  // _LIBCPP_STD_VER
+
 #ifdef _LIBCPP_DEBUG2
 #   include <__debug>
 #else

Modified: trunk/contrib/libc++/include/__debug
===================================================================
--- trunk/contrib/libc++/include/__debug	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__debug	2016-01-07 17:22:14 UTC (rev 7405)
@@ -16,7 +16,9 @@
 #   include <cstdlib>
 #   include <cstdio>
 #   include <cstddef>
-#   define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#   ifndef _LIBCPP_ASSERT
+#      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#   endif
 
 #endif
 
@@ -24,9 +26,9 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-struct _LIBCPP_VISIBLE __c_node;
+struct _LIBCPP_TYPE_VIS __c_node;
 
-struct _LIBCPP_VISIBLE __i_node
+struct _LIBCPP_TYPE_VIS __i_node
 {
     void* __i_;
     __i_node* __next_;
@@ -40,7 +42,7 @@
     ~__i_node();
 };
 
-struct _LIBCPP_VISIBLE __c_node
+struct _LIBCPP_TYPE_VIS __c_node
 {
     void* __c_;
     __c_node* __next_;
@@ -117,7 +119,7 @@
     return _Cp->__subscriptable(__j, __n);
 }
 
-class _LIBCPP_VISIBLE __libcpp_db
+class _LIBCPP_TYPE_VIS __libcpp_db
 {
     __c_node** __cbeg_;
     __c_node** __cend_;
@@ -176,11 +178,11 @@
     _LIBCPP_HIDDEN
     __i_node* __find_iterator(const void* __i) const;
 
-    friend _LIBCPP_VISIBLE __libcpp_db* __get_db();
+    friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
 };
 
-_LIBCPP_VISIBLE __libcpp_db* __get_db();
-_LIBCPP_VISIBLE const __libcpp_db* __get_const_db();
+_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
+_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
 
 
 _LIBCPP_END_NAMESPACE_STD

Modified: trunk/contrib/libc++/include/__functional_03
===================================================================
--- trunk/contrib/libc++/include/__functional_03	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__functional_03	2016-01-07 17:22:14 UTC (rev 7405)
@@ -203,7 +203,7 @@
 {
 };
 
-template<class _Fp> class _LIBCPP_VISIBLE function; // undefined
+template<class _Fp> class _LIBCPP_TYPE_VIS function; // undefined
 
 namespace __function
 {
@@ -644,7 +644,7 @@
 }  // __function
 
 template<class _Rp>
-class _LIBCPP_VISIBLE function<_Rp()>
+class _LIBCPP_TYPE_VIS function<_Rp()>
 {
     typedef __function::__base<_Rp()> __base;
     aligned_storage<3*sizeof(void*)>::type __buf_;
@@ -928,7 +928,7 @@
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0>
-class _LIBCPP_VISIBLE function<_Rp(_A0)>
+class _LIBCPP_TYPE_VIS function<_Rp(_A0)>
     : public unary_function<_A0, _Rp>
 {
     typedef __function::__base<_Rp(_A0)> __base;
@@ -1230,7 +1230,7 @@
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0, class _A1>
-class _LIBCPP_VISIBLE function<_Rp(_A0, _A1)>
+class _LIBCPP_TYPE_VIS function<_Rp(_A0, _A1)>
     : public binary_function<_A0, _A1, _Rp>
 {
     typedef __function::__base<_Rp(_A0, _A1)> __base;
@@ -1532,7 +1532,7 @@
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0, class _A1, class _A2>
-class _LIBCPP_VISIBLE function<_Rp(_A0, _A1, _A2)>
+class _LIBCPP_TYPE_VIS function<_Rp(_A0, _A1, _A2)>
 {
     typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
     aligned_storage<3*sizeof(void*)>::type __buf_;
@@ -1860,11 +1860,11 @@
 {return __x.swap(__y);}
 
 template<class _Tp> struct __is_bind_expression : public false_type {};
-template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
+template<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression
     : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
 
 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
-template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
+template<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder
     : public __is_placeholder<typename remove_cv<_Tp>::type> {};
 
 namespace placeholders

Modified: trunk/contrib/libc++/include/__functional_base
===================================================================
--- trunk/contrib/libc++/include/__functional_base	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__functional_base	2016-01-07 17:22:14 UTC (rev 7405)
@@ -23,7 +23,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Arg, class _Result>
-struct _LIBCPP_VISIBLE unary_function
+struct _LIBCPP_TYPE_VIS unary_function
 {
     typedef _Arg    argument_type;
     typedef _Result result_type;
@@ -30,7 +30,7 @@
 };
 
 template <class _Arg1, class _Arg2, class _Result>
-struct _LIBCPP_VISIBLE binary_function
+struct _LIBCPP_TYPE_VIS binary_function
 {
     typedef _Arg1   first_argument_type;
     typedef _Arg2   second_argument_type;
@@ -37,13 +37,13 @@
     typedef _Result result_type;
 };
 
-template <class _Tp> struct _LIBCPP_VISIBLE hash;
+template <class _Tp> struct _LIBCPP_TYPE_VIS hash;
 
 template <class _Tp>
 struct __has_result_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::result_type* = 0);
 public:
@@ -51,7 +51,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS less : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x < __y;}
@@ -69,7 +69,7 @@
 struct __derives_from_unary_function
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     static __two __test(...);
     template <class _Ap, class _Rp>
         static unary_function<_Ap, _Rp>
@@ -83,7 +83,7 @@
 struct __derives_from_binary_function
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     static __two __test(...);
     template <class _A1, class _A2, class _Rp>
         static binary_function<_A1, _A2, _Rp>
@@ -292,7 +292,8 @@
 
 // bullets 1 and 2
 
-template <class _Fp, class _A0, class ..._Args>
+template <class _Fp, class _A0, class ..._Args,
+            class>
 inline _LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
@@ -301,7 +302,8 @@
     return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
 }
 
-template <class _Fp, class _A0, class ..._Args>
+template <class _Fp, class _A0, class ..._Args,
+            class>
 inline _LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
@@ -312,7 +314,8 @@
 
 // bullets 3 and 4
 
-template <class _Fp, class _A0>
+template <class _Fp, class _A0,
+            class>
 inline _LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
@@ -321,7 +324,8 @@
     return _VSTD::forward<_A0>(__a0).*__f;
 }
 
-template <class _Fp, class _A0>
+template <class _Fp, class _A0,
+            class>
 inline _LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
@@ -348,7 +352,7 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE reference_wrapper
+class _LIBCPP_TYPE_VIS reference_wrapper
     : public __weak_result_type<_Tp>
 {
 public:

Modified: trunk/contrib/libc++/include/__functional_base_03
===================================================================
--- trunk/contrib/libc++/include/__functional_base_03	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__functional_base_03	2016-01-07 17:22:14 UTC (rev 7405)
@@ -19,7 +19,7 @@
 struct __derives_from_unary_function
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     static __two __test(...);
     template <class _Ap, class _Rp>
         static unary_function<_Ap, _Rp>
@@ -33,7 +33,7 @@
 struct __derives_from_binary_function
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     static __two __test(...);
     template <class _A1, class _A2, class _Rp>
         static binary_function<_A1, _A2, _Rp>
@@ -943,7 +943,7 @@
 struct __has_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::type* = 0);
 public:
@@ -996,7 +996,7 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE reference_wrapper
+class _LIBCPP_TYPE_VIS reference_wrapper
     : public __weak_result_type<_Tp>
 {
 public:

Modified: trunk/contrib/libc++/include/__hash_table
===================================================================
--- trunk/contrib/libc++/include/__hash_table	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__hash_table	2016-01-07 17:22:14 UTC (rev 7405)
@@ -26,7 +26,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
 size_t __next_prime(size_t __n);
 
 template <class _NodePtr>
@@ -33,7 +33,6 @@
 struct __hash_node_base
 {
     typedef __hash_node_base __first_node;
- //   typedef _NodePtr pointer;
 
     _NodePtr    __next_;
 
@@ -58,15 +57,36 @@
     value_type __value_;
 };
 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__is_power2(size_t __bc)
+{
+    return __bc > 2 && !(__bc & (__bc - 1));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__constrain_hash(size_t __h, size_t __bc)
+{
+    return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : __h % __bc;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__next_pow2(size_t __n)
+{
+    return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
+}
+
 template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
-template <class _ConstNodePtr> class __hash_const_iterator;
-template <class _HashIterator> class __hash_map_iterator;
-template <class _HashIterator> class __hash_map_const_iterator;
+template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS __hash_const_iterator;
+template <class _HashIterator> class _LIBCPP_TYPE_VIS __hash_map_iterator;
+template <class _HashIterator> class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-    class _LIBCPP_VISIBLE unordered_map;
+    class _LIBCPP_TYPE_VIS unordered_map;
 
 template <class _NodePtr>
-class _LIBCPP_VISIBLE __hash_iterator
+class _LIBCPP_TYPE_VIS __hash_iterator
 {
     typedef _NodePtr __node_pointer;
 
@@ -90,7 +110,7 @@
     _LIBCPP_INLINE_VISIBILITY
         reference operator*() const {return __node_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-        pointer operator->() const {return _VSTD::addressof(__node_->__value_);}
+        pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_iterator& operator++()
@@ -121,14 +141,14 @@
         {}
 
     template <class, class, class, class> friend class __hash_table;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_iterator;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
 };
 
 template <class _ConstNodePtr>
-class _LIBCPP_VISIBLE __hash_const_iterator
+class _LIBCPP_TYPE_VIS __hash_const_iterator
 {
     typedef _ConstNodePtr __node_pointer;
 
@@ -168,7 +188,7 @@
     _LIBCPP_INLINE_VISIBILITY
         reference operator*() const {return __node_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-        pointer operator->() const {return _VSTD::addressof(__node_->__value_);}
+        pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_const_iterator& operator++()
@@ -199,15 +219,15 @@
         {}
 
     template <class, class, class, class> friend class __hash_table;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
 };
 
-template <class _ConstNodePtr> class _LIBCPP_VISIBLE __hash_const_local_iterator;
+template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
 
 template <class _NodePtr>
-class _LIBCPP_VISIBLE __hash_local_iterator
+class _LIBCPP_TYPE_VIS __hash_local_iterator
 {
     typedef _NodePtr __node_pointer;
 
@@ -234,13 +254,13 @@
     _LIBCPP_INLINE_VISIBILITY
         reference operator*() const {return __node_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-        pointer operator->() const {return &__node_->__value_;}
+        pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_local_iterator& operator++()
     {
         __node_ = __node_->__next_;
-        if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_)
+        if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
             __node_ = nullptr;
         return *this;
     }
@@ -273,12 +293,12 @@
         }
 
     template <class, class, class, class> friend class __hash_table;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_iterator;
 };
 
 template <class _ConstNodePtr>
-class _LIBCPP_VISIBLE __hash_const_local_iterator
+class _LIBCPP_TYPE_VIS __hash_const_local_iterator
 {
     typedef _ConstNodePtr __node_pointer;
 
@@ -324,13 +344,13 @@
     _LIBCPP_INLINE_VISIBILITY
         reference operator*() const {return __node_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-        pointer operator->() const {return &__node_->__value_;}
+        pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_const_local_iterator& operator++()
     {
         __node_ = __node_->__next_;
-        if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_)
+        if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
             __node_ = nullptr;
         return *this;
     }
@@ -363,7 +383,7 @@
         }
 
     template <class, class, class, class> friend class __hash_table;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
 };
 
 template <class _Alloc>
@@ -484,8 +504,15 @@
                                                      __node_allocator;
     typedef allocator_traits<__node_allocator>       __node_traits;
     typedef typename __node_traits::pointer          __node_pointer;
-    typedef typename __node_traits::const_pointer    __node_const_pointer;
+    typedef typename __node_traits::pointer          __node_const_pointer;
     typedef __hash_node_base<__node_pointer>         __first_node;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__first_node>
+#else
+            rebind<__first_node>::other
+#endif
+                                                     __node_base_pointer;
 
 private:
 
@@ -537,9 +564,9 @@
 
 public:
     typedef __hash_iterator<__node_pointer>                   iterator;
-    typedef __hash_const_iterator<__node_const_pointer>       const_iterator;
+    typedef __hash_const_iterator<__node_pointer>             const_iterator;
     typedef __hash_local_iterator<__node_pointer>             local_iterator;
-    typedef __hash_const_local_iterator<__node_const_pointer> const_local_iterator;
+    typedef __hash_const_local_iterator<__node_pointer>       const_local_iterator;
 
     __hash_table()
         _NOEXCEPT_(
@@ -637,7 +664,7 @@
     template <class _Key>
         _LIBCPP_INLINE_VISIBILITY
         size_type bucket(const _Key& __k) const
-            {return hash_function()(__k) % bucket_count();}
+            {return __constrain_hash(hash_function()(__k), bucket_count());}
 
     template <class _Key>
         iterator       find(const _Key& __x);
@@ -685,7 +712,7 @@
 
     _LIBCPP_INLINE_VISIBILITY
     size_type max_bucket_count() const _NOEXCEPT
-        {return __bucket_list_.get_deleter().__alloc().max_size();}
+        {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());}
     size_type bucket_size(size_type __n) const;
     _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
     {
@@ -786,6 +813,9 @@
 
     void __deallocate(__node_pointer __np) _NOEXCEPT;
     __node_pointer __detach() _NOEXCEPT;
+
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
 };
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -871,8 +901,8 @@
 {
     if (size() > 0)
     {
-        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
-            static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
         __u.__p1_.first().__next_ = nullptr;
         __u.size() = 0;
     }
@@ -895,8 +925,8 @@
         {
             __p1_.first().__next_ = __u.__p1_.first().__next_;
             __u.__p1_.first().__next_ = nullptr;
-            __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
-                static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+            __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+                static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
             size() = __u.size();
             __u.size() = 0;
         }
@@ -992,8 +1022,8 @@
     __p1_.first().__next_ = __u.__p1_.first().__next_;
     if (size() > 0)
     {
-        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
-            static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
         __u.__p1_.first().__next_ = nullptr;
         __u.size() = 0;
     }
@@ -1190,12 +1220,12 @@
     size_t __chash;
     if (__bc != 0)
     {
-        __chash = __nd->__hash_ % __bc;
+        __chash = __constrain_hash(__nd->__hash_, __bc);
         __ndptr = __bucket_list_[__chash];
         if (__ndptr != nullptr)
         {
             for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
-                                             __ndptr->__hash_ % __bc == __chash;
+                                             __constrain_hash(__ndptr->__hash_, __bc) == __chash;
                                                      __ndptr = __ndptr->__next_)
             {
                 if (key_eq()(__ndptr->__value_, __nd->__value_))
@@ -1206,22 +1236,22 @@
     {
         if (size()+1 > __bc * max_load_factor() || __bc == 0)
         {
-            rehash(_VSTD::max<size_type>(2 * __bc + 1,
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
                            size_type(ceil(float(size() + 1) / max_load_factor()))));
             __bc = bucket_count();
-            __chash = __nd->__hash_ % __bc;
+            __chash = __constrain_hash(__nd->__hash_, __bc);
         }
         // insert_after __bucket_list_[__chash], or __first_node if bucket is null
         __node_pointer __pn = __bucket_list_[__chash];
         if (__pn == nullptr)
         {
-            __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+            __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
             __nd->__next_ = __pn->__next_;
             __pn->__next_ = __nd;
             // fix up __bucket_list_
             __bucket_list_[__chash] = __pn;
             if (__nd->__next_ != nullptr)
-                __bucket_list_[__nd->__next_->__hash_ % __bc] = __nd;
+                __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd;
         }
         else
         {
@@ -1245,26 +1275,26 @@
     size_type __bc = bucket_count();
     if (size()+1 > __bc * max_load_factor() || __bc == 0)
     {
-        rehash(_VSTD::max<size_type>(2 * __bc + 1,
+        rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
                        size_type(ceil(float(size() + 1) / max_load_factor()))));
         __bc = bucket_count();
     }
-    size_t __chash = __cp->__hash_ % __bc;
+    size_t __chash = __constrain_hash(__cp->__hash_, __bc);
     __node_pointer __pn = __bucket_list_[__chash];
     if (__pn == nullptr)
     {
-        __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+        __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
         __cp->__next_ = __pn->__next_;
         __pn->__next_ = __cp;
         // fix up __bucket_list_
         __bucket_list_[__chash] = __pn;
         if (__cp->__next_ != nullptr)
-            __bucket_list_[__cp->__next_->__hash_ % __bc] = __cp;
+            __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp;
     }
     else
     {
         for (bool __found = false; __pn->__next_ != nullptr &&
-                                   __pn->__next_->__hash_ % __bc == __chash;
+                                   __constrain_hash(__pn->__next_->__hash_, __bc) == __chash;
                                                            __pn = __pn->__next_)
         {
             //      __found    key_eq()     action
@@ -1285,7 +1315,7 @@
         __pn->__next_ = __cp;
         if (__cp->__next_ != nullptr)
         {
-            size_t __nhash = __cp->__next_->__hash_ % __bc;
+            size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc);
             if (__nhash != __chash)
                 __bucket_list_[__nhash] = __cp;
         }
@@ -1301,16 +1331,16 @@
 {
     if (__p != end() && key_eq()(*__p, __cp->__value_))
     {
-        __node_pointer __np = const_cast<__node_pointer>(__p.__node_);
+        __node_pointer __np = __p.__node_;
         __cp->__hash_ = __np->__hash_;
         size_type __bc = bucket_count();
         if (size()+1 > __bc * max_load_factor() || __bc == 0)
         {
-            rehash(_VSTD::max<size_type>(2 * __bc + 1,
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
                            size_type(ceil(float(size() + 1) / max_load_factor()))));
             __bc = bucket_count();
         }
-        size_t __chash = __cp->__hash_ % __bc;
+        size_t __chash = __constrain_hash(__cp->__hash_, __bc);
         __node_pointer __pp = __bucket_list_[__chash];
         while (__pp->__next_ != __np)
             __pp = __pp->__next_;
@@ -1333,12 +1363,12 @@
     size_t __chash;
     if (__bc != 0)
     {
-        __chash = __hash % __bc;
+        __chash = __constrain_hash(__hash, __bc);
         __nd = __bucket_list_[__chash];
         if (__nd != nullptr)
         {
             for (__nd = __nd->__next_; __nd != nullptr &&
-                                       __nd->__hash_ % __bc == __chash;
+                                       __constrain_hash(__nd->__hash_, __bc) == __chash;
                                                            __nd = __nd->__next_)
             {
                 if (key_eq()(__nd->__value_, __x))
@@ -1350,22 +1380,22 @@
         __node_holder __h = __construct_node(__x, __hash);
         if (size()+1 > __bc * max_load_factor() || __bc == 0)
         {
-            rehash(_VSTD::max<size_type>(2 * __bc + 1,
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
                            size_type(ceil(float(size() + 1) / max_load_factor()))));
             __bc = bucket_count();
-            __chash = __hash % __bc;
+            __chash = __constrain_hash(__hash, __bc);
         }
         // insert_after __bucket_list_[__chash], or __first_node if bucket is null
         __node_pointer __pn = __bucket_list_[__chash];
         if (__pn == nullptr)
         {
-            __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+            __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
             __h->__next_ = __pn->__next_;
             __pn->__next_ = __h.get();
             // fix up __bucket_list_
             __bucket_list_[__chash] = __pn;
             if (__h->__next_ != nullptr)
-                __bucket_list_[__h->__next_->__hash_ % __bc] = __h.get();
+                __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get();
         }
         else
         {
@@ -1489,16 +1519,20 @@
 void
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
 {
-    __n = __next_prime(_VSTD::max<size_type>(__n, size() > 0));
+    if (__n == 1)
+        __n = 2;
+    else if (__n & (__n - 1))
+        __n = __next_prime(__n);
     size_type __bc = bucket_count();
     if (__n > __bc)
         __rehash(__n);
-    else
+    else if (__n < __bc)
     {
         __n = _VSTD::max<size_type>
               (
                   __n,
-                  __next_prime(size_t(ceil(float(size()) / max_load_factor())))
+                  __is_power2(__bc) ? __next_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
+                                      __next_prime(size_t(ceil(float(size()) / max_load_factor())))
               );
         if (__n < __bc)
             __rehash(__n);
@@ -1517,17 +1551,17 @@
     {
         for (size_type __i = 0; __i < __nbc; ++__i)
             __bucket_list_[__i] = nullptr;
-        __node_pointer __pp(static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())));
+        __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
         __node_pointer __cp = __pp->__next_;
         if (__cp != nullptr)
         {
-            size_type __chash = __cp->__hash_ % __nbc;
+            size_type __chash = __constrain_hash(__cp->__hash_, __nbc);
             __bucket_list_[__chash] = __pp;
             size_type __phash = __chash;
             for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
                                                            __cp = __pp->__next_)
             {
-                __chash = __cp->__hash_ % __nbc;
+                __chash = __constrain_hash(__cp->__hash_, __nbc);
                 if (__chash == __phash)
                     __pp = __cp;
                 else
@@ -1565,12 +1599,12 @@
     size_type __bc = bucket_count();
     if (__bc != 0)
     {
-        size_t __chash = __hash % __bc;
+        size_t __chash = __constrain_hash(__hash, __bc);
         __node_pointer __nd = __bucket_list_[__chash];
         if (__nd != nullptr)
         {
             for (__nd = __nd->__next_; __nd != nullptr &&
-                                       __nd->__hash_ % __bc == __chash;
+                                       __constrain_hash(__nd->__hash_, __bc) == __chash;
                                                            __nd = __nd->__next_)
             {
                 if (key_eq()(__nd->__value_, __k))
@@ -1590,12 +1624,12 @@
     size_type __bc = bucket_count();
     if (__bc != 0)
     {
-        size_t __chash = __hash % __bc;
+        size_t __chash = __constrain_hash(__hash, __bc);
         __node_const_pointer __nd = __bucket_list_[__chash];
         if (__nd != nullptr)
         {
             for (__nd = __nd->__next_; __nd != nullptr &&
-                                           __nd->__hash_ % __bc == __chash;
+                                           __constrain_hash(__nd->__hash_, __bc) == __chash;
                                                            __nd = __nd->__next_)
             {
                 if (key_eq()(__nd->__value_, __k))
@@ -1675,7 +1709,7 @@
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
 {
-    __node_pointer __np = const_cast<__node_pointer>(__p.__node_);
+    __node_pointer __np = __p.__node_;
     iterator __r(__np);
     ++__r;
     remove(__p);
@@ -1692,7 +1726,7 @@
         ++__first;
         erase(__p);
     }
-    __node_pointer __np = const_cast<__node_pointer>(__last.__node_);
+    __node_pointer __np = __last.__node_;
     return iterator (__np);
 }
 
@@ -1732,9 +1766,9 @@
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
 {
     // current node
-    __node_pointer __cn = const_cast<__node_pointer>(__p.__node_);
+    __node_pointer __cn = __p.__node_;
     size_type __bc = bucket_count();
-    size_t __chash = __cn->__hash_ % __bc;
+    size_t __chash = __constrain_hash(__cn->__hash_, __bc);
     // find previous node
     __node_pointer __pn = __bucket_list_[__chash];
     for (; __pn->__next_ != __cn; __pn = __pn->__next_)
@@ -1742,15 +1776,16 @@
     // Fix up __bucket_list_
         // if __pn is not in same bucket (before begin is not in same bucket) &&
         //    if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
-    if (__pn == _VSTD::addressof(__p1_.first()) || __pn->__hash_ % __bc != __chash)
+    if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))
+                            || __constrain_hash(__pn->__hash_, __bc) != __chash)
     {
-        if (__cn->__next_ == nullptr || __cn->__next_->__hash_ % __bc != __chash)
+        if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash)
             __bucket_list_[__chash] = nullptr;
     }
         // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
     if (__cn->__next_ != nullptr)
     {
-        size_t __nhash = __cn->__next_->__hash_ % __bc;
+        size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc);
         if (__nhash != __chash)
             __bucket_list_[__nhash] = __pn;
     }
@@ -1881,11 +1916,11 @@
     __p2_.swap(__u.__p2_);
     __p3_.swap(__u.__p3_);
     if (size() > 0)
-        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
-            static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()));
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
     if (__u.size() > 0)
-        __u.__bucket_list_[__u.__p1_.first().__next_->__hash_ % __u.bucket_count()] =
-            static_cast<__node_pointer>(_VSTD::addressof(__u.__p1_.first()));
+        __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first()));
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1898,7 +1933,7 @@
     if (__np != nullptr)
     {
         for (__np = __np->__next_; __np != nullptr &&
-                                   __np->__hash_ % __bc == __n;
+                                   __constrain_hash(__np->__hash_, __bc) == __n;
                                                     __np = __np->__next_, ++__r)
             ;
     }

Modified: trunk/contrib/libc++/include/__locale
===================================================================
--- trunk/contrib/libc++/include/__locale	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__locale	2016-01-07 17:22:14 UTC (rev 7405)
@@ -19,11 +19,11 @@
 #include <cstdint>
 #include <cctype>
 #include <locale.h>
-#if _WIN32
+#ifdef _WIN32
 # include <support/win32/locale_win32.h>
-#elif (__GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__)
+#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(EMSCRIPTEN)
 # include <xlocale.h>
-#endif  // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD_
+#endif  // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || EMSCRIPTEN
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -31,17 +31,24 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class locale;
+class _LIBCPP_TYPE_VIS locale;
 
-template <class _Facet> bool has_facet(const locale&) _NOEXCEPT;
-template <class _Facet> const _Facet& use_facet(const locale&);
+template <class _Facet>
+_LIBCPP_INLINE_VISIBILITY
+bool
+has_facet(const locale&) _NOEXCEPT;
 
-class _LIBCPP_VISIBLE locale
+template <class _Facet>
+_LIBCPP_INLINE_VISIBILITY
+const _Facet&
+use_facet(const locale&);
+
+class _LIBCPP_TYPE_VIS locale
 {
 public:
     // types:
-    class facet;
-    class id;
+    class _LIBCPP_TYPE_VIS facet;
+    class _LIBCPP_TYPE_VIS id;
 
     typedef int category;
     static const category // values assigned here are for exposition only
@@ -96,7 +103,7 @@
     template <class _Facet> friend const _Facet& use_facet(const locale&);
 };
 
-class _LIBCPP_VISIBLE locale::facet
+class _LIBCPP_TYPE_VIS locale::facet
     : public __shared_count
 {
 protected:
@@ -112,7 +119,7 @@
     virtual void __on_zero_shared() _NOEXCEPT;
 };
 
-class _LIBCPP_VISIBLE locale::id
+class _LIBCPP_TYPE_VIS locale::id
 {
     once_flag      __flag_;
     int32_t        __id_;
@@ -119,7 +126,7 @@
 
     static int32_t __next_id;
 public:
-    _LIBCPP_INLINE_VISIBILITY id() {}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
 private:
     void __init();
     void operator=(const id&); // = delete;
@@ -168,7 +175,7 @@
 // template <class _CharT> class collate;
 
 template <class _CharT>
-class _LIBCPP_VISIBLE collate
+class _LIBCPP_TYPE_VIS collate
     : public locale::facet
 {
 public:
@@ -247,15 +254,15 @@
     return static_cast<long>(__h);
 }
 
-extern template class _LIBCPP_VISIBLE collate<char>;
-extern template class _LIBCPP_VISIBLE collate<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS collate<char>)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS collate<wchar_t>)
 
 // template <class CharT> class collate_byname;
 
-template <class _CharT> class _LIBCPP_VISIBLE collate_byname;
+template <class _CharT> class _LIBCPP_TYPE_VIS collate_byname;
 
 template <>
-class _LIBCPP_VISIBLE collate_byname<char>
+class _LIBCPP_TYPE_VIS collate_byname<char>
     : public collate<char>
 {
     locale_t __l;
@@ -274,7 +281,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE collate_byname<wchar_t>
+class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
     : public collate<wchar_t>
 {
     locale_t __l;
@@ -305,10 +312,10 @@
 
 // template <class charT> class ctype
 
-class _LIBCPP_VISIBLE ctype_base
+class _LIBCPP_TYPE_VIS ctype_base
 {
 public:
-#if __GLIBC__
+#ifdef __GLIBC__
     typedef unsigned short mask;
     static const mask space  = _ISspace;
     static const mask print  = _ISprint;
@@ -320,7 +327,7 @@
     static const mask punct  = _ISpunct;
     static const mask xdigit = _ISxdigit;
     static const mask blank  = _ISblank;
-#elif _WIN32
+#elif defined(_WIN32)
     typedef unsigned short mask;
     static const mask space  = _SPACE;
     static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
@@ -332,11 +339,13 @@
     static const mask punct  = _PUNCT;
     static const mask xdigit = _HEX;
     static const mask blank  = _BLANK;
-#elif (__APPLE__ || __FreeBSD__)
-#if __APPLE__
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
+#ifdef __APPLE__
     typedef __uint32_t mask;
-#elif __FreeBSD__
+#elif defined(__FreeBSD__)
     typedef unsigned long mask;
+#elif defined(EMSCRIPTEN) ||  defined(__NetBSD__)
+    typedef unsigned short mask;
 #endif
     static const mask space  = _CTYPE_S;
     static const mask print  = _CTYPE_R;
@@ -347,8 +356,12 @@
     static const mask digit  = _CTYPE_D;
     static const mask punct  = _CTYPE_P;
     static const mask xdigit = _CTYPE_X;
+# if defined(__NetBSD__)
+    static const mask blank  = _CTYPE_BL;
+# else
     static const mask blank  = _CTYPE_B;
-#elif __sun__
+# endif
+#elif defined(__sun__)
     typedef unsigned int mask;
     static const mask space  = _ISSPACE;
     static const mask print  = _ISPRINT;
@@ -360,7 +373,7 @@
     static const mask punct  = _ISPUNCT;
     static const mask xdigit = _ISXDIGIT;
     static const mask blank  = _ISBLANK;
-#else  // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __sun__
+#else  // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || EMSCRIPTEN || __sun__
     typedef unsigned long mask;
     static const mask space  = 1<<0;
     static const mask print  = 1<<1;
@@ -379,10 +392,10 @@
     _LIBCPP_ALWAYS_INLINE ctype_base() {}
 };
 
-template <class _CharT> class _LIBCPP_VISIBLE ctype;
+template <class _CharT> class _LIBCPP_TYPE_VIS ctype;
 
 template <>
-class _LIBCPP_VISIBLE ctype<wchar_t>
+class _LIBCPP_TYPE_VIS ctype<wchar_t>
     : public locale::facet,
       public ctype_base
 {
@@ -484,7 +497,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE ctype<char>
+class _LIBCPP_TYPE_VIS ctype<char>
     : public locale::facet, public ctype_base
 {
     const mask* __tab_;
@@ -583,10 +596,14 @@
 #endif
     _LIBCPP_ALWAYS_INLINE const mask* table() const  _NOEXCEPT {return __tab_;}
     static const mask* classic_table()  _NOEXCEPT;
-#if defined(__GLIBC__)
+#if defined(__GLIBC__) || defined(EMSCRIPTEN)
     static const int* __classic_upper_table() _NOEXCEPT;
     static const int* __classic_lower_table() _NOEXCEPT;
 #endif
+#if defined(__NetBSD__)
+    static const short* __classic_upper_table() _NOEXCEPT;
+    static const short* __classic_lower_table() _NOEXCEPT;
+#endif
 
 protected:
     ~ctype();
@@ -602,10 +619,10 @@
 
 // template <class CharT> class ctype_byname;
 
-template <class _CharT> class _LIBCPP_VISIBLE ctype_byname;
+template <class _CharT> class _LIBCPP_TYPE_VIS ctype_byname;
 
 template <>
-class _LIBCPP_VISIBLE ctype_byname<char>
+class _LIBCPP_TYPE_VIS ctype_byname<char>
     : public ctype<char>
 {
     locale_t __l;
@@ -623,7 +640,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE ctype_byname<wchar_t>
+class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
     : public ctype<wchar_t>
 {
     locale_t __l;
@@ -754,7 +771,7 @@
 
 // codecvt_base
 
-class _LIBCPP_VISIBLE codecvt_base
+class _LIBCPP_TYPE_VIS codecvt_base
 {
 public:
     _LIBCPP_ALWAYS_INLINE codecvt_base() {}
@@ -763,12 +780,12 @@
 
 // template <class internT, class externT, class stateT> class codecvt;
 
-template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_VISIBLE codecvt;
+template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS codecvt;
 
 // template <> class codecvt<char, char, mbstate_t>
 
 template <>
-class _LIBCPP_VISIBLE codecvt<char, char, mbstate_t>
+class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
     : public locale::facet,
       public codecvt_base
 {
@@ -854,7 +871,7 @@
 // template <> class codecvt<wchar_t, char, mbstate_t>
 
 template <>
-class _LIBCPP_VISIBLE codecvt<wchar_t, char, mbstate_t>
+class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
     : public locale::facet,
       public codecvt_base
 {
@@ -937,7 +954,7 @@
 // template <> class codecvt<char16_t, char, mbstate_t>
 
 template <>
-class _LIBCPP_VISIBLE codecvt<char16_t, char, mbstate_t>
+class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
     : public locale::facet,
       public codecvt_base
 {
@@ -1023,7 +1040,7 @@
 // template <> class codecvt<char32_t, char, mbstate_t>
 
 template <>
-class _LIBCPP_VISIBLE codecvt<char32_t, char, mbstate_t>
+class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
     : public locale::facet,
       public codecvt_base
 {
@@ -1109,7 +1126,7 @@
 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
 
 template <class _InternT, class _ExternT, class _StateT>
-class _LIBCPP_VISIBLE codecvt_byname
+class _LIBCPP_TYPE_VIS codecvt_byname
     : public codecvt<_InternT, _ExternT, _StateT>
 {
 public:
@@ -1128,12 +1145,12 @@
 {
 }
 
-extern template class codecvt_byname<char, char, mbstate_t>;
-extern template class codecvt_byname<wchar_t, char, mbstate_t>;
-extern template class codecvt_byname<char16_t, char, mbstate_t>;
-extern template class codecvt_byname<char32_t, char, mbstate_t>;
+_LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<wchar_t, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char16_t, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char32_t, char, mbstate_t>)
 
-_LIBCPP_VISIBLE void __throw_runtime_error(const char*);
+_LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
 
 template <size_t _Np>
 struct __narrow_to_utf8
@@ -1317,10 +1334,10 @@
 
 // template <class charT> class numpunct
 
-template <class _CharT> class _LIBCPP_VISIBLE numpunct;
+template <class _CharT> class _LIBCPP_TYPE_VIS numpunct;
 
 template <>
-class _LIBCPP_VISIBLE numpunct<char>
+class _LIBCPP_TYPE_VIS numpunct<char>
     : public locale::facet
 {
 public:
@@ -1351,7 +1368,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE numpunct<wchar_t>
+class _LIBCPP_TYPE_VIS numpunct<wchar_t>
     : public locale::facet
 {
 public:
@@ -1383,10 +1400,10 @@
 
 // template <class charT> class numpunct_byname
 
-template <class charT> class _LIBCPP_VISIBLE numpunct_byname;
+template <class charT> class _LIBCPP_TYPE_VIS numpunct_byname;
 
 template <>
-class _LIBCPP_VISIBLE numpunct_byname<char>
+class _LIBCPP_TYPE_VIS numpunct_byname<char>
 : public numpunct<char>
 {
 public:
@@ -1404,7 +1421,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE numpunct_byname<wchar_t>
+class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
 : public numpunct<wchar_t>
 {
 public:

Modified: trunk/contrib/libc++/include/__mutex_base
===================================================================
--- trunk/contrib/libc++/include/__mutex_base	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__mutex_base	2016-01-07 17:22:14 UTC (rev 7405)
@@ -32,13 +32,17 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_VISIBLE mutex
+class _LIBCPP_TYPE_VIS mutex
 {
     pthread_mutex_t __m_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-     mutex() {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
+#else
+     mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
+#endif
      ~mutex();
 
 private:
@@ -47,31 +51,33 @@
 
 public:
     void lock();
-    bool try_lock();
-    void unlock();
+    bool try_lock() _NOEXCEPT;
+    void unlock() _NOEXCEPT;
 
     typedef pthread_mutex_t* native_handle_type;
     _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
 };
 
-struct _LIBCPP_VISIBLE defer_lock_t {};
-struct _LIBCPP_VISIBLE try_to_lock_t {};
-struct _LIBCPP_VISIBLE adopt_lock_t {};
+struct _LIBCPP_TYPE_VIS defer_lock_t {};
+struct _LIBCPP_TYPE_VIS try_to_lock_t {};
+struct _LIBCPP_TYPE_VIS adopt_lock_t {};
 
-//constexpr
-extern const
-defer_lock_t  defer_lock;
+#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MUTEX)
 
-//constexpr
-extern const
-try_to_lock_t try_to_lock;
+extern const defer_lock_t  defer_lock;
+extern const try_to_lock_t try_to_lock;
+extern const adopt_lock_t  adopt_lock;
 
-//constexpr
-extern const
-adopt_lock_t  adopt_lock;
+#else
 
+constexpr defer_lock_t  defer_lock  = defer_lock_t();
+constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+constexpr adopt_lock_t  adopt_lock  = adopt_lock_t();
+
+#endif
+
 template <class _Mutex>
-class _LIBCPP_VISIBLE lock_guard
+class _LIBCPP_TYPE_VIS lock_guard
 {
 public:
     typedef _Mutex mutex_type;
@@ -95,7 +101,7 @@
 };
 
 template <class _Mutex>
-class _LIBCPP_VISIBLE unique_lock
+class _LIBCPP_TYPE_VIS unique_lock
 {
 public:
     typedef _Mutex mutex_type;
@@ -106,12 +112,12 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    unique_lock() : __m_(nullptr), __owns_(false) {}
+    unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
     _LIBCPP_INLINE_VISIBILITY
     explicit unique_lock(mutex_type& __m)
         : __m_(&__m), __owns_(true) {__m_->lock();}
     _LIBCPP_INLINE_VISIBILITY
-    unique_lock(mutex_type& __m, defer_lock_t)
+    unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
         : __m_(&__m), __owns_(false) {}
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(mutex_type& __m, try_to_lock_t)
@@ -141,11 +147,11 @@
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    unique_lock(unique_lock&& __u)
+    unique_lock(unique_lock&& __u) _NOEXCEPT
         : __m_(__u.__m_), __owns_(__u.__owns_)
         {__u.__m_ = nullptr; __u.__owns_ = false;}
     _LIBCPP_INLINE_VISIBILITY
-    unique_lock& operator=(unique_lock&& __u)
+    unique_lock& operator=(unique_lock&& __u) _NOEXCEPT
         {
             if (__owns_)
                 __m_->unlock();
@@ -190,13 +196,13 @@
     void unlock();
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(unique_lock& __u)
+    void swap(unique_lock& __u) _NOEXCEPT
     {
         _VSTD::swap(__m_, __u.__m_);
         _VSTD::swap(__owns_, __u.__owns_);
     }
     _LIBCPP_INLINE_VISIBILITY
-    mutex_type* release()
+    mutex_type* release() _NOEXCEPT
     {
         mutex_type* __m = __m_;
         __m_ = nullptr;
@@ -205,12 +211,12 @@
     }
 
     _LIBCPP_INLINE_VISIBILITY
-    bool owns_lock() const {return __owns_;}
+    bool owns_lock() const _NOEXCEPT {return __owns_;}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_EXPLICIT
-        operator bool () const {return __owns_;}
+        operator bool () const _NOEXCEPT {return __owns_;}
     _LIBCPP_INLINE_VISIBILITY
-    mutex_type* mutex() const {return __m_;}
+    mutex_type* mutex() const _NOEXCEPT {return __m_;}
 };
 
 template <class _Mutex>
@@ -276,28 +282,33 @@
 template <class _Mutex>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) {__x.swap(__y);}
+swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT
+    {__x.swap(__y);}
 
-struct _LIBCPP_VISIBLE cv_status
+struct _LIBCPP_TYPE_VIS cv_status
 {
-    enum _ {
+    enum __lx {
         no_timeout,
         timeout
     };
 
-    _ __v_;
+    __lx __v_;
 
-    _LIBCPP_INLINE_VISIBILITY cv_status(_ __v) : __v_(__v) {}
+    _LIBCPP_INLINE_VISIBILITY cv_status(__lx __v) : __v_(__v) {}
     _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;}
 
 };
 
-class _LIBCPP_VISIBLE condition_variable
+class _LIBCPP_TYPE_VIS condition_variable
 {
     pthread_cond_t __cv_;
 public:
     _LIBCPP_INLINE_VISIBILITY
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
+#else
     condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
+#endif
     ~condition_variable();
 
 private:
@@ -305,18 +316,13 @@
     condition_variable& operator=(const condition_variable&); // = delete;
 
 public:
-    void notify_one();
-    void notify_all();
+    void notify_one() _NOEXCEPT;
+    void notify_all() _NOEXCEPT;
 
     void wait(unique_lock<mutex>& __lk);
     template <class _Predicate>
         void wait(unique_lock<mutex>& __lk, _Predicate __pred);
 
-    template <class _Duration>
-        cv_status
-        wait_until(unique_lock<mutex>& __lk,
-                   const chrono::time_point<chrono::system_clock, _Duration>& __t);
-
     template <class _Clock, class _Duration>
         cv_status
         wait_until(unique_lock<mutex>& __lk,
@@ -371,19 +377,6 @@
         wait(__lk);
 }
 
-template <class _Duration>
-cv_status
-condition_variable::wait_until(unique_lock<mutex>& __lk,
-                 const chrono::time_point<chrono::system_clock, _Duration>& __t)
-{
-    using namespace chrono;
-    typedef time_point<system_clock, nanoseconds> __nano_sys_tmpt;
-    __do_timed_wait(__lk,
-                  __nano_sys_tmpt(__ceil<nanoseconds>(__t.time_since_epoch())));
-    return system_clock::now() < __t ? cv_status::no_timeout :
-                                       cv_status::timeout;
-}
-
 template <class _Clock, class _Duration>
 cv_status
 condition_variable::wait_until(unique_lock<mutex>& __lk,
@@ -390,9 +383,7 @@
                                const chrono::time_point<_Clock, _Duration>& __t)
 {
     using namespace chrono;
-    system_clock::time_point     __s_now = system_clock::now();
-    typename _Clock::time_point  __c_now = _Clock::now();
-    __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__t - __c_now));
+    wait_for(__lk, __t - _Clock::now());
     return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
 }
 
@@ -416,9 +407,17 @@
                              const chrono::duration<_Rep, _Period>& __d)
 {
     using namespace chrono;
+    if (__d <= __d.zero())
+        return cv_status::timeout;
+    typedef time_point<system_clock, duration<long double, nano> > __sys_tpf;
+    typedef time_point<system_clock, nanoseconds> __sys_tpi;
+    __sys_tpf _Max = __sys_tpi::max();
     system_clock::time_point __s_now = system_clock::now();
     steady_clock::time_point __c_now = steady_clock::now();
-    __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));
+    if (_Max - __d > __s_now)
+        __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));
+    else
+        __do_timed_wait(__lk, __sys_tpi::max());
     return steady_clock::now() - __c_now < __d ? cv_status::no_timeout :
                                                  cv_status::timeout;
 }

Modified: trunk/contrib/libc++/include/__split_buffer
===================================================================
--- trunk/contrib/libc++/include/__split_buffer	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__split_buffer	2016-01-07 17:22:14 UTC (rev 7405)
@@ -290,7 +290,7 @@
 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
 {
     while (__begin_ != __new_begin)
-        __alloc_traits::destroy(__alloc(), __begin_++);
+        __alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++));
 }
 
 template <class _Tp, class _Allocator>
@@ -307,7 +307,7 @@
 __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
 {
     while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), --__end_);
+        __alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_));
 }
 
 template <class _Tp, class _Allocator>
@@ -320,7 +320,7 @@
 
 template <class _Tp, class _Allocator>
 __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
-    : __end_cap_(0, __a)
+    : __end_cap_(nullptr, __a)
 {
     __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
     __begin_ = __end_ = __first_ + __start;
@@ -331,7 +331,7 @@
 _LIBCPP_INLINE_VISIBILITY inline
 __split_buffer<_Tp, _Allocator>::__split_buffer()
     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-    : __first_(0), __begin_(0), __end_(0), __end_cap_(0)
+    : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr)
 {
 }
 
@@ -338,7 +338,7 @@
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 __split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
-    : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a)
+    : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
 {
 }
 
@@ -345,7 +345,7 @@
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 __split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
-    : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a)
+    : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
 {
 }
 

Modified: trunk/contrib/libc++/include/__std_stream
===================================================================
--- trunk/contrib/libc++/include/__std_stream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__std_stream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -41,7 +41,7 @@
     typedef typename traits_type::off_type   off_type;
     typedef typename traits_type::state_type state_type;
 
-    explicit __stdinbuf(FILE* __fp);
+    __stdinbuf(FILE* __fp, state_type* __st);
 
 protected:
     virtual int_type underflow();
@@ -53,8 +53,10 @@
 
     FILE* __file_;
     const codecvt<char_type, char, state_type>* __cv_;
-    state_type __st_;
+    state_type* __st_;
     int __encoding_;
+    int_type __last_consumed_;
+    bool __last_consumed_is_next_;
     bool __always_noconv_;
 
     __stdinbuf(const __stdinbuf&);
@@ -64,9 +66,11 @@
 };
 
 template <class _CharT>
-__stdinbuf<_CharT>::__stdinbuf(FILE* __fp)
+__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st)
     : __file_(__fp),
-      __st_()
+      __st_(__st),
+      __last_consumed_(traits_type::eof()),
+      __last_consumed_is_next_(false)
 {
     imbue(this->getloc());
 }
@@ -100,6 +104,16 @@
 typename __stdinbuf<_CharT>::int_type
 __stdinbuf<_CharT>::__getchar(bool __consume)
 {
+    if (__last_consumed_is_next_)
+    {
+        int_type __result = __last_consumed_;
+        if (__consume)
+        {
+            __last_consumed_ = traits_type::eof();
+            __last_consumed_is_next_ = false;
+        }
+        return __result;
+    }
     char __extbuf[__limit];
     int __nread = _VSTD::max(1, __encoding_);
     for (int __i = 0; __i < __nread; ++__i)
@@ -119,8 +133,8 @@
         codecvt_base::result __r;
         do
         {
-            state_type __sv_st = __st_;
-            __r = __cv_->in(__st_, __extbuf, __extbuf + __nread, __enxt,
+            state_type __sv_st = *__st_;
+            __r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt,
                                    &__1buf, &__1buf + 1, __inxt);
             switch (__r)
             {
@@ -127,7 +141,7 @@
             case _VSTD::codecvt_base::ok:
                 break;
             case codecvt_base::partial:
-                __st_ = __sv_st;
+                *__st_ = __sv_st;
                 if (__nread == sizeof(__extbuf))
                     return traits_type::eof();
                 {
@@ -150,10 +164,12 @@
     {
         for (int __i = __nread; __i > 0;)
         {
-            if (ungetc(__extbuf[--__i], __file_) == EOF)
+            if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF)
                 return traits_type::eof();
         }
     }
+    else
+        __last_consumed_ = traits_type::to_int_type(__1buf);
     return traits_type::to_int_type(__1buf);
 }
 
@@ -162,28 +178,41 @@
 __stdinbuf<_CharT>::pbackfail(int_type __c)
 {
     if (traits_type::eq_int_type(__c, traits_type::eof()))
+    {
+        if (!__last_consumed_is_next_)
+        {
+            __c = __last_consumed_;
+            __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_,
+                                                                 traits_type::eof());
+        }
         return __c;
-    char __extbuf[__limit];
-    char* __enxt;
-    const char_type __ci = traits_type::to_char_type(__c);
-    const char_type* __inxt;
-    switch (__cv_->out(__st_, &__ci, &__ci + 1, __inxt,
-                              __extbuf, __extbuf + sizeof(__extbuf), __enxt))
+    }
+    if (__last_consumed_is_next_)
     {
-    case _VSTD::codecvt_base::ok:
-        break;
-    case _VSTD::codecvt_base::noconv:
-        __extbuf[0] = static_cast<char>(__c);
-        __enxt = __extbuf + 1;
-        break;
-    case codecvt_base::partial:
-    case codecvt_base::error:
-        return traits_type::eof();
+        char __extbuf[__limit];
+        char* __enxt;
+        const char_type __ci = traits_type::to_char_type(__last_consumed_);
+        const char_type* __inxt;
+        switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt,
+                                  __extbuf, __extbuf + sizeof(__extbuf), __enxt))
+        {
+        case _VSTD::codecvt_base::ok:
+            break;
+        case _VSTD::codecvt_base::noconv:
+            __extbuf[0] = static_cast<char>(__last_consumed_);
+            __enxt = __extbuf + 1;
+            break;
+        case codecvt_base::partial:
+        case codecvt_base::error:
+            return traits_type::eof();
+        }
+        while (__enxt > __extbuf)
+            if (ungetc(*--__enxt, __file_) == EOF)
+                return traits_type::eof();
     }
-    while (__enxt > __extbuf)
-        if (ungetc(*--__enxt, __file_) == EOF)
-            return traits_type::eof();
- return traits_type::not_eof(__c);
+    __last_consumed_ = __c;
+    __last_consumed_is_next_ = true;
+    return __c;
 }
 
 // __stdoutbuf
@@ -200,7 +229,7 @@
     typedef typename traits_type::off_type   off_type;
     typedef typename traits_type::state_type state_type;
 
-    explicit __stdoutbuf(FILE* __fp);
+    __stdoutbuf(FILE* __fp, state_type* __st);
 
 protected:
     virtual int_type overflow (int_type __c = traits_type::eof());
@@ -210,7 +239,7 @@
 private:
     FILE* __file_;
     const codecvt<char_type, char, state_type>* __cv_;
-    state_type __st_;
+    state_type* __st_;
     bool __always_noconv_;
 
     __stdoutbuf(const __stdoutbuf&);
@@ -218,10 +247,10 @@
 };
 
 template <class _CharT>
-__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp)
+__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st)
     : __file_(__fp),
       __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
-      __st_(),
+      __st_(__st),
       __always_noconv_(__cv_->always_noconv())
 {
 }
@@ -234,12 +263,10 @@
     char_type __1buf;
     if (!traits_type::eq_int_type(__c, traits_type::eof()))
     {
-        this->setp(&__1buf, &__1buf+1);
-        *this->pptr() = traits_type::to_char_type(__c);
-        this->pbump(1);
+        __1buf = traits_type::to_char_type(__c);
         if (__always_noconv_)
         {
-            if (fwrite(this->pbase(), sizeof(char_type), 1, __file_) != 1)
+            if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1)
                 return traits_type::eof();
         }
         else
@@ -246,18 +273,21 @@
         {
             char* __extbe = __extbuf;
             codecvt_base::result __r;
+            char_type* pbase = &__1buf;
+            char_type* pptr = pbase + 1;
+            char_type* epptr = pptr;
             do
             {
                 const char_type* __e;
-                __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
+                __r = __cv_->out(*__st_, pbase, pptr, __e,
                                         __extbuf,
                                         __extbuf + sizeof(__extbuf),
                                         __extbe);
-                if (__e == this->pbase())
+                if (__e == pbase)
                     return traits_type::eof();
                 if (__r == codecvt_base::noconv)
                 {
-                    if (fwrite(this->pbase(), 1, 1, __file_) != 1)
+                    if (fwrite(pbase, 1, 1, __file_) != 1)
                         return traits_type::eof();
                 }
                 else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
@@ -267,8 +297,7 @@
                         return traits_type::eof();
                     if (__r == codecvt_base::partial)
                     {
-                        this->setp((char_type*)__e, this->pptr());
-                        this->pbump(static_cast<int>(this->epptr() - this->pbase()));
+                        pbase = (char_type*)__e;
                     }
                 }
                 else
@@ -275,7 +304,6 @@
                     return traits_type::eof();
             } while (__r == codecvt_base::partial);
         }
-        this->setp(0, 0);
     }
     return traits_type::not_eof(__c);
 }
@@ -289,7 +317,7 @@
     do
     {
         char* __extbe;
-        __r = __cv_->unshift(__st_, __extbuf,
+        __r = __cv_->unshift(*__st_, __extbuf,
                                     __extbuf + sizeof(__extbuf),
                                     __extbe);
         size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);

Modified: trunk/contrib/libc++/include/__tree
===================================================================
--- trunk/contrib/libc++/include/__tree	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__tree	2016-01-07 17:22:14 UTC (rev 7405)
@@ -25,17 +25,17 @@
 
 template <class _Tp, class _Compare, class _Allocator> class __tree;
 template <class _Tp, class _NodePtr, class _DiffType>
-    class _LIBCPP_VISIBLE __tree_iterator;
+    class _LIBCPP_TYPE_VIS __tree_iterator;
 template <class _Tp, class _ConstNodePtr, class _DiffType>
-    class _LIBCPP_VISIBLE __tree_const_iterator;
+    class _LIBCPP_TYPE_VIS __tree_const_iterator;
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-    class _LIBCPP_VISIBLE map;
+    class _LIBCPP_TYPE_VIS map;
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-    class _LIBCPP_VISIBLE multimap;
+    class _LIBCPP_TYPE_VIS multimap;
 template <class _Key, class _Compare, class _Allocator>
-    class _LIBCPP_VISIBLE set;
+    class _LIBCPP_TYPE_VIS set;
 template <class _Key, class _Compare, class _Allocator>
-    class _LIBCPP_VISIBLE multiset;
+    class _LIBCPP_TYPE_VIS multiset;
 
 /*
 
@@ -614,11 +614,11 @@
 #endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 };
 
-template <class _TreeIterator> class __map_iterator;
-template <class _TreeIterator> class __map_const_iterator;
+template <class _TreeIterator> class _LIBCPP_TYPE_VIS __map_iterator;
+template <class _TreeIterator> class _LIBCPP_TYPE_VIS __map_const_iterator;
 
 template <class _Tp, class _NodePtr, class _DiffType>
-class _LIBCPP_VISIBLE __tree_iterator
+class _LIBCPP_TYPE_VIS __tree_iterator
 {
     typedef _NodePtr                                              __node_pointer;
     typedef typename pointer_traits<__node_pointer>::element_type __node;
@@ -644,7 +644,8 @@
     _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT {}
 
     _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;}
-    _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const
+        {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __tree_iterator& operator++()
@@ -673,20 +674,20 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
     template <class, class, class> friend class __tree;
-    template <class, class, class> friend class _LIBCPP_VISIBLE __tree_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __map_iterator;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
-    template <class, class, class> friend class _LIBCPP_VISIBLE set;
-    template <class, class, class> friend class _LIBCPP_VISIBLE multiset;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS __tree_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __map_iterator;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS set;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS multiset;
 };
 
 template <class _Tp, class _ConstNodePtr, class _DiffType>
-class _LIBCPP_VISIBLE __tree_const_iterator
+class _LIBCPP_TYPE_VIS __tree_const_iterator
 {
     typedef _ConstNodePtr                                         __node_pointer;
     typedef typename pointer_traits<__node_pointer>::element_type __node;
-    typedef const typename __node::base                           __node_base;
+    typedef typename __node::base                                 __node_base;
     typedef typename pointer_traits<__node_pointer>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind<__node_base>
@@ -729,7 +730,8 @@
         : __ptr_(__p.__ptr_) {}
 
     _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;}
-    _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const
+        {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __tree_const_iterator& operator++()
@@ -759,11 +761,11 @@
     explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT
         : __ptr_(__p) {}
     template <class, class, class> friend class __tree;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
-    template <class, class, class> friend class _LIBCPP_VISIBLE set;
-    template <class, class, class> friend class _LIBCPP_VISIBLE multiset;
-    template <class> friend class _LIBCPP_VISIBLE __map_const_iterator;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS set;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS multiset;
+    template <class> friend class _LIBCPP_TYPE_VIS __map_const_iterator;
 };
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -779,8 +781,10 @@
     typedef typename __alloc_traits::size_type       size_type;
     typedef typename __alloc_traits::difference_type difference_type;
 
-    typedef __tree_node<value_type, typename __alloc_traits::void_pointer> __node;
-    typedef __tree_node_base<typename __alloc_traits::void_pointer> __node_base;
+    typedef typename __alloc_traits::void_pointer  __void_pointer;
+
+    typedef __tree_node<value_type, __void_pointer> __node;
+    typedef __tree_node_base<__void_pointer>        __node_base;
     typedef typename __alloc_traits::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind_alloc<__node>
@@ -790,9 +794,9 @@
                                                      __node_allocator;
     typedef allocator_traits<__node_allocator>       __node_traits;
     typedef typename __node_traits::pointer          __node_pointer;
-    typedef typename __node_traits::const_pointer    __node_const_pointer;
+    typedef typename __node_traits::pointer          __node_const_pointer;
     typedef typename __node_base::pointer            __node_base_pointer;
-    typedef typename __node_base::const_pointer      __node_base_const_pointer;
+    typedef typename __node_base::pointer            __node_base_const_pointer;
 private:
     typedef typename __node_base::base __end_node_t;
     typedef typename pointer_traits<__node_pointer>::template
@@ -804,9 +808,9 @@
                                                      __end_node_ptr;
     typedef typename pointer_traits<__node_pointer>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-            rebind<const __end_node_t>
+            rebind<__end_node_t>
 #else
-            rebind<const __end_node_t>::other
+            rebind<__end_node_t>::other
 #endif
                                                      __end_node_const_ptr;
 
@@ -828,7 +832,7 @@
     {
         return static_cast<__node_const_pointer>
                (
-                   pointer_traits<__end_node_const_ptr>::pointer_to(__pair1_.first())
+                   pointer_traits<__end_node_const_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first()))
                );
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -865,7 +869,7 @@
         {return static_cast<__node_const_pointer>(__end_node()->__left_);}
 
     typedef __tree_iterator<value_type, __node_pointer, difference_type>             iterator;
-    typedef __tree_const_iterator<value_type, __node_const_pointer, difference_type> const_iterator;
+    typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator;
 
     explicit __tree(const value_compare& __comp)
         _NOEXCEPT_(
@@ -1102,6 +1106,9 @@
 
     __node_pointer __detach();
     static __node_pointer __detach(__node_pointer);
+
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
 };
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -1161,7 +1168,7 @@
 {
     if (__cache->__parent_ == nullptr)
         return nullptr;
-    if (__tree_is_left_child(__cache))
+    if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache)))
     {
         __cache->__parent_->__left_ = nullptr;
         __cache = static_cast<__node_pointer>(__cache->__parent_);
@@ -1294,7 +1301,7 @@
         __begin_node() = __end_node();
     else
     {
-        __end_node()->__left_->__parent_ = __end_node();
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
         __t.__begin_node() = __t.__end_node();
         __t.__end_node()->__left_ = nullptr;
         __t.size() = 0;
@@ -1314,7 +1321,7 @@
         {
             __begin_node() = __t.__begin_node();
             __end_node()->__left_ = __t.__end_node()->__left_;
-            __end_node()->__left_->__parent_ = __end_node();
+            __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
             size() = __t.size();
             __t.__begin_node() = __t.__end_node();
             __t.__end_node()->__left_ = nullptr;
@@ -1342,7 +1349,7 @@
         __begin_node() = __end_node();
     else
     {
-        __end_node()->__left_->__parent_ = __end_node();
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
         __t.__begin_node() = __t.__end_node();
         __t.__end_node()->__left_ = nullptr;
         __t.size() = 0;
@@ -1447,11 +1454,11 @@
     if (size() == 0)
         __begin_node() = __end_node();
     else
-        __end_node()->__left_->__parent_ = __end_node();
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
     if (__t.size() == 0)
         __t.__begin_node() = __t.__end_node();
     else
-        __t.__end_node()->__left_->__parent_ = __t.__end_node();
+        __t.__end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__t.__end_node());
 }
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -1483,7 +1490,7 @@
                     __nd = static_cast<__node_pointer>(__nd->__right_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__right_;
                 }
             }
@@ -1493,13 +1500,13 @@
                     __nd = static_cast<__node_pointer>(__nd->__left_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__left_;
                 }
             }
         }
     }
-    __parent = __end_node();
+    __parent = static_cast<__node_base_pointer>(__end_node());
     return __parent->__left_;
 }
 
@@ -1522,7 +1529,7 @@
                     __nd = static_cast<__node_pointer>(__nd->__left_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__left_;
                 }
             }
@@ -1532,13 +1539,13 @@
                     __nd = static_cast<__node_pointer>(__nd->__right_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__right_;
                 }
             }
         }
     }
-    __parent = __end_node();
+    __parent = static_cast<__node_base_pointer>(__end_node());
     return __parent->__left_;
 }
 
@@ -1563,12 +1570,12 @@
             // *prev(__hint) <= __v <= *__hint
             if (__hint.__ptr_->__left_ == nullptr)
             {
-                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
                 return __parent->__left_;
             }
             else
             {
-                __parent = const_cast<__node_pointer&>(__prior.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__prior.__ptr_);
                 return __parent->__right_;
             }
         }
@@ -1600,7 +1607,7 @@
                     __nd = static_cast<__node_pointer>(__nd->__left_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__left_;
                 }
             }
@@ -1610,18 +1617,18 @@
                     __nd = static_cast<__node_pointer>(__nd->__right_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__right_;
                 }
             }
             else
             {
-                __parent = __nd;
+                __parent = static_cast<__node_base_pointer>(__nd);
                 return __parent;
             }
         }
     }
-    __parent = __end_node();
+    __parent = static_cast<__node_base_pointer>(__end_node());
     return __parent->__left_;
 }
 
@@ -1648,12 +1655,12 @@
             // *prev(__hint) < __v < *__hint
             if (__hint.__ptr_->__left_ == nullptr)
             {
-                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
                 return __parent->__left_;
             }
             else
             {
-                __parent = const_cast<__node_pointer&>(__prior.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__prior.__ptr_);
                 return __parent->__right_;
             }
         }
@@ -1669,12 +1676,12 @@
             // *__hint < __v < *_VSTD::next(__hint)
             if (__hint.__ptr_->__right_ == nullptr)
             {
-                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
                 return __parent->__right_;
             }
             else
             {
-                __parent = const_cast<__node_pointer&>(__next.__ptr_);
+                __parent = static_cast<__node_base_pointer>(__next.__ptr_);
                 return __parent->__left_;
             }
         }
@@ -1682,7 +1689,7 @@
         return __find_equal(__parent, __v);
     }
     // else __v == *__hint
-    __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+    __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
     return __parent;
 }
 
@@ -1729,7 +1736,7 @@
     bool __inserted = false;
     if (__child == nullptr)
     {
-        __insert_node_at(__parent, __child, __h.get());
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
         __inserted = true;
     }
@@ -1747,7 +1754,7 @@
     __node_pointer __r = static_cast<__node_pointer>(__child);
     if (__child == nullptr)
     {
-        __insert_node_at(__parent, __child, __h.get());
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
     }
     return iterator(__r);
@@ -1761,7 +1768,7 @@
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(static_cast<__node_pointer>(__h.release()));
 }
 
@@ -1774,7 +1781,7 @@
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(static_cast<__node_pointer>(__h.release()));
 }
 
@@ -1812,7 +1819,7 @@
     __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(__h.release());
 }
 
@@ -1824,7 +1831,7 @@
     __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(__h.release());
 }
 
@@ -1854,7 +1861,7 @@
     if (__child == nullptr)
     {
         __node_holder __h = __construct_node(__v);
-        __insert_node_at(__parent, __child, __h.get());
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
         __inserted = true;
     }
@@ -1871,7 +1878,7 @@
     if (__child == nullptr)
     {
         __node_holder __h = __construct_node(__v);
-        __insert_node_at(__parent, __child, __h.get());
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
     }
     return iterator(__r);
@@ -1884,7 +1891,7 @@
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf_high(__parent, __v);
     __node_holder __h = __construct_node(__v);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(__h.release());
 }
 
@@ -1895,7 +1902,7 @@
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf(__p, __parent, __v);
     __node_holder __h = __construct_node(__v);
-    __insert_node_at(__parent, __child, __h.get());
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(__h.release());
 }
 
@@ -1909,7 +1916,7 @@
     bool __inserted = false;
     if (__child == nullptr)
     {
-        __insert_node_at(__parent, __child, __nd);
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
         __r = __nd;
         __inserted = true;
     }
@@ -1926,7 +1933,7 @@
     __node_pointer __r = static_cast<__node_pointer>(__child);
     if (__child == nullptr)
     {
-        __insert_node_at(__parent, __child, __nd);
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
         __r = __nd;
     }
     return iterator(__r);
@@ -1938,7 +1945,7 @@
 {
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_);
-    __insert_node_at(__parent, __child, __nd);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
     return iterator(__nd);
 }
 
@@ -1949,7 +1956,7 @@
 {
     __node_base_pointer __parent;
     __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_);
-    __insert_node_at(__parent, __child, __nd);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
     return iterator(__nd);
 }
 
@@ -1957,7 +1964,7 @@
 typename __tree<_Tp, _Compare, _Allocator>::iterator
 __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p)
 {
-    __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer __np = __p.__ptr_;
     iterator __r(__np);
     ++__r;
     if (__begin_node() == __np)
@@ -1977,7 +1984,7 @@
 {
     while (__f != __l)
         __f = erase(__f);
-    return iterator(const_cast<__node_pointer>(__l.__ptr_));
+    return iterator(__l.__ptr_);
 }
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -2264,7 +2271,7 @@
 typename __tree<_Tp, _Compare, _Allocator>::__node_holder
 __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT
 {
-    __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer __np = __p.__ptr_;
     if (__begin_node() == __np)
     {
         if (__np->__right_ != nullptr)

Modified: trunk/contrib/libc++/include/__tuple
===================================================================
--- trunk/contrib/libc++/include/__tuple	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__tuple	2016-01-07 17:22:14 UTC (rev 7405)
@@ -27,24 +27,24 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp> class _LIBCPP_VISIBLE tuple_size;
+template <class _Tp> class _LIBCPP_TYPE_VIS tuple_size;
 
 template <class _Tp>
-class _LIBCPP_VISIBLE tuple_size<const _Tp>
+class _LIBCPP_TYPE_VIS tuple_size<const _Tp>
     : public tuple_size<_Tp> {};
 
 template <class _Tp>
-class _LIBCPP_VISIBLE tuple_size<volatile _Tp>
+class _LIBCPP_TYPE_VIS tuple_size<volatile _Tp>
     : public tuple_size<_Tp> {};
 
 template <class _Tp>
-class _LIBCPP_VISIBLE tuple_size<const volatile _Tp>
+class _LIBCPP_TYPE_VIS tuple_size<const volatile _Tp>
     : public tuple_size<_Tp> {};
 
-template <size_t _Ip, class _Tp> class _LIBCPP_VISIBLE tuple_element;
+template <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS tuple_element;
 
 template <size_t _Ip, class _Tp>
-class _LIBCPP_VISIBLE tuple_element<_Ip, const _Tp>
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, const _Tp>
 {
 public:
     typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
@@ -51,7 +51,7 @@
 };
 
 template <size_t _Ip, class _Tp>
-class _LIBCPP_VISIBLE tuple_element<_Ip, volatile _Tp>
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, volatile _Tp>
 {
 public:
     typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
@@ -58,15 +58,15 @@
 };
 
 template <size_t _Ip, class _Tp>
-class _LIBCPP_VISIBLE tuple_element<_Ip, const volatile _Tp>
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, const volatile _Tp>
 {
 public:
     typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
 };
 
-template <class ..._Tp> class _LIBCPP_VISIBLE tuple;
-template <class _T1, class _T2> struct _LIBCPP_VISIBLE pair;
-template <class _Tp, size_t _Size> struct _LIBCPP_VISIBLE array;
+template <class ..._Tp> class _LIBCPP_TYPE_VIS tuple;
+template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS pair;
+template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS array;
 
 template <class _Tp> struct __tuple_like : false_type {};
 
@@ -79,38 +79,47 @@
 template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
 
 template <size_t _Ip, class ..._Tp>
+_LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, tuple<_Tp...> >::type&
 get(tuple<_Tp...>&) _NOEXCEPT;
 
 template <size_t _Ip, class ..._Tp>
+_LIBCPP_INLINE_VISIBILITY
 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
 get(const tuple<_Tp...>&) _NOEXCEPT;
 
 template <size_t _Ip, class ..._Tp>
+_LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
 get(tuple<_Tp...>&&) _NOEXCEPT;
 
 template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
 get(pair<_T1, _T2>&) _NOEXCEPT;
 
 template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY
 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
 get(const pair<_T1, _T2>&) _NOEXCEPT;
 
 template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY
 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
 get(pair<_T1, _T2>&&) _NOEXCEPT;
 
 template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY
 _Tp&
 get(array<_Tp, _Size>&) _NOEXCEPT;
 
 template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY
 const _Tp&
 get(const array<_Tp, _Size>&) _NOEXCEPT;
 
 template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY
 _Tp&&
 get(array<_Tp, _Size>&&) _NOEXCEPT;
 
@@ -145,7 +154,7 @@
 template <class ..._Tp> struct __tuple_types {};
 
 template <size_t _Ip>
-class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<> >
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, __tuple_types<> >
 {
 public:
     static_assert(_Ip == 0, "tuple_element index out of range");
@@ -153,7 +162,7 @@
 };
 
 template <class _Hp, class ..._Tp>
-class _LIBCPP_VISIBLE tuple_element<0, __tuple_types<_Hp, _Tp...> >
+class _LIBCPP_TYPE_VIS tuple_element<0, __tuple_types<_Hp, _Tp...> >
 {
 public:
     typedef _Hp type;
@@ -160,7 +169,7 @@
 };
 
 template <size_t _Ip, class _Hp, class ..._Tp>
-class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<_Hp, _Tp...> >
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, __tuple_types<_Hp, _Tp...> >
 {
 public:
     typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type;
@@ -167,7 +176,7 @@
 };
 
 template <class ..._Tp>
-class _LIBCPP_VISIBLE tuple_size<__tuple_types<_Tp...> >
+class _LIBCPP_TYPE_VIS tuple_size<__tuple_types<_Tp...> >
     : public integral_constant<size_t, sizeof...(_Tp)>
 {
 };

Modified: trunk/contrib/libc++/include/__tuple_03
===================================================================
--- trunk/contrib/libc++/include/__tuple_03	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__tuple_03	2016-01-07 17:22:14 UTC (rev 7405)
@@ -19,8 +19,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp> class _LIBCPP_VISIBLE tuple_size;
-template <size_t _Ip, class _Tp> class _LIBCPP_VISIBLE tuple_element;
+template <class _Tp> class _LIBCPP_TYPE_VIS tuple_size;
+template <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS tuple_element;
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/__undef_min_max
===================================================================
--- trunk/contrib/libc++/include/__undef_min_max	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/__undef_min_max	2016-01-07 17:22:14 UTC (rev 7405)
@@ -9,11 +9,11 @@
 //===----------------------------------------------------------------------===//
 
 #ifdef min
-#warning: macro min is incompatible with C++.  #undef'ing min
+#warning: macro min is incompatible with C++.  #undefing min
 #undef min
 #endif
 
 #ifdef max
-#warning: macro max is incompatible with C++.  #undef'ing max
+#warning: macro max is incompatible with C++.  #undefing max
 #undef max
 #endif

Modified: trunk/contrib/libc++/include/algorithm
===================================================================
--- trunk/contrib/libc++/include/algorithm	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/algorithm	2016-01-07 17:22:14 UTC (rev 7405)
@@ -87,30 +87,63 @@
     pair<InputIterator1, InputIterator2>
     mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
 
+template <class InputIterator1, class InputIterator2>
+    pair<InputIterator1, InputIterator2>
+    mismatch(InputIterator1 first1, InputIterator1 last1, 
+             InputIterator2 first2, InputIterator2 last2); // **C++14**
+
 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
     pair<InputIterator1, InputIterator2>
     mismatch(InputIterator1 first1, InputIterator1 last1,
              InputIterator2 first2, BinaryPredicate pred);
 
+template <class InputIterator1, class InputIterator2, class BinaryPredicate>
+    pair<InputIterator1, InputIterator2>
+    mismatch(InputIterator1 first1, InputIterator1 last1,
+             InputIterator2 first2, InputIterator2 last2,
+             BinaryPredicate pred); // **C++14**
+
 template <class InputIterator1, class InputIterator2>
     bool
     equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
 
+template <class InputIterator1, class InputIterator2>
+    bool
+    equal(InputIterator1 first1, InputIterator1 last1, 
+          InputIterator2 first2, InputIterator2 last2); // **C++14**
+
 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
     bool
     equal(InputIterator1 first1, InputIterator1 last1,
           InputIterator2 first2, BinaryPredicate pred);
 
+template <class InputIterator1, class InputIterator2, class BinaryPredicate>
+    bool
+    equal(InputIterator1 first1, InputIterator1 last1,
+          InputIterator2 first2, InputIterator2 last2,
+          BinaryPredicate pred); // **C++14**
+
 template<class ForwardIterator1, class ForwardIterator2>
     bool
     is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
                    ForwardIterator2 first2);
 
+template<class ForwardIterator1, class ForwardIterator2>
+    bool
+    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+                   ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
+
 template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
     bool
     is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
                    ForwardIterator2 first2, BinaryPredicate pred);
 
+template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+    bool
+    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+                   ForwardIterator2 first2, ForwardIterator2 last2,
+                   BinaryPredicate pred);  // **C++14**
+
 template <class ForwardIterator1, class ForwardIterator2>
     ForwardIterator1
     search(ForwardIterator1 first1, ForwardIterator1 last1,
@@ -593,7 +626,7 @@
 #include <utility>
 #include <memory>
 #include <iterator>
-#include <cstdlib>
+#include <cstddef>
 
 #include <__undef_min_max>
 
@@ -1087,6 +1120,32 @@
     return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+         _InputIterator2 __first2, _InputIterator2 __last2,
+         _BinaryPredicate __pred)
+{
+    for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            break;
+    return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+         _InputIterator2 __first2, _InputIterator2 __last2)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type __v1;
+    typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+    return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+}
+#endif
+
 // equal
 
 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -1110,6 +1169,60 @@
     return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
 }
 
+#if _LIBCPP_STD_VER > 11
+template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__equal(_InputIterator1 __first1, _InputIterator1 __last1, 
+        _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred,
+        input_iterator_tag, input_iterator_tag )
+{
+    for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            return false;
+    return __first1 == __last1 && __first2 == __last2;
+}
+
+template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, 
+        _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, 
+      random_access_iterator_tag, random_access_iterator_tag )
+{
+    if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
+        return false;
+    return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
+                        typename add_lvalue_reference<_BinaryPredicate>::type>
+                       (__first1, __last1, __first2, __pred );
+}
+
+template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+equal(_InputIterator1 __first1, _InputIterator1 __last1, 
+      _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred )
+{
+    return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>
+       (__first1, __last1, __first2, __last2, __pred, 
+        typename iterator_traits<_InputIterator1>::iterator_category(),
+        typename iterator_traits<_InputIterator2>::iterator_category());
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+equal(_InputIterator1 __first1, _InputIterator1 __last1, 
+      _InputIterator2 __first2, _InputIterator2 __last2)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type __v1;
+    typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+    return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(),
+        typename iterator_traits<_InputIterator1>::iterator_category(),
+        typename iterator_traits<_InputIterator2>::iterator_category());
+}
+#endif
+
 // is_permutation
 
 template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -1169,6 +1282,100 @@
     return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
 }
 
+#if _LIBCPP_STD_VER > 11
+template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
+bool
+__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+                 _ForwardIterator2 __first2, _ForwardIterator2 __last2, 
+                 _BinaryPredicate __pred,
+                 forward_iterator_tag, forward_iterator_tag )
+{
+    // shorten sequences as much as possible by lopping of any equal parts
+    for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            goto __not_done;
+    return __first1 == __last1 && __first2 == __last2;
+__not_done:
+    // __first1 != __last1 && __first2 != __last2 && *__first1 != *__first2
+    typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
+    _D1 __l1 = _VSTD::distance(__first1, __last1);
+
+    typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2;
+    _D2 __l2 = _VSTD::distance(__first2, __last2);
+    if (__l1 != __l2)
+        return false;
+
+    // For each element in [f1, l1) see if there are the same number of
+    //    equal elements in [f2, l2)
+    for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
+    {
+        // Have we already counted the number of *__i in [f1, l1)?
+        for (_ForwardIterator1 __j = __first1; __j != __i; ++__j)
+            if (__pred(*__j, *__i))
+                goto __next_iter;
+        {
+            // Count number of *__i in [f2, l2)
+            _D1 __c2 = 0;
+            for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
+                if (__pred(*__i, *__j))
+                    ++__c2;
+            if (__c2 == 0)
+                return false;
+            // Count number of *__i in [__i, l1) (we can start with 1)
+            _D1 __c1 = 1;
+            for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
+                if (__pred(*__i, *__j))
+                    ++__c1;
+            if (__c1 != __c2)
+                return false;
+        }
+__next_iter:;
+    }
+    return true;
+}
+
+template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
+bool
+__is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1,
+               _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, 
+               _BinaryPredicate __pred,
+               random_access_iterator_tag, random_access_iterator_tag )
+{
+    if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
+        return false;
+    return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
+                                 typename add_lvalue_reference<_BinaryPredicate>::type>
+                                (__first1, __last1, __first2, __pred );
+}
+
+template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+               _ForwardIterator2 __first2, _ForwardIterator2 __last2,
+               _BinaryPredicate __pred )
+{
+    return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>
+       (__first1, __last1, __first2, __last2, __pred,
+        typename iterator_traits<_ForwardIterator1>::iterator_category(),
+        typename iterator_traits<_ForwardIterator2>::iterator_category());
+}
+
+template<class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+               _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+{
+    typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
+    return _VSTD::__is_permutation(__first1, __last1, __first2, __last2,
+        __equal_to<__v1, __v2>(),
+        typename iterator_traits<_ForwardIterator1>::iterator_category(),
+        typename iterator_traits<_ForwardIterator2>::iterator_category());
+}
+#endif
+
 // search
 
 template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
@@ -1398,7 +1605,7 @@
         // Find first element in sequence that matchs __value_, with a mininum of loop checks
         while (true)
         {
-            if (__first == __s)  // return __last if no element matches __value_
+            if (__first >= __s)  // return __last if no element matches __value_
                 return __last;
             if (__pred(*__first, __value_))
                 break;
@@ -1528,10 +1735,10 @@
 
 // copy_backward
 
-template <class _InputIterator, class _OutputIterator>
+template <class _BidirectionalIterator, class _OutputIterator>
 inline _LIBCPP_INLINE_VISIBILITY
 _OutputIterator
-__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
 {
     while (__first != __last)
         *--__result = *--__last;
@@ -2103,12 +2310,31 @@
 
 template <class _ForwardIterator>
 _ForwardIterator
-__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, false_type)
+__rotate_left(_ForwardIterator __first, _ForwardIterator __last)
 {
-    if (__first == __middle)
-        return __last;
-    if (__middle == __last)
-        return __first;
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    value_type __tmp = _VSTD::move(*__first);
+    _ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first);
+    *__lm1 = _VSTD::move(__tmp);
+    return __lm1;
+}
+
+template <class _BidirectionalIterator>
+_BidirectionalIterator
+__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
+{
+    typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+    _BidirectionalIterator __lm1 = _VSTD::prev(__last);
+    value_type __tmp = _VSTD::move(*__lm1);
+    _BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last);
+    *__first = _VSTD::move(__tmp);
+    return __fp1;
+}
+
+template <class _ForwardIterator>
+_ForwardIterator
+__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
+{
     _ForwardIterator __i = __middle;
     while (true)
     {
@@ -2156,15 +2382,11 @@
 
 template<typename _RandomAccessIterator>
 _RandomAccessIterator
-__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, true_type)
+__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
 
-    if (__first == __middle)
-        return __last;
-    if (__middle == __last)
-        return __first;
     const difference_type __m1 = __middle - __first;
     const difference_type __m2 = __last - __middle;
     if (__m1 == __m2)
@@ -2172,15 +2394,15 @@
         _VSTD::swap_ranges(__first, __middle, __middle);
         return __middle;
     }
-    const difference_type __g = __gcd(__m1, __m2);
+    const difference_type __g = _VSTD::__gcd(__m1, __m2);
     for (_RandomAccessIterator __p = __first + __g; __p != __first;)
     {
-        value_type __t(*--__p);
+        value_type __t(_VSTD::move(*--__p));
         _RandomAccessIterator __p1 = __p;
         _RandomAccessIterator __p2 = __p1 + __m1;
         do
         {
-            *__p1 = *__p2;
+            *__p1 = _VSTD::move(*__p2);
             __p1 = __p2;
             const difference_type __d = __last - __p2;
             if (__m1 < __d)
@@ -2188,7 +2410,7 @@
             else
                 __p2 = __first + (__m1 - __d);
         } while (__p2 != __p);
-        *__p1 = __t;
+        *__p1 = _VSTD::move(__t);
     }
     return __first + __m2;
 }
@@ -2196,22 +2418,64 @@
 template <class _ForwardIterator>
 inline _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator
+__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
+         _VSTD::forward_iterator_tag)
+{
+    typedef typename _VSTD::iterator_traits<_ForwardIterator>::value_type value_type;
+    if (_VSTD::is_trivially_move_assignable<value_type>::value)
+    {
+        if (_VSTD::next(__first) == __middle)
+            return _VSTD::__rotate_left(__first, __last);
+    }
+    return _VSTD::__rotate_forward(__first, __middle, __last);
+}
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_BidirectionalIterator
+__rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
+         _VSTD::bidirectional_iterator_tag)
+{
+    typedef typename _VSTD::iterator_traits<_BidirectionalIterator>::value_type value_type;
+    if (_VSTD::is_trivially_move_assignable<value_type>::value)
+    {
+        if (_VSTD::next(__first) == __middle)
+            return _VSTD::__rotate_left(__first, __last);
+        if (_VSTD::next(__middle) == __last)
+            return _VSTD::__rotate_right(__first, __last);
+    }
+    return _VSTD::__rotate_forward(__first, __middle, __last);
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_RandomAccessIterator
+__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
+         _VSTD::random_access_iterator_tag)
+{
+    typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::value_type value_type;
+    if (_VSTD::is_trivially_move_assignable<value_type>::value)
+    {
+        if (_VSTD::next(__first) == __middle)
+            return _VSTD::__rotate_left(__first, __last);
+        if (_VSTD::next(__middle) == __last)
+            return _VSTD::__rotate_right(__first, __last);
+        return _VSTD::__rotate_gcd(__first, __middle, __last);
+    }
+    return _VSTD::__rotate_forward(__first, __middle, __last);
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
 rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
 {
+    if (__first == __middle)
+        return __last;
+    if (__middle == __last)
+        return __first;
     return _VSTD::__rotate(__first, __middle, __last,
-                          integral_constant
-                          <
-                               bool,
-                               is_convertible
-                               <
-                                   typename iterator_traits<_ForwardIterator>::iterator_category,
-                                   random_access_iterator_tag
-                               >::value &&
-                               is_trivially_copy_assignable
-                               <
-                                   typename iterator_traits<_ForwardIterator>::value_type
-                               >::value
-                           >());
+                           typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category());
 }
 
 // rotate_copy
@@ -2707,7 +2971,7 @@
 
     __rs_default();
 public:
-    typedef unsigned result_type;
+    typedef uint_fast32_t result_type;
 
     static const result_type _Min = 0;
     static const result_type _Max = 0xFFFFFFFF;
@@ -3725,39 +3989,39 @@
 #pragma warning( push )
 #pragma warning( disable: 4231)
 #endif // _MSC_VER
-extern template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
-extern template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
-extern template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
-extern template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
-extern template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
-extern template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
-extern template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
-extern template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
-extern template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
-extern template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
-extern template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
-extern template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
-extern template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
-extern template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
-extern template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<int>&, int*>(int*, int*, __less<int>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<long>&, long*>(long*, long*, __less<long>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<float>&, float*>(float*, float*, __less<float>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<double>&, double*>(double*, double*, __less<double>&))
+_LIBCPP_EXTERN_TEMPLATE(void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
 
-extern template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
-extern template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
-extern template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
-extern template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
-extern template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
-extern template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
-extern template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
-extern template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
-extern template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
-extern template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
-extern template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
-extern template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
-extern template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
-extern template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
-extern template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&))
+_LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
 
-extern template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
+_LIBCPP_EXTERN_TEMPLATE(unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&))
 #ifdef _MSC_VER
 #pragma warning( pop )
 #endif  // _MSC_VER

Modified: trunk/contrib/libc++/include/array
===================================================================
--- trunk/contrib/libc++/include/array	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/array	2016-01-07 17:22:14 UTC (rev 7405)
@@ -55,7 +55,7 @@
     // capacity:
     constexpr size_type size() const noexcept;
     constexpr size_type max_size() const noexcept;
-    bool empty() const noexcept;
+    constexpr bool empty() const noexcept;
 
     // element access:
     reference operator[](size_type n);
@@ -118,7 +118,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp, size_t _Size>
-struct _LIBCPP_VISIBLE array
+struct _LIBCPP_TYPE_VIS array
 {
     // types:
     typedef array __self;
@@ -173,11 +173,11 @@
 
     // capacity:
     _LIBCPP_INLINE_VISIBILITY
-    /*constexpr*/ size_type size() const _NOEXCEPT {return _Size;}
+    _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
     _LIBCPP_INLINE_VISIBILITY
-    /*constexpr*/ size_type max_size() const _NOEXCEPT {return _Size;}
+    _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
     _LIBCPP_INLINE_VISIBILITY
-    bool empty() const _NOEXCEPT {return _Size == 0;}
+    _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
 
     // element access:
     _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n)             {return __elems_[__n];}
@@ -284,15 +284,15 @@
 }
 
 template <class _Tp, size_t _Size>
-class _LIBCPP_VISIBLE tuple_size<array<_Tp, _Size> >
+class _LIBCPP_TYPE_VIS tuple_size<array<_Tp, _Size> >
     : public integral_constant<size_t, _Size> {};
 
 template <class _Tp, size_t _Size>
-class _LIBCPP_VISIBLE tuple_size<const array<_Tp, _Size> >
+class _LIBCPP_TYPE_VIS tuple_size<const array<_Tp, _Size> >
     : public integral_constant<size_t, _Size> {};
 
 template <size_t _Ip, class _Tp, size_t _Size>
-class _LIBCPP_VISIBLE tuple_element<_Ip, array<_Tp, _Size> >
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, array<_Tp, _Size> >
 {
 public:
     typedef _Tp type;
@@ -299,7 +299,7 @@
 };
 
 template <size_t _Ip, class _Tp, size_t _Size>
-class _LIBCPP_VISIBLE tuple_element<_Ip, const array<_Tp, _Size> >
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, const array<_Tp, _Size> >
 {
 public:
     typedef const _Tp type;
@@ -310,6 +310,7 @@
 _Tp&
 get(array<_Tp, _Size>& __a) _NOEXCEPT
 {
+    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
     return __a[_Ip];
 }
 
@@ -318,6 +319,7 @@
 const _Tp&
 get(const array<_Tp, _Size>& __a) _NOEXCEPT
 {
+    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
     return __a[_Ip];
 }
 
@@ -328,6 +330,7 @@
 _Tp&&
 get(array<_Tp, _Size>&& __a) _NOEXCEPT
 {
+    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
     return _VSTD::move(__a[_Ip]);
 }
 

Modified: trunk/contrib/libc++/include/atomic
===================================================================
--- trunk/contrib/libc++/include/atomic	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/atomic	2016-01-07 17:22:14 UTC (rev 7405)
@@ -33,6 +33,7 @@
 
 // lock-free property
 
+#define ATOMIC_BOOL_LOCK_FREE unspecified
 #define ATOMIC_CHAR_LOCK_FREE unspecified
 #define ATOMIC_CHAR16_T_LOCK_FREE unspecified
 #define ATOMIC_CHAR32_T_LOCK_FREE unspecified
@@ -41,6 +42,7 @@
 #define ATOMIC_INT_LOCK_FREE unspecified
 #define ATOMIC_LONG_LOCK_FREE unspecified
 #define ATOMIC_LLONG_LOCK_FREE unspecified
+#define ATOMIC_POINTER_LOCK_FREE unspecified
 
 // flag type and operations
 
@@ -472,6 +474,7 @@
 
 // Atomics for standard typedef types
 
+typedef atomic<bool>               atomic_bool;
 typedef atomic<char>               atomic_char;
 typedef atomic<signed char>        atomic_schar;
 typedef atomic<unsigned char>      atomic_uchar;
@@ -555,7 +558,7 @@
 template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
 struct __atomic_base  // false
 {
-    _Atomic(_Tp) __a_;
+    mutable _Atomic(_Tp) __a_;
 
     _LIBCPP_INLINE_VISIBILITY
     bool is_lock_free() const volatile _NOEXCEPT
@@ -619,7 +622,12 @@
         {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
 
     _LIBCPP_INLINE_VISIBILITY
-    __atomic_base() _NOEXCEPT {} // = default;
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+    __atomic_base() _NOEXCEPT = default;
+#else
+    __atomic_base() _NOEXCEPT : __a_() {}
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
@@ -642,7 +650,7 @@
 {
     typedef __atomic_base<_Tp, false> __base;
     _LIBCPP_INLINE_VISIBILITY
-    __atomic_base() _NOEXCEPT {} // = default;
+    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
 
@@ -723,7 +731,7 @@
 {
     typedef __atomic_base<_Tp> __base;
     _LIBCPP_INLINE_VISIBILITY
-    atomic() _NOEXCEPT {} // = default;
+    atomic() _NOEXCEPT _LIBCPP_DEFAULT
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
 
@@ -743,7 +751,7 @@
 {
     typedef __atomic_base<_Tp*> __base;
     _LIBCPP_INLINE_VISIBILITY
-    atomic() _NOEXCEPT {} // = default;
+    atomic() _NOEXCEPT _LIBCPP_DEFAULT
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
 
@@ -1364,7 +1372,12 @@
         {__c11_atomic_store(&__a_, false, __m);}
 
     _LIBCPP_INLINE_VISIBILITY
-    atomic_flag() _NOEXCEPT {} // = default;
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+    atomic_flag() _NOEXCEPT = default;
+#else
+    atomic_flag() _NOEXCEPT : __a_() {}
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
     _LIBCPP_INLINE_VISIBILITY
     atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
 
@@ -1454,6 +1467,7 @@
 
 // Atomics for standard typedef types
 
+typedef atomic<bool>               atomic_bool;
 typedef atomic<char>               atomic_char;
 typedef atomic<signed char>        atomic_schar;
 typedef atomic<unsigned char>      atomic_uchar;
@@ -1499,14 +1513,16 @@
 
 // lock-free property
 
-#define ATOMIC_CHAR_LOCK_FREE 0
-#define ATOMIC_CHAR16_T_LOCK_FREE 0
-#define ATOMIC_CHAR32_T_LOCK_FREE 0
-#define ATOMIC_WCHAR_T_LOCK_FREE 0
-#define ATOMIC_SHORT_LOCK_FREE 0
-#define ATOMIC_INT_LOCK_FREE 0
-#define ATOMIC_LONG_LOCK_FREE 0
-#define ATOMIC_LLONG_LOCK_FREE 0
+#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
+#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
+#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
+#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
+#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
+#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
+#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
 
 #endif  //  !__has_feature(cxx_atomic)
 

Modified: trunk/contrib/libc++/include/bitset
===================================================================
--- trunk/contrib/libc++/include/bitset	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/bitset	2016-01-07 17:22:14 UTC (rev 7405)
@@ -148,9 +148,9 @@
 public:
     typedef ptrdiff_t              difference_type;
     typedef size_t                 size_type;
+    typedef size_type              __storage_type;
 protected:
     typedef __bitset __self;
-    typedef size_type              __storage_type;
     typedef       __storage_type*  __storage_pointer;
     typedef const __storage_type*  __const_storage_pointer;
     static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
@@ -159,7 +159,7 @@
     friend class __bit_const_reference<__bitset>;
     friend class __bit_iterator<__bitset, false>;
     friend class __bit_iterator<__bitset, true>;
-    friend class __bit_array<__bitset>;
+    friend struct __bit_array<__bitset>;
 
     __storage_type __first_[_N_words];
 
@@ -168,12 +168,12 @@
     typedef __bit_iterator<__bitset, false>            iterator;
     typedef __bit_iterator<__bitset, true>             const_iterator;
 
-    __bitset() _NOEXCEPT;
-    explicit __bitset(unsigned long long __v) _NOEXCEPT;
+    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
+    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
         {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
-    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
         {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
     _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
         {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
@@ -194,8 +194,10 @@
     bool any() const _NOEXCEPT;
     size_t __hash_code() const _NOEXCEPT;
 private:
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
     void __init(unsigned long long __v, false_type) _NOEXCEPT;
     void __init(unsigned long long __v, true_type) _NOEXCEPT;
+#endif  // _LIBCPP_HAS_NO_CONSTEXPR
     unsigned long to_ulong(false_type) const;
     unsigned long to_ulong(true_type) const;
     unsigned long long to_ullong(false_type) const;
@@ -206,11 +208,19 @@
 
 template <size_t _N_words, size_t _Size>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+    : __first_{0}
+#endif
 {
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
     _VSTD::fill_n(__first_, _N_words, __storage_type(0));
+#endif
 }
 
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
+
 template <size_t _N_words, size_t _Size>
 void
 __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
@@ -232,11 +242,25 @@
     _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
 }
 
+#endif  // _LIBCPP_HAS_NO_CONSTEXPR
+
 template <size_t _N_words, size_t _Size>
 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
+    : __first_{__v}
+#elif __SIZE_WIDTH__ == 32
+    : __first_{__v, __v >> __bits_per_word}
+#else
+#error This constructor has not been ported to this platform
+#endif
+#endif
 {
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
     __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
+#endif
 }
 
 template <size_t _N_words, size_t _Size>
@@ -406,9 +430,9 @@
 public:
     typedef ptrdiff_t              difference_type;
     typedef size_t                 size_type;
+    typedef size_type              __storage_type;
 protected:
     typedef __bitset __self;
-    typedef size_type              __storage_type;
     typedef       __storage_type*  __storage_pointer;
     typedef const __storage_type*  __const_storage_pointer;
     static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
@@ -417,7 +441,7 @@
     friend class __bit_const_reference<__bitset>;
     friend class __bit_iterator<__bitset, false>;
     friend class __bit_iterator<__bitset, true>;
-    friend class __bit_array<__bitset>;
+    friend struct __bit_array<__bitset>;
 
     __storage_type __first_;
 
@@ -426,12 +450,12 @@
     typedef __bit_iterator<__bitset, false>            iterator;
     typedef __bit_iterator<__bitset, true>             const_iterator;
 
-    __bitset() _NOEXCEPT;
-    explicit __bitset(unsigned long long __v) _NOEXCEPT;
+    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
+    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
         {return reference(&__first_, __storage_type(1) << __pos);}
-    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
         {return const_reference(&__first_, __storage_type(1) << __pos);}
     _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
         {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
@@ -455,6 +479,7 @@
 
 template <size_t _Size>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 __bitset<1, _Size>::__bitset() _NOEXCEPT
     : __first_(0)
 {
@@ -462,6 +487,7 @@
 
 template <size_t _Size>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
     : __first_(static_cast<__storage_type>(__v))
 {
@@ -549,9 +575,9 @@
 public:
     typedef ptrdiff_t              difference_type;
     typedef size_t                 size_type;
+    typedef size_type              __storage_type;
 protected:
     typedef __bitset __self;
-    typedef size_type              __storage_type;
     typedef       __storage_type*  __storage_pointer;
     typedef const __storage_type*  __const_storage_pointer;
     static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
@@ -567,12 +593,12 @@
     typedef __bit_iterator<__bitset, false>            iterator;
     typedef __bit_iterator<__bitset, true>             const_iterator;
 
-    __bitset() _NOEXCEPT;
-    explicit __bitset(unsigned long long) _NOEXCEPT;
+    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
+    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
         {return reference(0, 1);}
-    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t) const _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
         {return const_reference(0, 1);}
     _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
         {return iterator(0, 0);}
@@ -595,22 +621,25 @@
 };
 
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 __bitset<0, 0>::__bitset() _NOEXCEPT
 {
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
 {
 }
 
-template <size_t _Size> class bitset;
-template <size_t _Size> struct hash<bitset<_Size> >;
+template <size_t _Size> class _LIBCPP_TYPE_VIS bitset;
+template <size_t _Size> struct _LIBCPP_TYPE_VIS hash<bitset<_Size> >;
 
 template <size_t _Size>
-class _LIBCPP_VISIBLE bitset
+class _LIBCPP_TYPE_VIS bitset
     : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
 {
+public:
     static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
     typedef __bitset<__n_words, _Size> base;
 
@@ -619,8 +648,9 @@
     typedef typename base::const_reference const_reference;
 
     // 23.3.5.1 constructors:
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset() _NOEXCEPT {}
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+        bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
     template<class _CharT>
         explicit bitset(const _CharT* __str,
                         typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
@@ -647,7 +677,8 @@
     bitset& flip(size_t __pos);
 
     // element access:
-    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+                              const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
     _LIBCPP_INLINE_VISIBILITY       reference operator[](size_t __p)       {return base::__make_ref(__p);}
     unsigned long to_ulong() const;
     unsigned long long to_ullong() const;
@@ -663,7 +694,7 @@
     basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
                                                                       char __one = '1') const;
     size_t count() const _NOEXCEPT;
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY size_t size() const _NOEXCEPT {return _Size;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
     bool operator==(const bitset& __rhs) const _NOEXCEPT;
     bool operator!=(const bitset& __rhs) const _NOEXCEPT;
     bool test(size_t __pos) const;
@@ -1029,7 +1060,7 @@
 }
 
 template <size_t _Size>
-struct _LIBCPP_VISIBLE hash<bitset<_Size> >
+struct _LIBCPP_TYPE_VIS hash<bitset<_Size> >
     : public unary_function<bitset<_Size>, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY

Modified: trunk/contrib/libc++/include/chrono
===================================================================
--- trunk/contrib/libc++/include/chrono	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/chrono	2016-01-07 17:22:14 UTC (rev 7405)
@@ -20,6 +20,7 @@
 {
 
 template <class ToDuration, class Rep, class Period>
+constexpr
 ToDuration
 duration_cast(const duration<Rep, Period>& fd);
 
@@ -29,9 +30,9 @@
 struct duration_values
 {
 public:
-    static Rep zero();
-    static Rep max();
-    static Rep min();
+    static constexpr Rep zero();
+    static constexpr Rep max();
+    static constexpr Rep min();
 };
 
 // duration
@@ -46,9 +47,9 @@
     typedef Rep rep;
     typedef Period period;
 
-    duration() = default;
+    constexpr duration() = default;
     template <class Rep2>
-        explicit duration(const Rep2& r,
+        constexpr explicit duration(const Rep2& r,
             typename enable_if
             <
                is_convertible<Rep2, rep>::value &&
@@ -58,7 +59,7 @@
 
     // conversions
     template <class Rep2, class Period2>
-        duration(const duration<Rep2, Period2>& d,
+        constexpr duration(const duration<Rep2, Period2>& d,
             typename enable_if
             <
                 treat_as_floating_point<rep>::value ||
@@ -67,12 +68,12 @@
 
     // observer
 
-    rep count() const;
+    constexpr rep count() const;
 
     // arithmetic
 
-    duration  operator+() const;
-    duration  operator-() const;
+    constexpr duration  operator+() const;
+    constexpr duration  operator-() const;
     duration& operator++();
     duration  operator++(int);
     duration& operator--();
@@ -86,9 +87,9 @@
 
     // special values
 
-    static duration zero();
-    static duration min();
-    static duration max();
+    static constexpr duration zero();
+    static constexpr duration min();
+    static constexpr duration max();
 };
 
 typedef duration<long long,         nano> nanoseconds;
@@ -145,36 +146,48 @@
 
 // duration arithmetic
 template <class Rep1, class Period1, class Rep2, class Period2>
+  constexpr
   typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
   operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+  constexpr
   typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
   operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period, class Rep2>
+  constexpr
   duration<typename common_type<Rep1, Rep2>::type, Period>
   operator*(const duration<Rep1, Period>& d, const Rep2& s);
 template <class Rep1, class Period, class Rep2>
+  constexpr
   duration<typename common_type<Rep1, Rep2>::type, Period>
   operator*(const Rep1& s, const duration<Rep2, Period>& d);
 template <class Rep1, class Period, class Rep2>
+  constexpr
   duration<typename common_type<Rep1, Rep2>::type, Period>
   operator/(const duration<Rep1, Period>& d, const Rep2& s);
 template <class Rep1, class Period1, class Rep2, class Period2>
+  constexpr
   typename common_type<Rep1, Rep2>::type
   operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
 // duration comparisons
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 template <class Rep1, class Period1, class Rep2, class Period2>
+   constexpr
    bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
 // duration_cast
@@ -266,7 +279,7 @@
 namespace chrono
 {
 
-template <class _Rep, class _Period = ratio<1> > class _LIBCPP_VISIBLE duration;
+template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS duration;
 
 template <class _Tp>
 struct __is_duration : false_type {};
@@ -286,7 +299,7 @@
 } // chrono
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-struct _LIBCPP_VISIBLE common_type<chrono::duration<_Rep1, _Period1>,
+struct _LIBCPP_TYPE_VIS common_type<chrono::duration<_Rep1, _Period1>,
                                    chrono::duration<_Rep2, _Period2> >
 {
     typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
@@ -306,7 +319,7 @@
 template <class _FromDuration, class _ToDuration, class _Period>
 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
 {
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     _ToDuration operator()(const _FromDuration& __fd) const
     {
         return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
@@ -316,7 +329,7 @@
 template <class _FromDuration, class _ToDuration, class _Period>
 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
 {
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     _ToDuration operator()(const _FromDuration& __fd) const
     {
         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
@@ -328,7 +341,7 @@
 template <class _FromDuration, class _ToDuration, class _Period>
 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
 {
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     _ToDuration operator()(const _FromDuration& __fd) const
     {
         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
@@ -340,7 +353,7 @@
 template <class _FromDuration, class _ToDuration, class _Period>
 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
 {
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     _ToDuration operator()(const _FromDuration& __fd) const
     {
         typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
@@ -352,6 +365,7 @@
 
 template <class _ToDuration, class _Rep, class _Period>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename enable_if
 <
     __is_duration<_ToDuration>::value,
@@ -363,21 +377,21 @@
 }
 
 template <class _Rep>
-struct _LIBCPP_VISIBLE treat_as_floating_point : is_floating_point<_Rep> {};
+struct _LIBCPP_TYPE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
 
 template <class _Rep>
-struct _LIBCPP_VISIBLE duration_values
+struct _LIBCPP_TYPE_VIS duration_values
 {
 public:
-    _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);}
-    _LIBCPP_INLINE_VISIBILITY static _Rep max()  {return numeric_limits<_Rep>::max();}
-    _LIBCPP_INLINE_VISIBILITY static _Rep min()  {return numeric_limits<_Rep>::lowest();}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max()  {return numeric_limits<_Rep>::max();}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  {return numeric_limits<_Rep>::lowest();}
 };
 
 // duration
 
 template <class _Rep, class _Period>
-class _LIBCPP_VISIBLE duration
+class _LIBCPP_TYPE_VIS duration
 {
     static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
     static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
@@ -389,9 +403,9 @@
     rep __rep_;
 public:
 
-    _LIBCPP_INLINE_VISIBILITY duration() {} // = default;
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default;
     template <class _Rep2>
-        _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
         explicit duration(const _Rep2& __r,
             typename enable_if
             <
@@ -403,7 +417,7 @@
 
     // conversions
     template <class _Rep2, class _Period2>
-        _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
         duration(const duration<_Rep2, _Period2>& __d,
             typename enable_if
             <
@@ -415,12 +429,12 @@
 
     // observer
 
-    _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
 
     // arithmetic
 
-    _LIBCPP_INLINE_VISIBILITY duration  operator+() const {return *this;}
-    _LIBCPP_INLINE_VISIBILITY duration  operator-() const {return duration(-__rep_);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration  operator+() const {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration  operator-() const {return duration(-__rep_);}
     _LIBCPP_INLINE_VISIBILITY duration& operator++()      {++__rep_; return *this;}
     _LIBCPP_INLINE_VISIBILITY duration  operator++(int)   {return duration(__rep_++);}
     _LIBCPP_INLINE_VISIBILITY duration& operator--()      {--__rep_; return *this;}
@@ -436,9 +450,9 @@
 
     // special values
 
-    _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values<rep>::zero());}
-    _LIBCPP_INLINE_VISIBILITY static duration min()  {return duration(duration_values<rep>::min());}
-    _LIBCPP_INLINE_VISIBILITY static duration max()  {return duration(duration_values<rep>::max());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min()  {return duration(duration_values<rep>::min());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max()  {return duration(duration_values<rep>::max());}
 };
 
 typedef duration<long long,         nano> nanoseconds;
@@ -453,8 +467,8 @@
 template <class _LhsDuration, class _RhsDuration>
 struct __duration_eq
 {
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
         {
             typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
             return _Ct(__lhs).count() == _Ct(__rhs).count();
@@ -464,13 +478,14 @@
 template <class _LhsDuration>
 struct __duration_eq<_LhsDuration, _LhsDuration>
 {
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
         {return __lhs.count() == __rhs.count();}
 };
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -481,6 +496,7 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -492,8 +508,8 @@
 template <class _LhsDuration, class _RhsDuration>
 struct __duration_lt
 {
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
         {
             typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
             return _Ct(__lhs).count() < _Ct(__rhs).count();
@@ -503,13 +519,14 @@
 template <class _LhsDuration>
 struct __duration_lt<_LhsDuration, _LhsDuration>
 {
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
         {return __lhs.count() < __rhs.count();}
 };
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -520,6 +537,7 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -530,6 +548,7 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -540,6 +559,7 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 bool
 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -550,12 +570,12 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
-    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
-    __r += __rhs;
-    return __r;
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
 }
 
 // Duration -
@@ -562,12 +582,12 @@
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
-    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
-    __r -= __rhs;
-    return __r;
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
 }
 
 // Duration *
@@ -574,6 +594,7 @@
 
 template <class _Rep1, class _Period, class _Rep2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename enable_if
 <
     is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
@@ -582,13 +603,13 @@
 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
 {
     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    duration<_Cr, _Period> __r = __d;
-    __r *= static_cast<_Cr>(__s);
-    return __r;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
 }
 
 template <class _Rep1, class _Period, class _Rep2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename enable_if
 <
     is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
@@ -627,17 +648,18 @@
 
 template <class _Rep1, class _Period, class _Rep2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
 {
     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    duration<_Cr, _Period> __r = __d;
-    __r /= static_cast<_Cr>(__s);
-    return __r;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
 }
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename common_type<_Rep1, _Rep2>::type
 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
@@ -649,23 +671,24 @@
 
 template <class _Rep1, class _Period, class _Rep2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
 {
     typedef typename common_type<_Rep1, _Rep2>::type _Cr;
-    duration<_Cr, _Period> __r = __d;
-    __r %= static_cast<_Cr>(__s);
-    return __r;
+    typedef duration<_Cr, _Period> _Cd;
+    return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
 }
 
 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
-    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
-    __r %= __rhs;
-    return __r;
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
+    return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
 }
 
 //////////////////////////////////////////////////////////
@@ -673,7 +696,7 @@
 //////////////////////////////////////////////////////////
 
 template <class _Clock, class _Duration = typename _Clock::duration>
-class _LIBCPP_VISIBLE time_point
+class _LIBCPP_TYPE_VIS time_point
 {
     static_assert(__is_duration<_Duration>::value,
                   "Second template parameter of time_point must be a std::chrono::duration");
@@ -705,19 +728,19 @@
 
     // arithmetic
 
-    _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d;}
-    _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d;}
+	_LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
+	_LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
 
     // special values
 
-    _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());}
-    _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());}
+    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());}
 };
 
 } // chrono
 
 template <class _Clock, class _Duration1, class _Duration2>
-struct _LIBCPP_VISIBLE common_type<chrono::time_point<_Clock, _Duration1>,
+struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
                                    chrono::time_point<_Clock, _Duration2> >
 {
     typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
@@ -840,7 +863,7 @@
 /////////////////////// clocks ///////////////////////////
 //////////////////////////////////////////////////////////
 
-class _LIBCPP_VISIBLE system_clock
+class _LIBCPP_TYPE_VIS system_clock
 {
 public:
     typedef microseconds                     duration;
@@ -854,7 +877,7 @@
     static time_point from_time_t(time_t __t) _NOEXCEPT;
 };
 
-class _LIBCPP_VISIBLE steady_clock
+class _LIBCPP_TYPE_VIS steady_clock
 {
 public:
     typedef nanoseconds                                   duration;

Modified: trunk/contrib/libc++/include/cmath
===================================================================
--- trunk/contrib/libc++/include/cmath	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cmath	2016-01-07 17:22:14 UTC (rev 7405)
@@ -137,21 +137,21 @@
 
 //  C99
 
-bool signbit(floating_point x);
+bool signbit(arithmetic x);
 
-int fpclassify(floating_point x);
+int fpclassify(arithmetic x);
 
-bool isfinite(floating_point x);
-bool isinf(floating_point x);
-bool isnan(floating_point x);
-bool isnormal(floating_point x);
+bool isfinite(arithmetic x);
+bool isinf(arithmetic x);
+bool isnan(arithmetic x);
+bool isnormal(arithmetic x);
 
-bool isgreater(floating_point x, floating_point y);
-bool isgreaterequal(floating_point x, floating_point y);
-bool isless(floating_point x, floating_point y);
-bool islessequal(floating_point x, floating_point y);
-bool islessgreater(floating_point x, floating_point y);
-bool isunordered(floating_point x, floating_point y);
+bool isgreater(arithmetic x, arithmetic y);
+bool isgreaterequal(arithmetic x, arithmetic y);
+bool isless(arithmetic x, arithmetic y);
+bool islessequal(arithmetic x, arithmetic y);
+bool islessgreater(arithmetic x, arithmetic y);
+bool isunordered(arithmetic x, arithmetic y);
 
 floating_point acosh (arithmetic x);
 float          acoshf(float x);
@@ -316,7 +316,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_signbit(_A1 __x)
+__libcpp_signbit(_A1 __x) _NOEXCEPT
 {
     return signbit(__x);
 }
@@ -325,10 +325,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
-signbit(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+signbit(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_signbit(__x);
+    return __libcpp_signbit((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // signbit
@@ -340,7 +340,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 int
-__libcpp_fpclassify(_A1 __x)
+__libcpp_fpclassify(_A1 __x) _NOEXCEPT
 {
     return fpclassify(__x);
 }
@@ -349,10 +349,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
-fpclassify(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
+fpclassify(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_fpclassify(__x);
+    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // fpclassify
@@ -364,7 +364,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isfinite(_A1 __x)
+__libcpp_isfinite(_A1 __x) _NOEXCEPT
 {
     return isfinite(__x);
 }
@@ -373,10 +373,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
-isfinite(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isfinite(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isfinite(__x);
+    return __libcpp_isfinite((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isfinite
@@ -388,7 +388,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isinf(_A1 __x)
+__libcpp_isinf(_A1 __x) _NOEXCEPT
 {
     return isinf(__x);
 }
@@ -397,10 +397,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
-isinf(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isinf(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isinf(__x);
+    return __libcpp_isinf((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isinf
@@ -412,7 +412,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isnan(_A1 __x)
+__libcpp_isnan(_A1 __x) _NOEXCEPT
 {
     return isnan(__x);
 }
@@ -421,10 +421,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
-isnan(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isnan(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isnan(__x);
+    return __libcpp_isnan((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isnan
@@ -436,7 +436,7 @@
 template <class _A1>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isnormal(_A1 __x)
+__libcpp_isnormal(_A1 __x) _NOEXCEPT
 {
     return isnormal(__x);
 }
@@ -445,10 +445,10 @@
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
-isnormal(_A1 __x)
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isnormal(_A1 __x) _NOEXCEPT
 {
-    return __libcpp_isnormal(__x);
+    return __libcpp_isnormal((typename std::__promote<_A1>::type)__x);
 }
 
 #endif  // isnormal
@@ -460,7 +460,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isgreater(_A1 __x, _A2 __y)
+__libcpp_isgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return isgreater(__x, __y);
 }
@@ -471,13 +471,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-isgreater(_A1 __x, _A2 __y)
+isgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isgreater(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreater((type)__x, (type)__y);
 }
 
 #endif  // isgreater
@@ -489,7 +490,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isgreaterequal(_A1 __x, _A2 __y)
+__libcpp_isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return isgreaterequal(__x, __y);
 }
@@ -500,13 +501,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-isgreaterequal(_A1 __x, _A2 __y)
+isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isgreaterequal(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreaterequal((type)__x, (type)__y);
 }
 
 #endif  // isgreaterequal
@@ -518,7 +520,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isless(_A1 __x, _A2 __y)
+__libcpp_isless(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return isless(__x, __y);
 }
@@ -529,13 +531,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-isless(_A1 __x, _A2 __y)
+isless(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isless(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isless((type)__x, (type)__y);
 }
 
 #endif  // isless
@@ -547,7 +550,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_islessequal(_A1 __x, _A2 __y)
+__libcpp_islessequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return islessequal(__x, __y);
 }
@@ -558,13 +561,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-islessequal(_A1 __x, _A2 __y)
+islessequal(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_islessequal(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessequal((type)__x, (type)__y);
 }
 
 #endif  // islessequal
@@ -576,7 +580,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_islessgreater(_A1 __x, _A2 __y)
+__libcpp_islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return islessgreater(__x, __y);
 }
@@ -587,13 +591,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-islessgreater(_A1 __x, _A2 __y)
+islessgreater(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_islessgreater(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessgreater((type)__x, (type)__y);
 }
 
 #endif  // islessgreater
@@ -605,7 +610,7 @@
 template <class _A1, class _A2>
 _LIBCPP_ALWAYS_INLINE
 bool
-__libcpp_isunordered(_A1 __x, _A2 __y)
+__libcpp_isunordered(_A1 __x, _A2 __y) _NOEXCEPT
 {
     return isunordered(__x, __y);
 }
@@ -616,13 +621,14 @@
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if
 <
-    std::is_floating_point<_A1>::value &&
-    std::is_floating_point<_A2>::value,
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
     bool
 >::type
-isunordered(_A1 __x, _A2 __y)
+isunordered(_A1 __x, _A2 __y) _NOEXCEPT
 {
-    return __libcpp_isunordered(__x, __y);
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isunordered((type)__x, (type)__y);
 }
 
 #endif  // isunordered
@@ -650,15 +656,15 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 float
-abs(float __x) {return fabsf(__x);}
+abs(float __x) _NOEXCEPT {return fabsf(__x);}
 
 inline _LIBCPP_INLINE_VISIBILITY
 double
-abs(double __x) {return fabs(__x);}
+abs(double __x) _NOEXCEPT {return fabs(__x);}
 
 inline _LIBCPP_INLINE_VISIBILITY
 long double
-abs(long double __x) {return fabsl(__x);}
+abs(long double __x) _NOEXCEPT {return fabsl(__x);}
 
 #ifndef __sun__
 
@@ -668,14 +674,14 @@
 using ::acosf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       acos(float __x)       {return acosf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) {return acosl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-acos(_A1 __x) {return acos((double)__x);}
+acos(_A1 __x) _NOEXCEPT {return acos((double)__x);}
 
 // asin
 
@@ -683,14 +689,14 @@
 using ::asinf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       asin(float __x)       {return asinf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) {return asinl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-asin(_A1 __x) {return asin((double)__x);}
+asin(_A1 __x) _NOEXCEPT {return asin((double)__x);}
 
 // atan
 
@@ -698,14 +704,14 @@
 using ::atanf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       atan(float __x)       {return atanf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) {return atanl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-atan(_A1 __x) {return atan((double)__x);}
+atan(_A1 __x) _NOEXCEPT {return atan((double)__x);}
 
 // atan2
 
@@ -713,8 +719,8 @@
 using ::atan2f;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __y, float __x)             {return atan2f(__y, __x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) {return atan2l(__y, __x);}
+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);}
 #endif
 
 template <class _A1, class _A2>
@@ -725,7 +731,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-atan2(_A1 __y, _A2 __x)
+atan2(_A1 __y, _A2 __x) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -739,14 +745,14 @@
 using ::ceilf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __x)       {return ceilf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) {return ceill(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-ceil(_A1 __x) {return ceil((double)__x);}
+ceil(_A1 __x) _NOEXCEPT {return ceil((double)__x);}
 
 // cos
 
@@ -754,14 +760,14 @@
 using ::cosf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       cos(float __x)       {return cosf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) {return cosl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cos(_A1 __x) {return cos((double)__x);}
+cos(_A1 __x) _NOEXCEPT {return cos((double)__x);}
 
 // cosh
 
@@ -769,14 +775,14 @@
 using ::coshf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __x)       {return coshf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) {return coshl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cosh(_A1 __x) {return cosh((double)__x);}
+cosh(_A1 __x) _NOEXCEPT {return cosh((double)__x);}
 
 #endif // __sun__
 // exp
@@ -787,8 +793,8 @@
 #ifndef __sun__
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       exp(float __x)       {return expf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) {return expl(__x);}
+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);}
 #endif
 
 
@@ -795,7 +801,7 @@
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-exp(_A1 __x) {return exp((double)__x);}
+exp(_A1 __x) _NOEXCEPT {return exp((double)__x);}
 
 // fabs
 
@@ -803,14 +809,14 @@
 using ::fabsf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __x)       {return fabsf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) {return fabsl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-fabs(_A1 __x) {return fabs((double)__x);}
+fabs(_A1 __x) _NOEXCEPT {return fabs((double)__x);}
 
 // floor
 
@@ -818,14 +824,14 @@
 using ::floorf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       floor(float __x)       {return floorf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) {return floorl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-floor(_A1 __x) {return floor((double)__x);}
+floor(_A1 __x) _NOEXCEPT {return floor((double)__x);}
 
 // fmod
 
@@ -835,8 +841,8 @@
 #ifndef __sun__
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __x, float __y)             {return fmodf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) {return fmodl(__x, __y);}
+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);}
 #endif
 
 template <class _A1, class _A2>
@@ -847,7 +853,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmod(_A1 __x, _A2 __y)
+fmod(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -862,14 +868,14 @@
 using ::frexpf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __x, int* __e)       {return frexpf(__x, __e);}
-inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) {return frexpl(__x, __e);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-frexp(_A1 __x, int* __e) {return frexp((double)__x, __e);}
+frexp(_A1 __x, int* __e) _NOEXCEPT {return frexp((double)__x, __e);}
 
 // ldexp
 
@@ -877,14 +883,14 @@
 using ::ldexpf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __x, int __e)       {return ldexpf(__x, __e);}
-inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) {return ldexpl(__x, __e);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-ldexp(_A1 __x, int __e) {return ldexp((double)__x, __e);}
+ldexp(_A1 __x, int __e) _NOEXCEPT {return ldexp((double)__x, __e);}
 
 // log
 
@@ -894,14 +900,14 @@
 #ifndef __sun__
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       log(float __x)       {return logf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) {return logl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log(_A1 __x) {return log((double)__x);}
+log(_A1 __x) _NOEXCEPT {return log((double)__x);}
 
 
 // log10
@@ -910,14 +916,14 @@
 using ::log10f;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       log10(float __x)       {return log10f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) {return log10l(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log10(_A1 __x) {return log10((double)__x);}
+log10(_A1 __x) _NOEXCEPT {return log10((double)__x);}
 
 // modf
 
@@ -925,8 +931,8 @@
 using ::modff;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       modf(float __x, float* __y)             {return modff(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) {return modfl(__x, __y);}
+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);}
 #endif
 
 // pow
@@ -938,8 +944,8 @@
 #ifndef __sun__
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       pow(float __x, float __y)             {return powf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) {return powl(__x, __y);}
+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);}
 #endif
 
 template <class _A1, class _A2>
@@ -950,7 +956,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-pow(_A1 __x, _A2 __y)
+pow(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -965,14 +971,14 @@
 using ::sinf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       sin(float __x)       {return sinf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) {return sinl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sin(_A1 __x) {return sin((double)__x);}
+sin(_A1 __x) _NOEXCEPT {return sin((double)__x);}
 
 // sinh
 
@@ -980,14 +986,14 @@
 using ::sinhf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __x)       {return sinhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) {return sinhl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sinh(_A1 __x) {return sinh((double)__x);}
+sinh(_A1 __x) _NOEXCEPT {return sinh((double)__x);}
 
 // sqrt
 
@@ -997,14 +1003,14 @@
 
 
 #if !(defined(_MSC_VER) || defined(__sun__))
-inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __x)       {return sqrtf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) {return sqrtl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-sqrt(_A1 __x) {return sqrt((double)__x);}
+sqrt(_A1 __x) _NOEXCEPT {return sqrt((double)__x);}
 
 // tan
 
@@ -1013,14 +1019,14 @@
 #ifndef __sun__
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       tan(float __x)       {return tanf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) {return tanl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tan(_A1 __x) {return tan((double)__x);}
+tan(_A1 __x) _NOEXCEPT {return tan((double)__x);}
 
 // tanh
 
@@ -1028,14 +1034,14 @@
 using ::tanhf;
 
 #ifndef _MSC_VER
-inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __x)       {return tanhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) {return tanhl(__x);}
+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);}
 #endif
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tanh(_A1 __x) {return tanh((double)__x);}
+tanh(_A1 __x) _NOEXCEPT {return tanh((double)__x);}
 
 // acosh
 
@@ -1043,13 +1049,13 @@
 using ::acosh;
 using ::acoshf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __x)       {return acoshf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __x) {return acoshl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-acosh(_A1 __x) {return acosh((double)__x);}
+acosh(_A1 __x) _NOEXCEPT {return acosh((double)__x);}
 #endif
 
 // asinh
@@ -1058,13 +1064,13 @@
 using ::asinh;
 using ::asinhf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __x)       {return asinhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __x) {return asinhl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-asinh(_A1 __x) {return asinh((double)__x);}
+asinh(_A1 __x) _NOEXCEPT {return asinh((double)__x);}
 #endif
 
 // atanh
@@ -1073,13 +1079,13 @@
 using ::atanh;
 using ::atanhf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __x)       {return atanhf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __x) {return atanhl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-atanh(_A1 __x) {return atanh((double)__x);}
+atanh(_A1 __x) _NOEXCEPT {return atanh((double)__x);}
 #endif
 
 // cbrt
@@ -1088,13 +1094,13 @@
 using ::cbrt;
 using ::cbrtf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __x)       {return cbrtf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __x) {return cbrtl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-cbrt(_A1 __x) {return cbrt((double)__x);}
+cbrt(_A1 __x) _NOEXCEPT {return cbrt((double)__x);}
 #endif
 
 // copysign
@@ -1102,8 +1108,8 @@
 using ::copysign;
 using ::copysignf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       copysign(float __x, float __y)             {return copysignf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __x, long double __y) {return copysignl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1113,7 +1119,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-copysign(_A1 __x, _A2 __y)
+copysign(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1128,13 +1134,13 @@
 using ::erf;
 using ::erff;
 
-inline _LIBCPP_INLINE_VISIBILITY float       erf(float __x)       {return erff(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __x) {return erfl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-erf(_A1 __x) {return erf((double)__x);}
+erf(_A1 __x) _NOEXCEPT {return erf((double)__x);}
 
 // erfc
 
@@ -1141,13 +1147,13 @@
 using ::erfc;
 using ::erfcf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __x)       {return erfcf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __x) {return erfcl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-erfc(_A1 __x) {return erfc((double)__x);}
+erfc(_A1 __x) _NOEXCEPT {return erfc((double)__x);}
 
 // exp2
 
@@ -1154,13 +1160,13 @@
 using ::exp2;
 using ::exp2f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __x)       {return exp2f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __x) {return exp2l(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-exp2(_A1 __x) {return exp2((double)__x);}
+exp2(_A1 __x) _NOEXCEPT {return exp2((double)__x);}
 
 // expm1
 
@@ -1167,13 +1173,13 @@
 using ::expm1;
 using ::expm1f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __x)       {return expm1f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __x) {return expm1l(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-expm1(_A1 __x) {return expm1((double)__x);}
+expm1(_A1 __x) _NOEXCEPT {return expm1((double)__x);}
 
 // fdim
 
@@ -1180,8 +1186,8 @@
 using ::fdim;
 using ::fdimf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __x, float __y)             {return fdimf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __x, long double __y) {return fdiml(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1191,7 +1197,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fdim(_A1 __x, _A2 __y)
+fdim(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1201,13 +1207,15 @@
 
 // fma
 
-inline _LIBCPP_INLINE_VISIBILITY float fmaf(float __x, float __y, float __z) {return (float)((double)__x*__y + __z);}
+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 ::fma;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fma(float __x, float __y, float __z)                   {return fmaf(__x, __y, __z);}
-inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __x, long double __y, long double __z) {return fmal(__x, __y, __z);}
+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);}
 
 template <class _A1, class _A2, class _A3>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1218,7 +1226,7 @@
     is_arithmetic<_A3>::value,
     typename __promote<_A1, _A2, _A3>::type
 >::type
-fma(_A1 __x, _A2 __y, _A3 __z)
+fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2, _A3>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1232,8 +1240,8 @@
 using ::fmax;
 using ::fmaxf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __x, float __y)             {return fmaxf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __x, long double __y) {return fmaxl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1243,7 +1251,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmax(_A1 __x, _A2 __y)
+fmax(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1256,8 +1264,8 @@
 using ::fmin;
 using ::fminf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __x, float __y)             {return fminf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __x, long double __y) {return fminl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1267,7 +1275,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-fmin(_A1 __x, _A2 __y)
+fmin(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1280,8 +1288,8 @@
 using ::hypot;
 using ::hypotf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __x, float __y)             {return hypotf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __x, long double __y) {return hypotl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1291,7 +1299,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-hypot(_A1 __x, _A2 __y)
+hypot(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1304,13 +1312,13 @@
 using ::ilogb;
 using ::ilogbf;
 
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __x)       {return ilogbf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __x) {return ilogbl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, int>::type
-ilogb(_A1 __x) {return ilogb((double)__x);}
+ilogb(_A1 __x) _NOEXCEPT {return ilogb((double)__x);}
 
 // lgamma
 
@@ -1317,14 +1325,14 @@
 using ::lgamma;
 using ::lgammaf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __x)       {return lgammaf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __x) {return lgammal(__x);}
+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);}
 
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-lgamma(_A1 __x) {return lgamma((double)__x);}
+lgamma(_A1 __x) _NOEXCEPT {return lgamma((double)__x);}
 
 
 // llrint
@@ -1332,13 +1340,13 @@
 using ::llrint;
 using ::llrintf;
 
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __x)       {return llrintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __x) {return llrintl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long long>::type
-llrint(_A1 __x) {return llrint((double)__x);}
+llrint(_A1 __x) _NOEXCEPT {return llrint((double)__x);}
 
 // llround
 
@@ -1345,13 +1353,13 @@
 using ::llround;
 using ::llroundf;
 
-inline _LIBCPP_INLINE_VISIBILITY long long llround(float __x)       {return llroundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __x) {return llroundl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long long>::type
-llround(_A1 __x) {return llround((double)__x);}
+llround(_A1 __x) _NOEXCEPT {return llround((double)__x);}
 
 // log1p
 
@@ -1358,13 +1366,13 @@
 using ::log1p;
 using ::log1pf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __x)       {return log1pf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __x) {return log1pl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log1p(_A1 __x) {return log1p((double)__x);}
+log1p(_A1 __x) _NOEXCEPT {return log1p((double)__x);}
 
 // log2
 
@@ -1371,13 +1379,13 @@
 using ::log2;
 using ::log2f;
 
-inline _LIBCPP_INLINE_VISIBILITY float       log2(float __x)       {return log2f(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __x) {return log2l(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-log2(_A1 __x) {return log2((double)__x);}
+log2(_A1 __x) _NOEXCEPT {return log2((double)__x);}
 
 // logb
 
@@ -1384,13 +1392,13 @@
 using ::logb;
 using ::logbf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       logb(float __x)       {return logbf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __x) {return logbl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-logb(_A1 __x) {return logb((double)__x);}
+logb(_A1 __x) _NOEXCEPT {return logb((double)__x);}
 
 // lrint
 
@@ -1397,13 +1405,13 @@
 using ::lrint;
 using ::lrintf;
 
-inline _LIBCPP_INLINE_VISIBILITY long lrint(float __x)       {return lrintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __x) {return lrintl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long>::type
-lrint(_A1 __x) {return lrint((double)__x);}
+lrint(_A1 __x) _NOEXCEPT {return lrint((double)__x);}
 
 // lround
 
@@ -1410,13 +1418,13 @@
 using ::lround;
 using ::lroundf;
 
-inline _LIBCPP_INLINE_VISIBILITY long lround(float __x)       {return lroundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long lround(long double __x) {return lroundl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, long>::type
-lround(_A1 __x) {return lround((double)__x);}
+lround(_A1 __x) _NOEXCEPT {return lround((double)__x);}
 
 // nan
 #endif // _MSC_VER
@@ -1431,13 +1439,13 @@
 using ::nearbyint;
 using ::nearbyintf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __x)       {return nearbyintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __x) {return nearbyintl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-nearbyint(_A1 __x) {return nearbyint((double)__x);}
+nearbyint(_A1 __x) _NOEXCEPT {return nearbyint((double)__x);}
 
 // nextafter
 
@@ -1444,8 +1452,8 @@
 using ::nextafter;
 using ::nextafterf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __x, float __y)             {return nextafterf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __x, long double __y) {return nextafterl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1455,7 +1463,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-nextafter(_A1 __x, _A2 __y)
+nextafter(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1468,13 +1476,13 @@
 using ::nexttoward;
 using ::nexttowardf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __x, long double __y)       {return nexttowardf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-nexttoward(_A1 __x, long double __y) {return nexttoward((double)__x, __y);}
+nexttoward(_A1 __x, long double __y) _NOEXCEPT {return nexttoward((double)__x, __y);}
 
 // remainder
 
@@ -1481,8 +1489,8 @@
 using ::remainder;
 using ::remainderf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __x, float __y)             {return remainderf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) {return remainderl(__x, __y);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1492,7 +1500,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-remainder(_A1 __x, _A2 __y)
+remainder(_A1 __x, _A2 __y) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1505,8 +1513,8 @@
 using ::remquo;
 using ::remquof;
 
-inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __x, float __y, int* __z)             {return remquof(__x, __y, __z);}
-inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __x, long double __y, int* __z) {return remquol(__x, __y, __z);}
+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);}
 
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1516,7 +1524,7 @@
     is_arithmetic<_A2>::value,
     typename __promote<_A1, _A2>::type
 >::type
-remquo(_A1 __x, _A2 __y, int* __z)
+remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT
 {
     typedef typename __promote<_A1, _A2>::type __result_type;
     static_assert((!(is_same<_A1, __result_type>::value &&
@@ -1529,13 +1537,13 @@
 using ::rint;
 using ::rintf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       rint(float __x)       {return rintf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __x) {return rintl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-rint(_A1 __x) {return rint((double)__x);}
+rint(_A1 __x) _NOEXCEPT {return rint((double)__x);}
 
 // round
 
@@ -1542,13 +1550,13 @@
 using ::round;
 using ::roundf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       round(float __x)       {return roundf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) {return roundl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-round(_A1 __x) {return round((double)__x);}
+round(_A1 __x) _NOEXCEPT {return round((double)__x);}
 
 // scalbln
 
@@ -1555,13 +1563,13 @@
 using ::scalbln;
 using ::scalblnf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __x, long __y)       {return scalblnf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __x, long __y) {return scalblnl(__x, __y);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-scalbln(_A1 __x, long __y) {return scalbln((double)__x, __y);}
+scalbln(_A1 __x, long __y) _NOEXCEPT {return scalbln((double)__x, __y);}
 
 // scalbn
 
@@ -1568,13 +1576,13 @@
 using ::scalbn;
 using ::scalbnf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __x, int __y)       {return scalbnf(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __x, int __y) {return scalbnl(__x, __y);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-scalbn(_A1 __x, int __y) {return scalbn((double)__x, __y);}
+scalbn(_A1 __x, int __y) _NOEXCEPT {return scalbn((double)__x, __y);}
 
 // tgamma
 
@@ -1581,13 +1589,13 @@
 using ::tgamma;
 using ::tgammaf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __x)       {return tgammaf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __x) {return tgammal(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-tgamma(_A1 __x) {return tgamma((double)__x);}
+tgamma(_A1 __x) _NOEXCEPT {return tgamma((double)__x);}
 
 // trunc
 
@@ -1594,13 +1602,13 @@
 using ::trunc;
 using ::truncf;
 
-inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __x)       {return truncf(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __x) {return truncl(__x);}
+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);}
 
 template <class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if<is_integral<_A1>::value, double>::type
-trunc(_A1 __x) {return trunc((double)__x);}
+trunc(_A1 __x) _NOEXCEPT {return trunc((double)__x);}
 
 #endif // !_MSC_VER
 

Modified: trunk/contrib/libc++/include/codecvt
===================================================================
--- trunk/contrib/libc++/include/codecvt	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/codecvt	2016-01-07 17:22:14 UTC (rev 7405)
@@ -179,7 +179,7 @@
 
 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
           codecvt_mode _Mode = (codecvt_mode)0>
-class _LIBCPP_VISIBLE codecvt_utf8
+class _LIBCPP_TYPE_VIS codecvt_utf8
     : public __codecvt_utf8<_Elem>
 {
 public:
@@ -407,7 +407,7 @@
 
 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
           codecvt_mode _Mode = (codecvt_mode)0>
-class _LIBCPP_VISIBLE codecvt_utf16
+class _LIBCPP_TYPE_VIS codecvt_utf16
     : public __codecvt_utf16<_Elem, _Mode & little_endian>
 {
 public:
@@ -530,7 +530,7 @@
 
 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
           codecvt_mode _Mode = (codecvt_mode)0>
-class _LIBCPP_VISIBLE codecvt_utf8_utf16
+class _LIBCPP_TYPE_VIS codecvt_utf8_utf16
     : public __codecvt_utf8_utf16<_Elem>
 {
 public:

Modified: trunk/contrib/libc++/include/complex
===================================================================
--- trunk/contrib/libc++/include/complex	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/complex	2016-01-07 17:22:14 UTC (rev 7405)
@@ -255,13 +255,13 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template<class _Tp> class _LIBCPP_VISIBLE complex;
+template<class _Tp> class _LIBCPP_TYPE_VIS complex;
 
 template<class _Tp> complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w);
 template<class _Tp> complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
 
 template<class _Tp>
-class _LIBCPP_VISIBLE complex
+class _LIBCPP_TYPE_VIS complex
 {
 public:
     typedef _Tp value_type;
@@ -319,11 +319,11 @@
         }
 };
 
-template<> class _LIBCPP_VISIBLE complex<double>;
-template<> class _LIBCPP_VISIBLE complex<long double>;
+template<> class _LIBCPP_TYPE_VIS complex<double>;
+template<> class _LIBCPP_TYPE_VIS complex<long double>;
 
 template<>
-class _LIBCPP_VISIBLE complex<float>
+class _LIBCPP_TYPE_VIS complex<float>
 {
     float __re_;
     float __im_;
@@ -330,13 +330,13 @@
 public:
     typedef float value_type;
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(float __re = 0.0f, float __im = 0.0f)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f)
         : __re_(__re), __im_(__im) {}
-    explicit /*constexpr*/ complex(const complex<double>& __c);
-    explicit /*constexpr*/ complex(const complex<long double>& __c);
+    explicit _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
+    explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float real() const {return __re_;}
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float imag() const {return __im_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;}
 
     _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
     _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
@@ -379,7 +379,7 @@
 };
 
 template<>
-class _LIBCPP_VISIBLE complex<double>
+class _LIBCPP_TYPE_VIS complex<double>
 {
     double __re_;
     double __im_;
@@ -386,13 +386,13 @@
 public:
     typedef double value_type;
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(double __re = 0.0, double __im = 0.0)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0)
         : __re_(__re), __im_(__im) {}
-    /*constexpr*/ complex(const complex<float>& __c);
-    explicit /*constexpr*/ complex(const complex<long double>& __c);
+    _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
+    explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double real() const {return __re_;}
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double imag() const {return __im_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;}
 
     _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
     _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
@@ -435,7 +435,7 @@
 };
 
 template<>
-class _LIBCPP_VISIBLE complex<long double>
+class _LIBCPP_TYPE_VIS complex<long double>
 {
     long double __re_;
     long double __im_;
@@ -442,13 +442,13 @@
 public:
     typedef long double value_type;
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(long double __re = 0.0L, long double __im = 0.0L)
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L)
         : __re_(__re), __im_(__im) {}
-    /*constexpr*/ complex(const complex<float>& __c);
-    /*constexpr*/ complex(const complex<double>& __c);
+    _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
+    _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
 
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double real() const {return __re_;}
-    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double imag() const {return __im_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;}
 
     _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
     _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
@@ -490,33 +490,33 @@
         }
 };
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<float>::complex(const complex<double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<float>::complex(const complex<long double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<double>::complex(const complex<float>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<double>::complex(const complex<long double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<long double>::complex(const complex<float>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-//constexpr
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 complex<long double>::complex(const complex<double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
@@ -1249,10 +1249,12 @@
         if (isnan(__x.imag()))
             return complex<_Tp>(abs(__x.real()), __x.imag());
         if (isinf(__x.imag()))
+        {
             if (__x.real() > 0)
                 return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag()));
             else
                 return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag()));
+        }
         if (__x.real() < 0)
             return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag()));
         return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
@@ -1351,7 +1353,11 @@
     _Tp __2r(_Tp(2) * __x.real());
     _Tp __2i(_Tp(2) * __x.imag());
     _Tp __d(cosh(__2r) + cos(__2i));
-    return  complex<_Tp>(sinh(__2r)/__d, sin(__2i)/__d);
+    _Tp __2rsh(sinh(__2r));
+    if (isinf(__2rsh) && isinf(__d))
+        return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1),
+                            __2i > _Tp(0) ? _Tp(0) : _Tp(-0.));
+    return  complex<_Tp>(__2rsh/__d, sin(__2i)/__d);
 }
 
 // asin

Modified: trunk/contrib/libc++/include/condition_variable
===================================================================
--- trunk/contrib/libc++/include/condition_variable	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/condition_variable	2016-01-07 17:22:14 UTC (rev 7405)
@@ -28,8 +28,8 @@
     condition_variable(const condition_variable&) = delete;
     condition_variable& operator=(const condition_variable&) = delete;
 
-    void notify_one();
-    void notify_all();
+    void notify_one() noexcept;
+    void notify_all() noexcept;
 
     void wait(unique_lock<mutex>& lock);
     template <class Predicate>
@@ -72,8 +72,8 @@
     condition_variable_any(const condition_variable_any&) = delete;
     condition_variable_any& operator=(const condition_variable_any&) = delete;
 
-    void notify_one();
-    void notify_all();
+    void notify_one() noexcept;
+    void notify_all() noexcept;
 
     template <class Lock>
         void wait(Lock& lock);
@@ -117,7 +117,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_VISIBLE condition_variable_any
+class _LIBCPP_TYPE_VIS condition_variable_any
 {
     condition_variable __cv_;
     shared_ptr<mutex>  __mut_;
@@ -124,8 +124,8 @@
 public:
     condition_variable_any();
 
-    void notify_one();
-    void notify_all();
+    void notify_one() _NOEXCEPT;
+    void notify_all() _NOEXCEPT;
 
     template <class _Lock>
         void wait(_Lock& __lock);
@@ -161,17 +161,17 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 void
-condition_variable_any::notify_one()
+condition_variable_any::notify_one() _NOEXCEPT
 {
-    {lock_guard<mutex> _(*__mut_);}
+    {lock_guard<mutex> __lx(*__mut_);}
     __cv_.notify_one();
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
 void
-condition_variable_any::notify_all()
+condition_variable_any::notify_all() _NOEXCEPT
 {
-    {lock_guard<mutex> _(*__mut_);}
+    {lock_guard<mutex> __lx(*__mut_);}
     __cv_.notify_all();
 }
 
@@ -188,8 +188,8 @@
     shared_ptr<mutex> __mut = __mut_;
     unique_lock<mutex> __lk(*__mut);
     __lock.unlock();
-    unique_ptr<_Lock, __lock_external> __(&__lock);
-    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
+    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
+    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
     __cv_.wait(__lk);
 }  // __mut_.unlock(), __lock.lock()
 
@@ -210,8 +210,8 @@
     shared_ptr<mutex> __mut = __mut_;
     unique_lock<mutex> __lk(*__mut);
     __lock.unlock();
-    unique_ptr<_Lock, __lock_external> __(&__lock);
-    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
+    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
+    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
     return __cv_.wait_until(__lk, __t);
 }  // __mut_.unlock(), __lock.lock()
 
@@ -248,7 +248,7 @@
                       _VSTD::move(__pred));
 }
 
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
 void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
 
 _LIBCPP_END_NAMESPACE_STD

Modified: trunk/contrib/libc++/include/cstddef
===================================================================
--- trunk/contrib/libc++/include/cstddef	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cstddef	2016-01-07 17:22:14 UTC (rev 7405)
@@ -56,19 +56,19 @@
 
 #ifdef _LIBCPP_HAS_NO_NULLPTR
 
-struct _LIBCPP_VISIBLE nullptr_t
+struct _LIBCPP_TYPE_VIS nullptr_t
 {
-    void* _;
+    void* __lx;
 
     struct __nat {int __for_bool_;};
 
-    _LIBCPP_ALWAYS_INLINE nullptr_t() {}
-    _LIBCPP_ALWAYS_INLINE nullptr_t(int __nat::*) {}
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
 
-    _LIBCPP_ALWAYS_INLINE operator int __nat::*() const {return 0;}
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
 
     template <class _Tp>
-        _LIBCPP_ALWAYS_INLINE
+        _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
         operator _Tp* () const {return 0;}
 
     template <class _Tp, class _Up>
@@ -75,15 +75,15 @@
         _LIBCPP_ALWAYS_INLINE
         operator _Tp _Up::* () const {return 0;}
 
-    friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE bool operator<(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE bool operator<=(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_ALWAYS_INLINE bool operator>(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE bool operator>=(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
 };
 
-inline _LIBCPP_ALWAYS_INLINE nullptr_t __get_nullptr_t() {return nullptr_t(0);}
+inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
 
 #define nullptr _VSTD::__get_nullptr_t()
 

Modified: trunk/contrib/libc++/include/cstdio
===================================================================
--- trunk/contrib/libc++/include/cstdio	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cstdio	2016-01-07 17:22:14 UTC (rev 7405)
@@ -103,6 +103,18 @@
 #pragma GCC system_header
 #endif
 
+#ifdef getc
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_getc(FILE* __stream) {return getc(__stream);}
+#undef getc
+inline _LIBCPP_INLINE_VISIBILITY int getc(FILE* __stream) {return __libcpp_getc(__stream);}
+#endif  // getc
+
+#ifdef putc
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_putc(int __c, FILE* __stream) {return putc(__c, __stream);}
+#undef putc
+inline _LIBCPP_INLINE_VISIBILITY int putc(int __c, FILE* __stream) {return __libcpp_putc(__c, __stream);}
+#endif  // putc
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::FILE;

Modified: trunk/contrib/libc++/include/cstdlib
===================================================================
--- trunk/contrib/libc++/include/cstdlib	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cstdlib	2016-01-07 17:22:14 UTC (rev 7405)
@@ -74,6 +74,9 @@
 int wctomb(char* s, wchar_t wchar);
 size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
 size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
+int at_quick_exit(void (*func)(void))                                     // C++11
+void quick_exit(int status);                                              // C++11
+void *aligned_alloc(size_t alignment, size_t size);                       // C11
 
 }  // std
 
@@ -94,18 +97,26 @@
 using ::size_t;
 using ::div_t;
 using ::ldiv_t;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::lldiv_t;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::atof;
 using ::atoi;
 using ::atol;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::atoll;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::strtod;
 using ::strtof;
 using ::strtold;
 using ::strtol;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoll;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoul;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::strtoull;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::rand;
 using ::srand;
 using ::calloc;
@@ -122,10 +133,14 @@
 using ::qsort;
 using ::abs;
 using ::labs;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::llabs;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::div;
 using ::ldiv;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::lldiv;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::mblen;
 using ::mbtowc;
 using ::wctomb;
@@ -135,14 +150,21 @@
 using ::at_quick_exit;
 using ::quick_exit;
 #endif
+#ifdef _LIBCPP_HAS_C11_FEATURES
+using ::aligned_alloc;
+#endif
 
 // MSVC already has the correct prototype in <stdlib.h.h> #ifdef __cplusplus
 #if !defined(_MSC_VER) && !defined(__sun__)
-inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) {return  labs(__x);}
-inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) {return llabs(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
+inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 
-inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) {return  ldiv(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) {return lldiv(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
+inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 #endif // _MSC_VER
 
 _LIBCPP_END_NAMESPACE_STD

Modified: trunk/contrib/libc++/include/cstring
===================================================================
--- trunk/contrib/libc++/include/cstring	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cstring	2016-01-07 17:22:14 UTC (rev 7405)
@@ -94,7 +94,7 @@
 using ::strstr;
 
 // MSVC, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
-#if !defined(__GLIBC__) && !defined(_MSC_VER) && !defined(__sun__)
+#if !defined(__GLIBC__) && !defined(_MSC_VER) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
 inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}

Modified: trunk/contrib/libc++/include/cwchar
===================================================================
--- trunk/contrib/libc++/include/cwchar	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/cwchar	2016-01-07 17:22:14 UTC (rev 7405)
@@ -106,7 +106,7 @@
 #include <__config>
 #include <cwctype>
 #include <wchar.h>
-#if _WIN32
+#ifdef _WIN32
 #include <support/win32/support.h> // pull in *swprintf defines
 #endif // _WIN32
 
@@ -151,9 +151,13 @@
 using ::wcstold;
 #endif // _MSC_VER
 using ::wcstol;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoll;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoul;
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
 using ::wcstoull;
+#endif // _LIBCPP_HAS_NO_LONG_LONG
 using ::wcscpy;
 using ::wcsncpy;
 using ::wcscat;
@@ -163,12 +167,19 @@
 using ::wcsncmp;
 using ::wcsxfrm;
 
+#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
+
+using ::wcschr;
+using ::wcspbrk;
+using ::wcsrchr;
+using ::wcsstr;
+using ::wmemchr;
+
+#else
+
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
 
-using ::wcscspn;
-using ::wcslen;
-
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
 
@@ -175,16 +186,18 @@
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
 
-using ::wcsspn;
-
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
 
-using ::wcstok;
-
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
 
+#endif
+
+using ::wcscspn;
+using ::wcslen;
+using ::wcsspn;
+using ::wcstok;
 using ::wmemcmp;
 using ::wmemcpy;
 using ::wmemmove;

Modified: trunk/contrib/libc++/include/deque
===================================================================
--- trunk/contrib/libc++/include/deque	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/deque	2016-01-07 17:22:14 UTC (rev 7405)
@@ -170,7 +170,7 @@
 
 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
           class _DiffType, _DiffType _BlockSize>
-class _LIBCPP_VISIBLE __deque_iterator;
+class _LIBCPP_TYPE_VIS __deque_iterator;
 
 template <class _RAIter,
           class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
@@ -262,7 +262,7 @@
 
 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
           class _DiffType, _DiffType _BlockSize>
-class _LIBCPP_VISIBLE __deque_iterator
+class _LIBCPP_TYPE_VIS __deque_iterator
 {
     typedef _MapPointer __map_iterator;
 public:
@@ -410,9 +410,9 @@
         : __m_iter_(__m), __ptr_(__p) {}
 
     template <class _Tp, class _Ap> friend class __deque_base;
-    template <class _Tp, class _Ap> friend class _LIBCPP_VISIBLE deque;
+    template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS deque;
     template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
-        friend class _LIBCPP_VISIBLE __deque_iterator;
+        friend class _LIBCPP_TYPE_VIS __deque_iterator;
 
     template <class _RAIter,
               class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
@@ -915,7 +915,14 @@
                                                          __pointer_allocator;
     typedef allocator_traits<__pointer_allocator>        __map_traits;
     typedef typename __map_traits::pointer               __map_pointer;
-    typedef typename __map_traits::const_pointer         __map_const_pointer;
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<const_pointer>
+#else
+                rebind_alloc<const_pointer>::other
+#endif
+                                                         __const_pointer_allocator;
+    typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
     typedef __split_buffer<pointer, __pointer_allocator> __map;
 
     typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
@@ -1053,7 +1060,7 @@
 typename __deque_base<_Tp, _Allocator>::const_iterator
 __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
 {
-    __map_const_pointer __mp = __map_.begin() + __start_ / __block_size;
+    __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
     return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
 }
 
@@ -1071,7 +1078,7 @@
 __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
 {
     size_type __p = size() + __start_;
-    __map_const_pointer __mp = __map_.begin() + __p / __block_size;
+    __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
     return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
 }
 
@@ -1167,7 +1174,7 @@
 }
 
 template <class _Tp, class _Allocator = allocator<_Tp> >
-class _LIBCPP_VISIBLE deque
+class _LIBCPP_TYPE_VIS deque
     : private __deque_base<_Tp, _Allocator>
 {
 public:
@@ -1341,6 +1348,8 @@
     _LIBCPP_INLINE_VISIBILITY
     bool __invariants() const {return __base::__invariants();}
 private:
+    typedef typename __base::__map_const_pointer __map_const_pointer;
+
     _LIBCPP_INLINE_VISIBILITY
     static size_type __recommend_blocks(size_type __n)
     {
@@ -1966,6 +1975,7 @@
         }
         else
         {
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);
             iterator __b = __base::begin();
             iterator __bm1 = _VSTD::prev(__b);
             __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
@@ -1973,7 +1983,7 @@
             ++__base::size();
             if (__pos > 1)
                 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
-            *__b = value_type(_VSTD::forward<_Args>(__args)...);
+            *__b = _VSTD::move(__tmp);
         }
     }
     else
@@ -1989,6 +1999,7 @@
         }
         else
         {
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);
             iterator __e = __base::end();
             iterator __em1 = _VSTD::prev(__e);
             __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
@@ -1995,7 +2006,7 @@
             ++__base::size();
             if (__de > 1)
                 __e = _VSTD::move_backward(__e - __de, __em1, __e);
-            *--__e = value_type(_VSTD::forward<_Args>(__args)...);
+            *--__e = _VSTD::move(__tmp);
         }
     }
     return __base::begin() + __pos;
@@ -2503,9 +2514,9 @@
 deque<_Tp, _Allocator>::pop_front()
 {
     allocator_type& __a = __base::__alloc();
-    __alloc_traits::destroy(__a, *(__base::__map_.begin() +
-                                   __base::__start_ / __base::__block_size) +
-                                   __base::__start_ % __base::__block_size);
+    __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
+                                                    __base::__start_ / __base::__block_size) +
+                                                    __base::__start_ % __base::__block_size));
     --__base::size();
     if (++__base::__start_ >= 2 * __base::__block_size)
     {
@@ -2521,9 +2532,9 @@
 {
     allocator_type& __a = __base::__alloc();
     size_type __p = __base::size() + __base::__start_ - 1;
-    __alloc_traits::destroy(__a, *(__base::__map_.begin() +
-                                   __p / __base::__block_size) +
-                                   __p % __base::__block_size);
+    __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
+                                                    __p / __base::__block_size) +
+                                                    __p % __base::__block_size));
     --__base::size();
     if (__back_spare() >= 2 * __base::__block_size)
     {
@@ -2554,7 +2565,7 @@
             __fe = __fb + __bs;
         }
         if (__fb <= __vt && __vt < __fe)
-            __vt = (const_iterator(__f.__m_iter_, __vt) -= __f - __r).__ptr_;
+            __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
         __r = _VSTD::move(__fb, __fe, __r);
         __n -= __bs;
         __f += __bs;
@@ -2585,7 +2596,7 @@
             __lb = __le - __bs;
         }
         if (__lb <= __vt && __vt < __le)
-            __vt = (const_iterator(__l.__m_iter_, __vt) += __r - __l - 1).__ptr_;
+            __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
         __r = _VSTD::move_backward(__lb, __le, __r);
         __n -= __bs;
         __l -= __bs - 1;
@@ -2616,7 +2627,7 @@
             __fe = __fb + __bs;
         }
         if (__fb <= __vt && __vt < __fe)
-            __vt = (const_iterator(__f.__m_iter_, __vt) += __r - __f).__ptr_;
+            __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
         for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
             __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
         __n -= __bs;
@@ -2652,7 +2663,7 @@
             __lb = __le - __bs;
         }
         if (__lb <= __vt && __vt < __le)
-            __vt = (const_iterator(__l.__m_iter_, __vt) -= __l - __r + 1).__ptr_;
+            __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
         while (__le != __lb)
         {
             __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));

Modified: trunk/contrib/libc++/include/exception
===================================================================
--- trunk/contrib/libc++/include/exception	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/exception	2016-01-07 17:22:14 UTC (rev 7405)
@@ -105,23 +105,23 @@
 };
 
 typedef void (*unexpected_handler)();
-_LIBCPP_VISIBLE unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
-_LIBCPP_VISIBLE unexpected_handler get_unexpected() _NOEXCEPT;
-_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void unexpected();
+_LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
+_LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT;
+_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected();
 
 typedef void (*terminate_handler)();
-_LIBCPP_VISIBLE terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
-_LIBCPP_VISIBLE terminate_handler get_terminate() _NOEXCEPT;
-_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void terminate() _NOEXCEPT;
+_LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
+_LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT;
+_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT;
 
-_LIBCPP_VISIBLE bool uncaught_exception() _NOEXCEPT;
+_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT;
 
-class exception_ptr;
+class _LIBCPP_TYPE_VIS exception_ptr;
 
 exception_ptr current_exception() _NOEXCEPT;
-_ATTRIBUTE(noreturn) void rethrow_exception(exception_ptr);
+_LIBCPP_NORETURN void rethrow_exception(exception_ptr);
 
-class _LIBCPP_VISIBLE exception_ptr
+class _LIBCPP_TYPE_VIS exception_ptr
 {
     void* __ptr_;
 public:
@@ -143,7 +143,7 @@
         {return !(__x == __y);}
 
     friend exception_ptr current_exception() _NOEXCEPT;
-    _ATTRIBUTE(noreturn) friend void rethrow_exception(exception_ptr);
+    friend void rethrow_exception(exception_ptr);
 };
 
 template<class _Ep>
@@ -174,7 +174,7 @@
     virtual ~nested_exception() _NOEXCEPT;
 
     // access functions
-    _ATTRIBUTE(noreturn) void rethrow_nested() const;
+    _LIBCPP_NORETURN void rethrow_nested() const;
     _LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;}
 };
 
@@ -187,7 +187,7 @@
 };
 
 template <class _Tp>
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
 void
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 throw_with_nested(_Tp&& __t, typename enable_if<
@@ -206,7 +206,7 @@
 }
 
 template <class _Tp>
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
 void
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 throw_with_nested(_Tp&& __t, typename enable_if<

Modified: trunk/contrib/libc++/include/ext/__hash
===================================================================
--- trunk/contrib/libc++/include/ext/__hash	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ext/__hash	2016-01-07 17:22:14 UTC (rev 7405)
@@ -19,10 +19,10 @@
 namespace __gnu_cxx {
 using namespace std;
 
-template <typename T> struct _LIBCPP_VISIBLE hash : public std::hash<T>
+template <typename T> struct _LIBCPP_TYPE_VIS hash : public std::hash<T>
     { };
 
-template <> struct _LIBCPP_VISIBLE hash<const char*>
+template <> struct _LIBCPP_TYPE_VIS hash<const char*>
     : public unary_function<const char*, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -32,7 +32,7 @@
     }
 };
 
-template <> struct _LIBCPP_VISIBLE hash<char *>
+template <> struct _LIBCPP_TYPE_VIS hash<char *>
     : public unary_function<char*, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -43,4 +43,4 @@
 };
 }
 
-#endif _LIBCPP_EXT_HASH
+#endif  // _LIBCPP_EXT_HASH

Modified: trunk/contrib/libc++/include/ext/hash_map
===================================================================
--- trunk/contrib/libc++/include/ext/hash_map	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ext/hash_map	2016-01-07 17:22:14 UTC (rev 7405)
@@ -361,7 +361,7 @@
 };
 
 template <class _HashIterator>
-class _LIBCPP_VISIBLE __hash_map_iterator
+class _LIBCPP_TYPE_VIS __hash_map_iterator
 {
     _HashIterator __i_;
 
@@ -404,15 +404,15 @@
     bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_multimap;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS hash_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS hash_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
 };
 
 template <class _HashIterator>
-class _LIBCPP_VISIBLE __hash_map_const_iterator
+class _LIBCPP_TYPE_VIS __hash_map_const_iterator
 {
     _HashIterator __i_;
 
@@ -463,15 +463,15 @@
     bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_multimap;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS hash_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS hash_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
 };
 
 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
           class _Alloc = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE hash_map
+class _LIBCPP_TYPE_VIS hash_map
 {
 public:
     // types
@@ -750,7 +750,7 @@
 
 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
           class _Alloc = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE hash_multimap
+class _LIBCPP_TYPE_VIS hash_multimap
 {
 public:
     // types

Modified: trunk/contrib/libc++/include/ext/hash_set
===================================================================
--- trunk/contrib/libc++/include/ext/hash_set	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ext/hash_set	2016-01-07 17:22:14 UTC (rev 7405)
@@ -208,7 +208,7 @@
 
 template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
           class _Alloc = allocator<_Value> >
-class _LIBCPP_VISIBLE hash_set
+class _LIBCPP_TYPE_VIS hash_set
 {
 public:
     // types
@@ -429,7 +429,7 @@
 
 template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
           class _Alloc = allocator<_Value> >
-class _LIBCPP_VISIBLE hash_multiset
+class _LIBCPP_TYPE_VIS hash_multiset
 {
 public:
     // types

Modified: trunk/contrib/libc++/include/forward_list
===================================================================
--- trunk/contrib/libc++/include/forward_list	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/forward_list	2016-01-07 17:22:14 UTC (rev 7405)
@@ -212,11 +212,11 @@
     value_type __value_;
 };
 
-template<class _Tp, class _Alloc> class forward_list;
-template<class _NodeConstPtr> class __forward_list_const_iterator;
+template<class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS forward_list;
+template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS __forward_list_const_iterator;
 
 template <class _NodePtr>
-class _LIBCPP_VISIBLE __forward_list_iterator
+class _LIBCPP_TYPE_VIS __forward_list_iterator
 {
     typedef _NodePtr __node_pointer;
 
@@ -225,14 +225,14 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 
-    template<class, class> friend class forward_list;
-    template<class> friend class __forward_list_const_iterator;
+    template<class, class> friend class _LIBCPP_TYPE_VIS forward_list;
+    template<class> friend class _LIBCPP_TYPE_VIS __forward_list_const_iterator;
 
 public:
     typedef forward_iterator_tag                              iterator_category;
     typedef typename pointer_traits<__node_pointer>::element_type::value_type
                                                               value_type;
-    typedef value_type& reference;
+    typedef value_type&                                       reference;
     typedef typename pointer_traits<__node_pointer>::difference_type
                                                               difference_type;
     typedef typename pointer_traits<__node_pointer>::template
@@ -249,7 +249,7 @@
     _LIBCPP_INLINE_VISIBILITY
     reference operator*() const {return __ptr_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return &__ptr_->__value_;}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_iterator& operator++()
@@ -276,7 +276,7 @@
 };
 
 template <class _NodeConstPtr>
-class _LIBCPP_VISIBLE __forward_list_const_iterator
+class _LIBCPP_TYPE_VIS __forward_list_const_iterator
 {
     typedef _NodeConstPtr __node_const_pointer;
 
@@ -303,7 +303,7 @@
 public:
     typedef forward_iterator_tag                              iterator_category;
     typedef typename __node::value_type                       value_type;
-    typedef const value_type& reference;
+    typedef const value_type&                                 reference;
     typedef typename pointer_traits<__node_const_pointer>::difference_type
                                                               difference_type;
     typedef typename pointer_traits<__node_const_pointer>::template
@@ -323,7 +323,7 @@
     _LIBCPP_INLINE_VISIBILITY
     reference operator*() const {return __ptr_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return &__ptr_->__value_;}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_const_iterator& operator++()
@@ -368,18 +368,27 @@
                                                       __node_allocator;
     typedef allocator_traits<__node_allocator>        __node_traits;
     typedef typename __node_traits::pointer           __node_pointer;
-    typedef typename __node_traits::const_pointer     __node_const_pointer;
+    typedef typename __node_traits::pointer           __node_const_pointer;
 
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<__begin_node>
+#else
+                rebind_alloc<__begin_node>::other
+#endif
+                                                      __begin_node_allocator;
+    typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
+
     __compressed_pair<__begin_node, __node_allocator> __before_begin_;
 
     _LIBCPP_INLINE_VISIBILITY
     __node_pointer        __before_begin() _NOEXCEPT
-        {return pointer_traits<__node_pointer>::pointer_to(
-                                static_cast<__node&>(__before_begin_.first()));}
+        {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
+                                        pointer_to(__before_begin_.first()));}
     _LIBCPP_INLINE_VISIBILITY
     __node_const_pointer  __before_begin() const _NOEXCEPT
-        {return pointer_traits<__node_const_pointer>::pointer_to(
-                          static_cast<const __node&>(__before_begin_.first()));}
+        {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
+                                        pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
 
     _LIBCPP_INLINE_VISIBILITY
           __node_allocator& __alloc() _NOEXCEPT
@@ -389,7 +398,7 @@
         {return __before_begin_.second();}
 
     typedef __forward_list_iterator<__node_pointer>             iterator;
-    typedef __forward_list_const_iterator<__node_const_pointer> const_iterator;
+    typedef __forward_list_const_iterator<__node_pointer>       const_iterator;
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_base()
@@ -533,7 +542,7 @@
 }
 
 template <class _Tp, class _Alloc = allocator<_Tp> >
-class _LIBCPP_VISIBLE forward_list
+class _LIBCPP_TYPE_VIS forward_list
     : private __forward_list_base<_Tp, _Alloc>
 {
     typedef __forward_list_base<_Tp, _Alloc> base;
@@ -1050,7 +1059,7 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
 {
-    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1067,7 +1076,7 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
 {
-    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1083,7 +1092,7 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
 {
-    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1098,7 +1107,7 @@
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
                                         const value_type& __v)
 {
-    __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer __r = __p.__ptr_;
     if (__n > 0)
     {
         __node_allocator& __a = base::__alloc();
@@ -1148,7 +1157,7 @@
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
                                         _InputIterator __f, _InputIterator __l)
 {
-    __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_pointer __r = __p.__ptr_;
     if (__f != __l)
     {
         __node_allocator& __a = base::__alloc();
@@ -1192,7 +1201,7 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
 {
-    __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
+    __node_pointer __p = __f.__ptr_;
     __node_pointer __n = __p->__next_;
     __p->__next_ = __n->__next_;
     __node_allocator& __a = base::__alloc();
@@ -1205,10 +1214,10 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
 {
-    __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
+    __node_pointer __e = __l.__ptr_;
     if (__f != __l)
     {
-        __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
+        __node_pointer __p = __f.__ptr_;
         __node_pointer __n = __p->__next_;
         if (__n != __e)
         {
@@ -1302,12 +1311,10 @@
             const_iterator __lm1 = __x.before_begin();
             while (__lm1.__ptr_->__next_ != nullptr)
                 ++__lm1;
-            const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
-                const_cast<__node_pointer>(__p.__ptr_)->__next_;
+            __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
         }
-        const_cast<__node_pointer>(__p.__ptr_)->__next_ =
-            const_cast<__node_pointer>(__x.__before_begin())->__next_;
-        const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr;
+        __p.__ptr_->__next_ = __x.__before_begin()->__next_;
+        __x.__before_begin()->__next_ = nullptr;
     }
 }
 
@@ -1320,12 +1327,9 @@
     const_iterator __lm1 = _VSTD::next(__i);
     if (__p != __i && __p != __lm1)
     {
-        const_cast<__node_pointer>(__i.__ptr_)->__next_ =
-            const_cast<__node_pointer>(__lm1.__ptr_)->__next_;
-        const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
-            const_cast<__node_pointer>(__p.__ptr_)->__next_;
-        const_cast<__node_pointer>(__p.__ptr_)->__next_ =
-            const_cast<__node_pointer>(__lm1.__ptr_);
+        __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
+        __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
+        __p.__ptr_->__next_ = __lm1.__ptr_;
     }
 }
 
@@ -1342,12 +1346,9 @@
             ++__lm1;
         if (__f != __lm1)
         {
-            const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
-                const_cast<__node_pointer>(__p.__ptr_)->__next_;
-            const_cast<__node_pointer>(__p.__ptr_)->__next_ =
-                const_cast<__node_pointer>(__f.__ptr_)->__next_;
-            const_cast<__node_pointer>(__f.__ptr_)->__next_ =
-                const_cast<__node_pointer>(__l.__ptr_);
+            __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
+            __p.__ptr_->__next_ = __f.__ptr_->__next_;
+            __f.__ptr_->__next_ = __l.__ptr_;
         }
     }
 }

Modified: trunk/contrib/libc++/include/fstream
===================================================================
--- trunk/contrib/libc++/include/fstream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/fstream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -180,7 +180,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_filebuf
+class _LIBCPP_TYPE_VIS basic_filebuf
     : public basic_streambuf<_CharT, _Traits>
 {
 public:
@@ -234,6 +234,7 @@
     FILE* __file_;
     const codecvt<char_type, char, state_type>* __cv_;
     state_type __st_;
+    state_type __st_last_;
     ios_base::openmode __om_;
     ios_base::openmode __cm_;
     bool __owns_eb_;
@@ -253,14 +254,20 @@
       __intbuf_(0),
       __ibs_(0),
       __file_(0),
-      __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
+      __cv_(nullptr),
       __st_(),
+      __st_last_(),
       __om_(0),
       __cm_(0),
       __owns_eb_(false),
       __owns_ib_(false),
-      __always_noconv_(__cv_->always_noconv())
+      __always_noconv_(false)
 {
+    if (has_facet<codecvt<char_type, char, state_type> >(this->getloc()))
+    {
+        __cv_ = &use_facet<codecvt<char_type, char, state_type> >(this->getloc());
+        __always_noconv_ = __cv_->always_noconv();
+    }
     setbuf(0, 4096);
 }
 
@@ -288,6 +295,7 @@
     __file_ = __rhs.__file_;
     __cv_ = __rhs.__cv_;
     __st_ = __rhs.__st_;
+    __st_last_ = __rhs.__st_last_;
     __om_ = __rhs.__om_;
     __cm_ = __rhs.__cm_;
     __owns_eb_ = __rhs.__owns_eb_;
@@ -320,6 +328,7 @@
     __rhs.__ibs_ = 0;
     __rhs.__file_ = 0;
     __rhs.__st_ = state_type();
+    __rhs.__st_last_ = state_type();
     __rhs.__om_ = 0;
     __rhs.__cm_ = 0;
     __rhs.__owns_eb_ = false;
@@ -335,6 +344,7 @@
 {
     close();
     swap(__rhs);
+    return *this;
 }
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -397,6 +407,7 @@
     _VSTD::swap(__file_, __rhs.__file_);
     _VSTD::swap(__cv_, __rhs.__cv_);
     _VSTD::swap(__st_, __rhs.__st_);
+    _VSTD::swap(__st_last_, __rhs.__st_last_);
     _VSTD::swap(__om_, __rhs.__om_);
     _VSTD::swap(__cm_, __rhs.__cm_);
     _VSTD::swap(__owns_eb_, __rhs.__owns_eb_);
@@ -591,18 +602,22 @@
             memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
             __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
             __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
-            size_t __nmemb = _VSTD::min(static_cast<size_t>(this->egptr() - this->eback() - __unget_sz),
+            size_t __nmemb = _VSTD::min(static_cast<size_t>(__ibs_ - __unget_sz),
                                  static_cast<size_t>(__extbufend_ - __extbufnext_));
             codecvt_base::result __r;
-            state_type __svs = __st_;
+            __st_last_ = __st_;
             size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_);
             if (__nr != 0)
             {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                if (!__cv_)
+                    throw bad_cast();
+#endif
                 __extbufend_ = __extbufnext_ + __nr;
                 char_type*  __inext;
                 __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
                                        this->eback() + __unget_sz,
-                                       this->egptr(), __inext);
+                                       this->eback() + __ibs_, __inext);
                 if (__r == codecvt_base::noconv)
                 {
                     this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_);
@@ -676,6 +691,10 @@
             codecvt_base::result __r;
             do
             {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                if (!__cv_)
+                    throw bad_cast();
+#endif
                 const char_type* __e;
                 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
                                         __extbuf_, __extbuf_ + __ebs_, __extbe);
@@ -765,6 +784,10 @@
 basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
                                         ios_base::openmode)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (!__cv_)
+        throw bad_cast();
+#endif
     int __width = __cv_->encoding();
     if (__file_ == 0 || (__width <= 0 && __off != 0) || sync())
         return pos_type(off_type(-1));
@@ -784,9 +807,15 @@
     default:
         return pos_type(off_type(-1));
     }
+#if _WIN32
+    if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
+        return pos_type(off_type(-1));
+    pos_type __r = ftell(__file_);
+#else
     if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence))
         return pos_type(off_type(-1));
     pos_type __r = ftello(__file_);
+#endif
     __r.state(__st_);
     return __r;
 }
@@ -797,8 +826,14 @@
 {
     if (__file_ == 0 || sync())
         return pos_type(off_type(-1));
+#if _WIN32
+    if (fseek(__file_, __sp, SEEK_SET))
+        return pos_type(off_type(-1));
+#else
     if (fseeko(__file_, __sp, SEEK_SET))
         return pos_type(off_type(-1));
+#endif
+    __st_ = __sp.state();
     return __sp;
 }
 
@@ -808,6 +843,10 @@
 {
     if (__file_ == 0)
         return 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (!__cv_)
+        throw bad_cast();
+#endif
     if (__cm_ & ios_base::out)
     {
         if (this->pptr() != this->pbase())
@@ -830,6 +869,8 @@
     else if (__cm_ & ios_base::in)
     {
         off_type __c;
+        state_type __state = __st_last_;
+        bool __update_st = false;
         if (__always_noconv_)
             __c = this->egptr() - this->gptr();
         else
@@ -842,32 +883,24 @@
             {
                 if (this->gptr() != this->egptr())
                 {
-                    reverse(this->gptr(), this->egptr());
-                    codecvt_base::result __r;
-                    const char_type* __e = this->gptr();
-                    char* __extbe;
-                    do
-                    {
-                        __r = __cv_->out(__st_, __e, this->egptr(), __e,
-                                         __extbuf_, __extbuf_ + __ebs_, __extbe);
-                        switch (__r)
-                        {
-                        case codecvt_base::noconv:
-                            __c += this->egptr() - this->gptr();
-                            break;
-                        case codecvt_base::ok:
-                        case codecvt_base::partial:
-                            __c += __extbe - __extbuf_;
-                            break;
-                        default:
-                            return -1;
-                        }
-                    } while (__r == codecvt_base::partial);
+                    const int __off =  __cv_->length(__state, __extbuf_,
+                                                     __extbufnext_,
+                                                     this->gptr() - this->eback());
+                    __c += __extbufnext_ - __extbuf_ - __off;
+                    __update_st = true;
                 }
             }
         }
+#if _WIN32
+        if (fseek(__file_, -__c, SEEK_CUR))
+            return -1;
+#else
         if (fseeko(__file_, -__c, SEEK_CUR))
             return -1;
+#endif
+        if (__update_st)
+            __st_ = __state;
+        __extbufnext_ = __extbufend_ = __extbuf_;
         this->setg(0, 0, 0);
         __cm_ = 0;
     }
@@ -961,7 +994,7 @@
 // basic_ifstream
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_ifstream
+class _LIBCPP_TYPE_VIS basic_ifstream
     : public basic_istream<_CharT, _Traits>
 {
 public:
@@ -1106,7 +1139,7 @@
 // basic_ofstream
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_ofstream
+class _LIBCPP_TYPE_VIS basic_ofstream
     : public basic_ostream<_CharT, _Traits>
 {
 public:
@@ -1251,7 +1284,7 @@
 // basic_fstream
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_fstream
+class _LIBCPP_TYPE_VIS basic_fstream
     : public basic_iostream<_CharT, _Traits>
 {
 public:

Modified: trunk/contrib/libc++/include/functional
===================================================================
--- trunk/contrib/libc++/include/functional	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/functional	2016-01-07 17:22:14 UTC (rev 7405)
@@ -474,7 +474,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS plus : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x + __y;}
@@ -481,7 +481,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS minus : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x - __y;}
@@ -488,7 +488,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x * __y;}
@@ -495,7 +495,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS divides : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x / __y;}
@@ -502,7 +502,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x % __y;}
@@ -509,7 +509,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp>
+struct _LIBCPP_TYPE_VIS negate : unary_function<_Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
         {return -__x;}
@@ -516,7 +516,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS equal_to : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x == __y;}
@@ -523,7 +523,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x != __y;}
@@ -530,7 +530,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS greater : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x > __y;}
@@ -539,7 +539,7 @@
 // less in <__functional_base>
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x >= __y;}
@@ -546,7 +546,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS less_equal : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x <= __y;}
@@ -553,7 +553,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS logical_and : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x && __y;}
@@ -560,7 +560,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool>
+struct _LIBCPP_TYPE_VIS logical_or : binary_function<_Tp, _Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
         {return __x || __y;}
@@ -567,7 +567,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool>
+struct _LIBCPP_TYPE_VIS logical_not : unary_function<_Tp, bool>
 {
     _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
         {return !__x;}
@@ -574,7 +574,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x & __y;}
@@ -581,7 +581,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x | __y;}
@@ -588,7 +588,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp>
+struct _LIBCPP_TYPE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
 {
     _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
         {return __x ^ __y;}
@@ -595,7 +595,7 @@
 };
 
 template <class _Predicate>
-class _LIBCPP_VISIBLE unary_negate
+class _LIBCPP_TYPE_VIS unary_negate
     : public unary_function<typename _Predicate::argument_type, bool>
 {
     _Predicate __pred_;
@@ -612,7 +612,7 @@
 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
 
 template <class _Predicate>
-class _LIBCPP_VISIBLE binary_negate
+class _LIBCPP_TYPE_VIS binary_negate
     : public binary_function<typename _Predicate::first_argument_type,
                              typename _Predicate::second_argument_type,
                              bool>
@@ -632,7 +632,7 @@
 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
 
 template <class __Operation>
-class _LIBCPP_VISIBLE binder1st
+class _LIBCPP_TYPE_VIS binder1st
     : public unary_function<typename __Operation::second_argument_type,
                             typename __Operation::result_type>
 {
@@ -658,7 +658,7 @@
     {return binder1st<__Operation>(__op, __x);}
 
 template <class __Operation>
-class _LIBCPP_VISIBLE binder2nd
+class _LIBCPP_TYPE_VIS binder2nd
     : public unary_function<typename __Operation::first_argument_type,
                             typename __Operation::result_type>
 {
@@ -684,7 +684,7 @@
     {return binder2nd<__Operation>(__op, __x);}
 
 template <class _Arg, class _Result>
-class _LIBCPP_VISIBLE pointer_to_unary_function
+class _LIBCPP_TYPE_VIS pointer_to_unary_function
     : public unary_function<_Arg, _Result>
 {
     _Result (*__f_)(_Arg);
@@ -702,7 +702,7 @@
     {return pointer_to_unary_function<_Arg,_Result>(__f);}
 
 template <class _Arg1, class _Arg2, class _Result>
-class _LIBCPP_VISIBLE pointer_to_binary_function
+class _LIBCPP_TYPE_VIS pointer_to_binary_function
     : public binary_function<_Arg1, _Arg2, _Result>
 {
     _Result (*__f_)(_Arg1, _Arg2);
@@ -720,7 +720,7 @@
     {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
 
 template<class _Sp, class _Tp>
-class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp>
+class _LIBCPP_TYPE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
 {
     _Sp (_Tp::*__p_)();
 public:
@@ -731,7 +731,7 @@
 };
 
 template<class _Sp, class _Tp, class _Ap>
-class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
+class _LIBCPP_TYPE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
 {
     _Sp (_Tp::*__p_)(_Ap);
 public:
@@ -754,7 +754,7 @@
     {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
 
 template<class _Sp, class _Tp>
-class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp>
+class _LIBCPP_TYPE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
 {
     _Sp (_Tp::*__p_)();
 public:
@@ -765,7 +765,7 @@
 };
 
 template<class _Sp, class _Tp, class _Ap>
-class _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
+class _LIBCPP_TYPE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
 {
     _Sp (_Tp::*__p_)(_Ap);
 public:
@@ -788,7 +788,7 @@
     {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
 
 template <class _Sp, class _Tp>
-class _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp>
+class _LIBCPP_TYPE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
 {
     _Sp (_Tp::*__p_)() const;
 public:
@@ -799,7 +799,7 @@
 };
 
 template <class _Sp, class _Tp, class _Ap>
-class _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
+class _LIBCPP_TYPE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
 {
     _Sp (_Tp::*__p_)(_Ap) const;
 public:
@@ -822,7 +822,7 @@
     {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
 
 template <class _Sp, class _Tp>
-class _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
+class _LIBCPP_TYPE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
 {
     _Sp (_Tp::*__p_)() const;
 public:
@@ -833,7 +833,7 @@
 };
 
 template <class _Sp, class _Tp, class _Ap>
-class _LIBCPP_VISIBLE const_mem_fun1_ref_t
+class _LIBCPP_TYPE_VIS const_mem_fun1_ref_t
     : public binary_function<_Tp, _Ap, _Sp>
 {
     _Sp (_Tp::*__p_)(_Ap) const;
@@ -932,7 +932,7 @@
 {
 };
 
-template<class _Fp> class _LIBCPP_VISIBLE function; // undefined
+template<class _Fp> class _LIBCPP_TYPE_VIS function; // undefined
 
 namespace __function
 {
@@ -1083,12 +1083,12 @@
 }  // __function
 
 template<class _Rp, class ..._ArgTypes>
-class _LIBCPP_VISIBLE function<_Rp(_ArgTypes...)>
+class _LIBCPP_TYPE_VIS function<_Rp(_ArgTypes...)>
     : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
       public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
 {
     typedef __function::__base<_Rp(_ArgTypes...)> __base;
-    aligned_storage<3*sizeof(void*)>::type __buf_;
+    typename aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
     template <class _Fp>
@@ -1113,7 +1113,8 @@
         _LIBCPP_INLINE_VISIBILITY
         static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
 
-    template <class _Fp, bool = __invokable<_Fp&, _ArgTypes...>::value>
+    template <class _Fp, bool = !is_same<_Fp, function>::value &&
+                                __invokable<_Fp&, _ArgTypes...>::value>
         struct __callable;
     template <class _Fp>
         struct __callable<_Fp, true>
@@ -1138,8 +1139,11 @@
     function(const function&);
     function(function&&) _NOEXCEPT;
     template<class _Fp>
-      function(_Fp,
-               typename enable_if<__callable<_Fp>::value>::type* = 0);
+      function(_Fp, typename enable_if
+                                     <
+                                        __callable<_Fp>::value &&
+                                        !is_same<_Fp, function>::value
+                                      >::type* = 0);
 
     template<class _Alloc>
       _LIBCPP_INLINE_VISIBILITY
@@ -1161,7 +1165,8 @@
     template<class _Fp>
       typename enable_if
       <
-        __callable<typename decay<_Fp>::type>::value,
+        __callable<typename decay<_Fp>::type>::value &&
+        !is_same<typename remove_reference<_Fp>::type, function>::value,
         function&
       >::type
       operator=(_Fp&&);
@@ -1265,7 +1270,11 @@
 template<class _Rp, class ..._ArgTypes>
 template <class _Fp>
 function<_Rp(_ArgTypes...)>::function(_Fp __f,
-                                     typename enable_if<__callable<_Fp>::value>::type*)
+                                     typename enable_if
+                                     <
+                                        __callable<_Fp>::value &&
+                                        !is_same<_Fp, function>::value
+                                     >::type*)
     : __f_(0)
 {
     if (__not_null(__f))
@@ -1350,6 +1359,7 @@
         __f_ = __f.__f_;
         __f.__f_ = 0;
     }
+    return *this;
 }
 
 template<class _Rp, class ..._ArgTypes>
@@ -1361,6 +1371,7 @@
     else if (__f_)
         __f_->destroy_deallocate();
     __f_ = 0;
+    return *this;
 }
 
 template<class _Rp, class ..._ArgTypes>
@@ -1367,7 +1378,8 @@
 template <class _Fp>
 typename enable_if
 <
-    function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value,
+    function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
+    !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
     function<_Rp(_ArgTypes...)>&
 >::type
 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
@@ -1493,11 +1505,11 @@
 {return __x.swap(__y);}
 
 template<class _Tp> struct __is_bind_expression : public false_type {};
-template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
+template<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression
     : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
 
 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
-template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
+template<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder
     : public __is_placeholder<typename remove_cv<_Tp>::type> {};
 
 namespace placeholders
@@ -1591,12 +1603,24 @@
           class _TupleUj>
 struct ____mu_return;
 
+template <bool _Invokable, class _Ti, class ..._Uj>
+struct ____mu_return_invokable  // false
+{
+    typedef __nat type;
+};
+
 template <class _Ti, class ..._Uj>
-struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
+struct ____mu_return_invokable<true, _Ti, _Uj...>
 {
     typedef typename __invoke_of<_Ti&, _Uj...>::type type;
 };
 
+template <class _Ti, class ..._Uj>
+struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
+    : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
+{
+};
+
 template <class _Ti, class _TupleUj>
 struct ____mu_return<_Ti, false, false, true, _TupleUj>
 {
@@ -1621,16 +1645,38 @@
     : public ____mu_return<_Ti,
                            __is_reference_wrapper<_Ti>::value,
                            is_bind_expression<_Ti>::value,
-                           0 < is_placeholder<_Ti>::value,
+                           0 < is_placeholder<_Ti>::value &&
+                           is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
                            _TupleUj>
 {
 };
 
 template <class _Fp, class _BoundArgs, class _TupleUj>
+struct _is_valid_bind_return
+{
+    static const bool value = false;
+};
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
+{
+    static const bool value = __invokable<_Fp,
+                    typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
+};
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
+{
+    static const bool value = __invokable<_Fp,
+                    typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
+};
+
+template <class _Fp, class _BoundArgs, class _TupleUj,
+          bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
 struct __bind_return;
 
 template <class _Fp, class ..._BoundArgs, class _TupleUj>
-struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
+struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
 {
     typedef typename __invoke_of
     <
@@ -1644,7 +1690,7 @@
 };
 
 template <class _Fp, class ..._BoundArgs, class _TupleUj>
-struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
+struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
 {
     typedef typename __invoke_of
     <
@@ -1670,8 +1716,10 @@
 class __bind
     : public __weak_result_type<typename decay<_Fp>::type>
 {
+protected:
     typedef typename decay<_Fp>::type _Fd;
     typedef tuple<typename decay<_BoundArgs>::type...> _Td;
+private:
     _Fd __f_;
     _Td __bound_args_;
 
@@ -1707,7 +1755,13 @@
 
 #endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 
-    template <class _Gp, class ..._BA>
+    template <class _Gp, class ..._BA,
+              class = typename enable_if
+                               <
+                                  is_constructible<_Fd, _Gp>::value &&
+                                  !is_same<typename remove_reference<_Gp>::type,
+                                           __bind>::value
+                               >::type>
       _LIBCPP_INLINE_VISIBILITY
       explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
         : __f_(_VSTD::forward<_Gp>(__f)),
@@ -1724,7 +1778,7 @@
 
     template <class ..._Args>
         _LIBCPP_INLINE_VISIBILITY
-        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
+        typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
         operator()(_Args&& ...__args) const
         {
             return __apply_functor(__f_, __bound_args_, __indices(),
@@ -1740,6 +1794,8 @@
     : public __bind<_Fp, _BoundArgs...>
 {
     typedef __bind<_Fp, _BoundArgs...> base;
+    typedef typename base::_Fd _Fd;
+    typedef typename base::_Td _Td;
 public:
     typedef _Rp result_type;
 
@@ -1769,7 +1825,13 @@
 
 #endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 
-    template <class _Gp, class ..._BA>
+    template <class _Gp, class ..._BA,
+              class = typename enable_if
+                               <
+                                  is_constructible<_Fd, _Gp>::value &&
+                                  !is_same<typename remove_reference<_Gp>::type,
+                                           __bind_r>::value
+                               >::type>
       _LIBCPP_INLINE_VISIBILITY
       explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
         : base(_VSTD::forward<_Gp>(__f),
@@ -1777,7 +1839,12 @@
 
     template <class ..._Args>
         _LIBCPP_INLINE_VISIBILITY
-        result_type
+        typename enable_if
+        <
+            is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
+                           result_type>::value,
+            result_type
+        >::type
         operator()(_Args&& ...__args)
         {
             return base::operator()(_VSTD::forward<_Args>(__args)...);
@@ -1785,7 +1852,12 @@
 
     template <class ..._Args>
         _LIBCPP_INLINE_VISIBILITY
-        result_type
+        typename enable_if
+        <
+            is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
+                           result_type>::value,
+            result_type
+        >::type
         operator()(_Args&& ...__args) const
         {
             return base::operator()(_VSTD::forward<_Args>(__args)...);
@@ -1816,7 +1888,7 @@
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
 template <>
-struct _LIBCPP_VISIBLE hash<bool>
+struct _LIBCPP_TYPE_VIS hash<bool>
     : public unary_function<bool, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1824,7 +1896,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<char>
+struct _LIBCPP_TYPE_VIS hash<char>
     : public unary_function<char, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1832,7 +1904,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<signed char>
+struct _LIBCPP_TYPE_VIS hash<signed char>
     : public unary_function<signed char, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1840,7 +1912,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<unsigned char>
+struct _LIBCPP_TYPE_VIS hash<unsigned char>
     : public unary_function<unsigned char, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1850,7 +1922,7 @@
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 
 template <>
-struct _LIBCPP_VISIBLE hash<char16_t>
+struct _LIBCPP_TYPE_VIS hash<char16_t>
     : public unary_function<char16_t, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1858,7 +1930,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<char32_t>
+struct _LIBCPP_TYPE_VIS hash<char32_t>
     : public unary_function<char32_t, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1868,7 +1940,7 @@
 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
 
 template <>
-struct _LIBCPP_VISIBLE hash<wchar_t>
+struct _LIBCPP_TYPE_VIS hash<wchar_t>
     : public unary_function<wchar_t, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1876,7 +1948,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<short>
+struct _LIBCPP_TYPE_VIS hash<short>
     : public unary_function<short, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1884,7 +1956,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<unsigned short>
+struct _LIBCPP_TYPE_VIS hash<unsigned short>
     : public unary_function<unsigned short, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1892,7 +1964,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<int>
+struct _LIBCPP_TYPE_VIS hash<int>
     : public unary_function<int, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1900,7 +1972,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<unsigned int>
+struct _LIBCPP_TYPE_VIS hash<unsigned int>
     : public unary_function<unsigned int, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1908,7 +1980,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<long>
+struct _LIBCPP_TYPE_VIS hash<long>
     : public unary_function<long, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1916,7 +1988,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<unsigned long>
+struct _LIBCPP_TYPE_VIS hash<unsigned long>
     : public unary_function<unsigned long, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1924,19 +1996,19 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<long long>
+struct _LIBCPP_TYPE_VIS hash<long long>
     : public __scalar_hash<long long>
 {
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<unsigned long long>
+struct _LIBCPP_TYPE_VIS hash<unsigned long long>
     : public __scalar_hash<unsigned long long>
 {
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<float>
+struct _LIBCPP_TYPE_VIS hash<float>
     : public __scalar_hash<float>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1950,7 +2022,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<double>
+struct _LIBCPP_TYPE_VIS hash<double>
     : public __scalar_hash<double>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -1964,7 +2036,7 @@
 };
 
 template <>
-struct _LIBCPP_VISIBLE hash<long double>
+struct _LIBCPP_TYPE_VIS hash<long double>
     : public __scalar_hash<long double>
 {
     _LIBCPP_INLINE_VISIBILITY

Modified: trunk/contrib/libc++/include/future
===================================================================
--- trunk/contrib/libc++/include/future	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/future	2016-01-07 17:22:14 UTC (rev 7405)
@@ -40,10 +40,10 @@
 };
 
 template <> struct is_error_code_enum<future_errc> : public true_type { };
-error_code make_error_code(future_errc e);
-error_condition make_error_condition(future_errc e);
+error_code make_error_code(future_errc e) noexcept;
+error_condition make_error_condition(future_errc e) noexcept;
 
-const error_category& future_category();
+const error_category& future_category() noexcept;
 
 class future_error
     : public logic_error
@@ -51,8 +51,8 @@
 public:
     future_error(error_code ec);  // exposition only
 
-    const error_code& code() const throw();
-    const char*       what() const throw();
+    const error_code& code() const noexcept;
+    const char*       what() const noexcept;
 };
 
 template <class R>
@@ -62,14 +62,14 @@
     promise();
     template <class Allocator>
         promise(allocator_arg_t, const Allocator& a);
-    promise(promise&& rhs);
+    promise(promise&& rhs) noexcept;
     promise(const promise& rhs) = delete;
     ~promise();
 
     // assignment
-    promise& operator=(promise&& rhs);
+    promise& operator=(promise&& rhs) noexcept;
     promise& operator=(const promise& rhs) = delete;
-    void swap(promise& other);
+    void swap(promise& other) noexcept;
 
     // retrieving the result
     future<R> get_future();
@@ -92,14 +92,14 @@
     promise();
     template <class Allocator>
         promise(allocator_arg_t, const Allocator& a);
-    promise(promise&& rhs);
+    promise(promise&& rhs) noexcept;
     promise(const promise& rhs) = delete;
     ~promise();
 
     // assignment
-    promise& operator=(promise&& rhs);
+    promise& operator=(promise&& rhs) noexcept;
     promise& operator=(const promise& rhs) = delete;
-    void swap(promise& other);
+    void swap(promise& other) noexcept;
 
     // retrieving the result
     future<R&> get_future();
@@ -120,14 +120,14 @@
     promise();
     template <class Allocator>
         promise(allocator_arg_t, const Allocator& a);
-    promise(promise&& rhs);
+    promise(promise&& rhs) noexcept;
     promise(const promise& rhs) = delete;
     ~promise();
 
     // assignment
-    promise& operator=(promise&& rhs);
+    promise& operator=(promise&& rhs) noexcept;
     promise& operator=(const promise& rhs) = delete;
-    void swap(promise& other);
+    void swap(promise& other) noexcept;
 
     // retrieving the result
     future<void> get_future();
@@ -141,7 +141,7 @@
     void set_exception_at_thread_exit(exception_ptr p);
 };
 
-template <class R> void swap(promise<R>& x, promise<R>& y);
+template <class R> void swap(promise<R>& x, promise<R>& y) noexcept;
 
 template <class R, class Alloc>
     struct uses_allocator<promise<R>, Alloc> : public true_type {};
@@ -150,19 +150,19 @@
 class future
 {
 public:
-    future();
-    future(future&&);
+    future() noexcept;
+    future(future&&) noexcept;
     future(const future& rhs) = delete;
     ~future();
     future& operator=(const future& rhs) = delete;
-    future& operator=(future&&);
-    shared_future<R> share() &&;
+    future& operator=(future&&) noexcept;
+    shared_future<R> share();
 
     // retrieving the value
     R get();
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -177,19 +177,19 @@
 class future<R&>
 {
 public:
-    future();
-    future(future&&);
+    future() noexcept;
+    future(future&&) noexcept;
     future(const future& rhs) = delete;
     ~future();
     future& operator=(const future& rhs) = delete;
-    future& operator=(future&&);
-    shared_future<R&> share() &&;
+    future& operator=(future&&) noexcept;
+    shared_future<R&> share();
 
     // retrieving the value
     R& get();
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -204,19 +204,19 @@
 class future<void>
 {
 public:
-    future();
-    future(future&&);
+    future() noexcept;
+    future(future&&) noexcept;
     future(const future& rhs) = delete;
     ~future();
     future& operator=(const future& rhs) = delete;
-    future& operator=(future&&);
-    shared_future<void> share() &&;
+    future& operator=(future&&) noexcept;
+    shared_future<void> share();
 
     // retrieving the value
     void get();
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -231,19 +231,19 @@
 class shared_future
 {
 public:
-    shared_future();
+    shared_future() noexcept;
     shared_future(const shared_future& rhs);
-    shared_future(future<R>&&);
-    shared_future(shared_future&& rhs);
+    shared_future(future<R>&&) noexcept;
+    shared_future(shared_future&& rhs) noexcept;
     ~shared_future();
     shared_future& operator=(const shared_future& rhs);
-    shared_future& operator=(shared_future&& rhs);
+    shared_future& operator=(shared_future&& rhs) noexcept;
 
     // retrieving the value
     const R& get() const;
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -258,19 +258,19 @@
 class shared_future<R&>
 {
 public:
-    shared_future();
+    shared_future() noexcept;
     shared_future(const shared_future& rhs);
-    shared_future(future<R&>&&);
-    shared_future(shared_future&& rhs);
+    shared_future(future<R&>&&) noexcept;
+    shared_future(shared_future&& rhs) noexcept;
     ~shared_future();
     shared_future& operator=(const shared_future& rhs);
-    shared_future& operator=(shared_future&& rhs);
+    shared_future& operator=(shared_future&& rhs) noexcept;
 
     // retrieving the value
     R& get() const;
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -285,19 +285,19 @@
 class shared_future<void>
 {
 public:
-    shared_future();
+    shared_future() noexcept;
     shared_future(const shared_future& rhs);
-    shared_future(future<void>&&);
-    shared_future(shared_future&& rhs);
+    shared_future(future<void>&&) noexcept;
+    shared_future(shared_future&& rhs) noexcept;
     ~shared_future();
     shared_future& operator=(const shared_future& rhs);
-    shared_future& operator=(shared_future&& rhs);
+    shared_future& operator=(shared_future&& rhs) noexcept;
 
     // retrieving the value
     void get() const;
 
     // functions to check state
-    bool valid() const;
+    bool valid() const noexcept;
 
     void wait() const;
     template <class Rep, class Period>
@@ -325,7 +325,7 @@
     typedef R result_type;
 
     // construction and destruction
-    packaged_task();
+    packaged_task() noexcept;
     template <class F>
         explicit packaged_task(F&& f);
     template <class F, class Allocator>
@@ -333,15 +333,15 @@
     ~packaged_task();
 
     // no copy
-    packaged_task(packaged_task&) = delete;
-    packaged_task& operator=(packaged_task&) = delete;
+    packaged_task(const packaged_task&) = delete;
+    packaged_task& operator=(const packaged_task&) = delete;
 
     // move support
-    packaged_task(packaged_task&& other);
-    packaged_task& operator=(packaged_task&& other);
-    void swap(packaged_task& other);
+    packaged_task(packaged_task&& other) noexcept;
+    packaged_task& operator=(packaged_task&& other) noexcept;
+    void swap(packaged_task& other) noexcept;
 
-    bool valid() const;
+    bool valid() const noexcept;
 
     // result retrieval
     future<R> get_future();
@@ -354,7 +354,7 @@
 };
 
 template <class R>
-  void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&);
+  void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
 
 template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 
@@ -387,11 +387,11 @@
 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
 
 template <>
-struct _LIBCPP_VISIBLE is_error_code_enum<future_errc> : public true_type {};
+struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc> : public true_type {};
 
 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
 template <>
-struct _LIBCPP_VISIBLE is_error_code_enum<future_errc::_> : public true_type { };
+struct _LIBCPP_TYPE_VIS is_error_code_enum<future_errc::__lx> : public true_type { };
 #endif
 
 //enum class launch
@@ -403,6 +403,72 @@
 };
 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
 
+#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
+
+#ifdef _LIBCXX_UNDERLYING_TYPE
+typedef underlying_type<launch>::type __launch_underlying_type;
+#else
+typedef int __launch_underlying_type;
+#endif
+
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+launch
+operator&(launch __x, launch __y)
+{
+    return static_cast<launch>(static_cast<__launch_underlying_type>(__x) &
+                               static_cast<__launch_underlying_type>(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+launch
+operator|(launch __x, launch __y)
+{
+    return static_cast<launch>(static_cast<__launch_underlying_type>(__x) |
+                               static_cast<__launch_underlying_type>(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+launch
+operator^(launch __x, launch __y)
+{
+    return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^
+                               static_cast<__launch_underlying_type>(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
+launch
+operator~(launch __x)
+{
+    return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+launch&
+operator&=(launch& __x, launch __y)
+{
+    __x = __x & __y; return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+launch&
+operator|=(launch& __x, launch __y)
+{
+    __x = __x | __y; return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+launch&
+operator^=(launch& __x, launch __y)
+{
+    __x = __x ^ __y; return __x;
+}
+
+#endif  // !_LIBCPP_HAS_NO_STRONG_ENUMS
+
 //enum class future_status
 _LIBCPP_DECLARE_STRONG_ENUM(future_status)
 {
@@ -412,12 +478,12 @@
 };
 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
 
-_LIBCPP_VISIBLE
-const error_category& future_category();
+_LIBCPP_FUNC_VIS
+const error_category& future_category() _NOEXCEPT;
 
 inline _LIBCPP_INLINE_VISIBILITY
 error_code
-make_error_code(future_errc __e)
+make_error_code(future_errc __e) _NOEXCEPT
 {
     return error_code(static_cast<int>(__e), future_category());
 }
@@ -424,7 +490,7 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 error_condition
-make_error_condition(future_errc __e)
+make_error_condition(future_errc __e) _NOEXCEPT
 {
     return error_condition(static_cast<int>(__e), future_category());
 }
@@ -437,7 +503,7 @@
     future_error(error_code __ec);
 
     _LIBCPP_INLINE_VISIBILITY
-    const error_code& code() const throw() {return __ec_;}
+    const error_code& code() const _NOEXCEPT {return __ec_;}
 
     virtual ~future_error() _NOEXCEPT;
 };
@@ -470,7 +536,11 @@
         {return (__state_ & __constructed) || (__exception_ != nullptr);}
 
     _LIBCPP_INLINE_VISIBILITY
-    void __set_future_attached() {__state_ |= __future_attached;}
+    void __set_future_attached()
+    {
+        lock_guard<mutex> __lk(__mut_);
+        __state_ |= __future_attached;
+    }
     _LIBCPP_INLINE_VISIBILITY
     bool __has_future_attached() const {return __state_ & __future_attached;}
 
@@ -755,7 +825,6 @@
 void
 __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
 {
-    this->~base();
     typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_);
     this->~__assoc_sub_state_alloc();
     __a.deallocate(this, 1);
@@ -963,12 +1032,12 @@
     base::__on_zero_shared();
 }
 
-template <class _Rp> class promise;
-template <class _Rp> class shared_future;
+template <class _Rp> class _LIBCPP_TYPE_VIS promise;
+template <class _Rp> class _LIBCPP_TYPE_VIS shared_future;
 
 // future
 
-template <class _Rp> class future;
+template <class _Rp> class _LIBCPP_TYPE_VIS future;
 
 template <class _Rp, class _Fp>
 future<_Rp>
@@ -987,7 +1056,7 @@
 #endif
 
 template <class _Rp>
-class _LIBCPP_VISIBLE future
+class _LIBCPP_TYPE_VIS future
 {
     __assoc_state<_Rp>* __state_;
 
@@ -1010,15 +1079,15 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    future() : __state_(nullptr) {}
+    future() _NOEXCEPT : __state_(nullptr) {}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    future(future&& __rhs)
+    future(future&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     future(const future&) = delete;
     future& operator=(const future&) = delete;
     _LIBCPP_INLINE_VISIBILITY
-    future& operator=(future&& __rhs)
+    future& operator=(future&& __rhs) _NOEXCEPT
         {
             future(std::move(__rhs)).swap(*this);
             return *this;
@@ -1036,11 +1105,11 @@
     _Rp get();
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -1091,7 +1160,7 @@
 }
 
 template <class _Rp>
-class _LIBCPP_VISIBLE future<_Rp&>
+class _LIBCPP_TYPE_VIS future<_Rp&>
 {
     __assoc_state<_Rp&>* __state_;
 
@@ -1114,15 +1183,15 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    future() : __state_(nullptr) {}
+    future() _NOEXCEPT : __state_(nullptr) {}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    future(future&& __rhs)
+    future(future&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     future(const future&) = delete;
     future& operator=(const future&) = delete;
     _LIBCPP_INLINE_VISIBILITY
-    future& operator=(future&& __rhs)
+    future& operator=(future&& __rhs) _NOEXCEPT
         {
             future(std::move(__rhs)).swap(*this);
             return *this;
@@ -1140,11 +1209,11 @@
     _Rp& get();
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -1190,7 +1259,7 @@
 }
 
 template <>
-class _LIBCPP_VISIBLE future<void>
+class _LIBCPP_TYPE_VIS future<void>
 {
     __assoc_sub_state* __state_;
 
@@ -1213,15 +1282,15 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    future() : __state_(nullptr) {}
+    future() _NOEXCEPT : __state_(nullptr) {}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    future(future&& __rhs)
+    future(future&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     future(const future&) = delete;
     future& operator=(const future&) = delete;
     _LIBCPP_INLINE_VISIBILITY
-    future& operator=(future&& __rhs)
+    future& operator=(future&& __rhs) _NOEXCEPT
         {
             future(std::move(__rhs)).swap(*this);
             return *this;
@@ -1239,11 +1308,11 @@
     void get();
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -1262,7 +1331,7 @@
 template <class _Rp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(future<_Rp>& __x, future<_Rp>& __y)
+swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT
 {
     __x.swap(__y);
 }
@@ -1272,12 +1341,12 @@
 template <class _Callable> class packaged_task;
 
 template <class _Rp>
-class _LIBCPP_VISIBLE promise
+class _LIBCPP_TYPE_VIS promise
 {
     __assoc_state<_Rp>* __state_;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit promise(nullptr_t) : __state_(nullptr) {}
+    explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
 
     template <class> friend class packaged_task;
 public:
@@ -1286,7 +1355,7 @@
         promise(allocator_arg_t, const _Alloc& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise(promise&& __rhs)
+    promise(promise&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     promise(const promise& __rhs) = delete;
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1299,7 +1368,7 @@
     // assignment
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise& operator=(promise&& __rhs)
+    promise& operator=(promise&& __rhs) _NOEXCEPT
         {
             promise(std::move(__rhs)).swap(*this);
             return *this;
@@ -1311,7 +1380,7 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // retrieving the result
     future<_Rp> get_future();
@@ -1450,12 +1519,12 @@
 // promise<R&>
 
 template <class _Rp>
-class _LIBCPP_VISIBLE promise<_Rp&>
+class _LIBCPP_TYPE_VIS promise<_Rp&>
 {
     __assoc_state<_Rp&>* __state_;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit promise(nullptr_t) : __state_(nullptr) {}
+    explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
 
     template <class> friend class packaged_task;
 
@@ -1465,7 +1534,7 @@
         promise(allocator_arg_t, const _Allocator& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise(promise&& __rhs)
+    promise(promise&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     promise(const promise& __rhs) = delete;
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1478,7 +1547,7 @@
     // assignment
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise& operator=(promise&& __rhs)
+    promise& operator=(promise&& __rhs) _NOEXCEPT
         {
             promise(std::move(__rhs)).swap(*this);
             return *this;
@@ -1490,7 +1559,7 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // retrieving the result
     future<_Rp&> get_future();
@@ -1593,12 +1662,12 @@
 // promise<void>
 
 template <>
-class _LIBCPP_VISIBLE promise<void>
+class _LIBCPP_TYPE_VIS promise<void>
 {
     __assoc_sub_state* __state_;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit promise(nullptr_t) : __state_(nullptr) {}
+    explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
 
     template <class> friend class packaged_task;
 
@@ -1608,7 +1677,7 @@
         promise(allocator_arg_t, const _Allocator& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise(promise&& __rhs)
+    promise(promise&& __rhs) _NOEXCEPT
         : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
     promise(const promise& __rhs) = delete;
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1621,7 +1690,7 @@
     // assignment
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    promise& operator=(promise&& __rhs)
+    promise& operator=(promise&& __rhs) _NOEXCEPT
         {
             promise(std::move(__rhs)).swap(*this);
             return *this;
@@ -1633,7 +1702,7 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // retrieving the result
     future<void> get_future();
@@ -1661,13 +1730,13 @@
 template <class _Rp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(promise<_Rp>& __x, promise<_Rp>& __y)
+swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT
 {
     __x.swap(__y);
 }
 
 template <class _Rp, class _Alloc>
-    struct _LIBCPP_VISIBLE uses_allocator<promise<_Rp>, _Alloc>
+    struct _LIBCPP_TYPE_VIS uses_allocator<promise<_Rp>, _Alloc>
         : public true_type {};
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -1686,7 +1755,7 @@
     __packaged_task_base() {}
     _LIBCPP_INLINE_VISIBILITY
     virtual ~__packaged_task_base() {}
-    virtual void __move_to(__packaged_task_base*) = 0;
+    virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
     virtual void destroy() = 0;
     virtual void destroy_deallocate() = 0;
     virtual _Rp operator()(_ArgTypes&& ...) = 0;
@@ -1710,7 +1779,7 @@
     _LIBCPP_INLINE_VISIBILITY
     __packaged_task_func(_Fp&& __f, const _Alloc& __a)
         : __f_(_VSTD::move(__f), __a) {}
-    virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*);
+    virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
     virtual void destroy();
     virtual void destroy_deallocate();
     virtual _Rp operator()(_ArgTypes&& ... __args);
@@ -1719,7 +1788,7 @@
 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
 void
 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
-                              __packaged_task_base<_Rp(_ArgTypes...)>* __p)
+                              __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT
 {
     ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
 }
@@ -1754,7 +1823,7 @@
 class __packaged_task_function<_Rp(_ArgTypes...)>
 {
     typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
-    aligned_storage<3*sizeof(void*)>::type __buf_;
+    typename aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
 public:
@@ -1762,14 +1831,14 @@
 
     // construct/copy/destroy:
     _LIBCPP_INLINE_VISIBILITY
-    __packaged_task_function() : __f_(nullptr) {}
+    __packaged_task_function() _NOEXCEPT : __f_(nullptr) {}
     template<class _Fp>
       __packaged_task_function(_Fp&& __f);
     template<class _Fp, class _Alloc>
       __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
 
-    __packaged_task_function(__packaged_task_function&&);
-    __packaged_task_function& operator=(__packaged_task_function&&);
+    __packaged_task_function(__packaged_task_function&&) _NOEXCEPT;
+    __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT;
 
     __packaged_task_function(const __packaged_task_function&) =  delete;
     __packaged_task_function& operator=(const __packaged_task_function&) =  delete;
@@ -1776,13 +1845,13 @@
 
     ~__packaged_task_function();
 
-    void swap(__packaged_task_function&);
+    void swap(__packaged_task_function&) _NOEXCEPT;
 
     _Rp operator()(_ArgTypes...) const;
 };
 
 template<class _Rp, class ..._ArgTypes>
-__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f)
+__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT
 {
     if (__f.__f_ == nullptr)
         __f_ = nullptr;
@@ -1854,7 +1923,7 @@
 
 template<class _Rp, class ..._ArgTypes>
 __packaged_task_function<_Rp(_ArgTypes...)>&
-__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f)
+__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT
 {
     if (__f_ == (__base*)&__buf_)
         __f_->destroy();
@@ -1873,6 +1942,7 @@
         __f_ = __f.__f_;
         __f.__f_ = nullptr;
     }
+    return *this;
 }
 
 template<class _Rp, class ..._ArgTypes>
@@ -1886,7 +1956,7 @@
 
 template<class _Rp, class ..._ArgTypes>
 void
-__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f)
+__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT
 {
     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
     {
@@ -1930,7 +2000,7 @@
 }
 
 template<class _Rp, class ..._ArgTypes>
-class _LIBCPP_VISIBLE packaged_task<_Rp(_ArgTypes...)>
+class _LIBCPP_TYPE_VIS packaged_task<_Rp(_ArgTypes...)>
 {
 public:
     typedef _Rp result_type;
@@ -1942,7 +2012,7 @@
 public:
     // construction and destruction
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task() : __p_(nullptr) {}
+    packaged_task() _NOEXCEPT : __p_(nullptr) {}
     template <class _Fp>
         _LIBCPP_INLINE_VISIBILITY
         explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
@@ -1954,15 +2024,15 @@
     // ~packaged_task() = default;
 
     // no copy
-    packaged_task(packaged_task&) = delete;
-    packaged_task& operator=(packaged_task&) = delete;
+    packaged_task(const packaged_task&) = delete;
+    packaged_task& operator=(const packaged_task&) = delete;
 
     // move support
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task(packaged_task&& __other)
+    packaged_task(packaged_task&& __other) _NOEXCEPT
         : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task& operator=(packaged_task&& __other)
+    packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
     {
         __f_ = _VSTD::move(__other.__f_);
         __p_ = _VSTD::move(__other.__p_);
@@ -1969,7 +2039,7 @@
         return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
-    void swap(packaged_task& __other)
+    void swap(packaged_task& __other) _NOEXCEPT
     {
         __f_.swap(__other.__f_);
         __p_.swap(__other.__p_);
@@ -1976,7 +2046,7 @@
     }
 
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __p_.__state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
 
     // result retrieval
     _LIBCPP_INLINE_VISIBILITY
@@ -2045,7 +2115,7 @@
 }
 
 template<class ..._ArgTypes>
-class _LIBCPP_VISIBLE packaged_task<void(_ArgTypes...)>
+class _LIBCPP_TYPE_VIS packaged_task<void(_ArgTypes...)>
 {
 public:
     typedef void result_type;
@@ -2057,7 +2127,7 @@
 public:
     // construction and destruction
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task() : __p_(nullptr) {}
+    packaged_task() _NOEXCEPT : __p_(nullptr) {}
     template <class _Fp>
         _LIBCPP_INLINE_VISIBILITY
         explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
@@ -2069,15 +2139,15 @@
     // ~packaged_task() = default;
 
     // no copy
-    packaged_task(packaged_task&) = delete;
-    packaged_task& operator=(packaged_task&) = delete;
+    packaged_task(const packaged_task&) = delete;
+    packaged_task& operator=(const packaged_task&) = delete;
 
     // move support
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task(packaged_task&& __other)
+    packaged_task(packaged_task&& __other) _NOEXCEPT
         : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
     _LIBCPP_INLINE_VISIBILITY
-    packaged_task& operator=(packaged_task&& __other)
+    packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
     {
         __f_ = _VSTD::move(__other.__f_);
         __p_ = _VSTD::move(__other.__p_);
@@ -2084,7 +2154,7 @@
         return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
-    void swap(packaged_task& __other)
+    void swap(packaged_task& __other) _NOEXCEPT
     {
         __f_.swap(__other.__f_);
         __p_.swap(__other.__p_);
@@ -2091,7 +2161,7 @@
     }
 
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __p_.__state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
 
     // result retrieval
     _LIBCPP_INLINE_VISIBILITY
@@ -2164,13 +2234,13 @@
 template <class _Callable>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y)
+swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT
 {
     __x.swap(__y);
 }
 
 template <class _Callable, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator<packaged_task<_Callable>, _Alloc>
+struct _LIBCPP_TYPE_VIS uses_allocator<packaged_task<_Callable>, _Alloc>
     : public true_type {};
 
 template <class _Rp, class _Fp>
@@ -2259,22 +2329,22 @@
 // shared_future
 
 template <class _Rp>
-class _LIBCPP_VISIBLE shared_future
+class _LIBCPP_TYPE_VIS shared_future
 {
     __assoc_state<_Rp>* __state_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    shared_future() : __state_(nullptr) {}
+    shared_future() _NOEXCEPT : __state_(nullptr) {}
     _LIBCPP_INLINE_VISIBILITY
     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
         {if (__state_) __state_->__add_shared();}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(future<_Rp>&& __f) : __state_(__f.__state_)
+    shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_)
         {__f.__state_ = nullptr;}
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
+    shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
         {__rhs.__state_ = nullptr;}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~shared_future();
@@ -2281,7 +2351,7 @@
     shared_future& operator=(const shared_future& __rhs);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future& operator=(shared_future&& __rhs)
+    shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
         {
             shared_future(std::move(__rhs)).swap(*this);
             return *this;
@@ -2293,11 +2363,11 @@
     const _Rp& get() const {return __state_->copy();}
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -2333,22 +2403,22 @@
 }
 
 template <class _Rp>
-class _LIBCPP_VISIBLE shared_future<_Rp&>
+class _LIBCPP_TYPE_VIS shared_future<_Rp&>
 {
     __assoc_state<_Rp&>* __state_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    shared_future() : __state_(nullptr) {}
+    shared_future() _NOEXCEPT : __state_(nullptr) {}
     _LIBCPP_INLINE_VISIBILITY
     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
         {if (__state_) __state_->__add_shared();}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(future<_Rp&>&& __f) : __state_(__f.__state_)
+    shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_)
         {__f.__state_ = nullptr;}
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
+    shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
         {__rhs.__state_ = nullptr;}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~shared_future();
@@ -2355,7 +2425,7 @@
     shared_future& operator=(const shared_future& __rhs);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future& operator=(shared_future&& __rhs)
+    shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
         {
             shared_future(std::move(__rhs)).swap(*this);
             return *this;
@@ -2367,11 +2437,11 @@
     _Rp& get() const {return __state_->copy();}
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -2407,22 +2477,22 @@
 }
 
 template <>
-class _LIBCPP_VISIBLE shared_future<void>
+class _LIBCPP_TYPE_VIS shared_future<void>
 {
     __assoc_sub_state* __state_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    shared_future() : __state_(nullptr) {}
+    shared_future() _NOEXCEPT : __state_(nullptr) {}
     _LIBCPP_INLINE_VISIBILITY
     shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
         {if (__state_) __state_->__add_shared();}
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(future<void>&& __f) : __state_(__f.__state_)
+    shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_)
         {__f.__state_ = nullptr;}
     _LIBCPP_INLINE_VISIBILITY
-    shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
+    shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
         {__rhs.__state_ = nullptr;}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~shared_future();
@@ -2429,7 +2499,7 @@
     shared_future& operator=(const shared_future& __rhs);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    shared_future& operator=(shared_future&& __rhs)
+    shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
         {
             shared_future(std::move(__rhs)).swap(*this);
             return *this;
@@ -2441,11 +2511,11 @@
     void get() const {__state_->copy();}
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
+    void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
 
     // functions to check state
     _LIBCPP_INLINE_VISIBILITY
-    bool valid() const {return __state_ != nullptr;}
+    bool valid() const _NOEXCEPT {return __state_ != nullptr;}
 
     _LIBCPP_INLINE_VISIBILITY
     void wait() const {__state_->wait();}
@@ -2464,7 +2534,7 @@
 template <class _Rp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y)
+swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT
 {
     __x.swap(__y);
 }

Modified: trunk/contrib/libc++/include/initializer_list
===================================================================
--- trunk/contrib/libc++/include/initializer_list	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/initializer_list	2016-01-07 17:22:14 UTC (rev 7405)
@@ -56,7 +56,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template<class _Ep>
-class _LIBCPP_VISIBLE initializer_list
+class _LIBCPP_TYPE_VIS initializer_list
 {
     const _Ep* __begin_;
     size_t    __size_;

Modified: trunk/contrib/libc++/include/ios
===================================================================
--- trunk/contrib/libc++/include/ios	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ios	2016-01-07 17:22:14 UTC (rev 7405)
@@ -29,43 +29,43 @@
     class failure;
 
     typedef T1 fmtflags;
-    static const fmtflags boolalpha;
-    static const fmtflags dec;
-    static const fmtflags fixed;
-    static const fmtflags hex;
-    static const fmtflags internal;
-    static const fmtflags left;
-    static const fmtflags oct;
-    static const fmtflags right;
-    static const fmtflags scientific;
-    static const fmtflags showbase;
-    static const fmtflags showpoint;
-    static const fmtflags showpos;
-    static const fmtflags skipws;
-    static const fmtflags unitbuf;
-    static const fmtflags uppercase;
-    static const fmtflags adjustfield;
-    static const fmtflags basefield;
-    static const fmtflags floatfield;
+    static constexpr fmtflags boolalpha;
+    static constexpr fmtflags dec;
+    static constexpr fmtflags fixed;
+    static constexpr fmtflags hex;
+    static constexpr fmtflags internal;
+    static constexpr fmtflags left;
+    static constexpr fmtflags oct;
+    static constexpr fmtflags right;
+    static constexpr fmtflags scientific;
+    static constexpr fmtflags showbase;
+    static constexpr fmtflags showpoint;
+    static constexpr fmtflags showpos;
+    static constexpr fmtflags skipws;
+    static constexpr fmtflags unitbuf;
+    static constexpr fmtflags uppercase;
+    static constexpr fmtflags adjustfield;
+    static constexpr fmtflags basefield;
+    static constexpr fmtflags floatfield;
 
     typedef T2 iostate;
-    static const iostate badbit;
-    static const iostate eofbit;
-    static const iostate failbit;
-    static const iostate goodbit;
+    static constexpr iostate badbit;
+    static constexpr iostate eofbit;
+    static constexpr iostate failbit;
+    static constexpr iostate goodbit;
 
     typedef T3 openmode;
-    static const openmode app;
-    static const openmode ate;
-    static const openmode binary;
-    static const openmode in;
-    static const openmode out;
-    static const openmode trunc;
+    static constexpr openmode app;
+    static constexpr openmode ate;
+    static constexpr openmode binary;
+    static constexpr openmode in;
+    static constexpr openmode out;
+    static constexpr openmode trunc;
 
     typedef T4 seekdir;
-    static const seekdir beg;
-    static const seekdir cur;
-    static const seekdir end;
+    static constexpr seekdir beg;
+    static constexpr seekdir cur;
+    static constexpr seekdir end;
 
     class Init;
 
@@ -160,7 +160,7 @@
     basic_ios();
     void init(basic_streambuf<charT,traits>* sb);
     void move(basic_ios& rhs);
-    void swap(basic_ios& rhs);
+    void swap(basic_ios& rhs) noexcept;
     void set_rdbuf(basic_streambuf<charT, traits>* sb);
 };
 
@@ -224,10 +224,10 @@
 
 typedef ptrdiff_t streamsize;
 
-class _LIBCPP_VISIBLE ios_base
+class _LIBCPP_TYPE_VIS ios_base
 {
 public:
-    class failure;
+    class _LIBCPP_TYPE_VIS failure;
 
     typedef unsigned int fmtflags;
     static const fmtflags boolalpha   = 0x0001;
@@ -271,7 +271,7 @@
     typedef _VSTD::streamoff streamoff;
     typedef _VSTD::streampos streampos;
 
-    class Init;
+    class _LIBCPP_TYPE_VIS Init;
 
     // 27.5.2.2 fmtflags state:
     _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
@@ -342,7 +342,7 @@
     void __call_callbacks(event);
     void copyfmt(const ios_base&);
     void move(ios_base&);
-    void swap(ios_base&);
+    void swap(ios_base&) _NOEXCEPT;
 
     _LIBCPP_ALWAYS_INLINE
     void set_rdbuf(void* __sb)
@@ -380,14 +380,14 @@
 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
 
 template <>
-struct _LIBCPP_VISIBLE is_error_code_enum<io_errc> : public true_type { };
+struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc> : public true_type { };
 
 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
 template <>
-struct _LIBCPP_VISIBLE is_error_code_enum<io_errc::_> : public true_type { };
+struct _LIBCPP_TYPE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
 #endif
 
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
 const error_category& iostream_category();
 
 inline _LIBCPP_INLINE_VISIBILITY
@@ -413,7 +413,7 @@
     virtual ~failure() throw();
 };
 
-class _LIBCPP_VISIBLE ios_base::Init
+class _LIBCPP_TYPE_VIS ios_base::Init
 {
 public:
     Init();
@@ -560,7 +560,7 @@
 }
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_ios
+class _LIBCPP_TYPE_VIS basic_ios
     : public ios_base
 {
 public:
@@ -632,12 +632,12 @@
     void move(basic_ios&& __rhs) {move(__rhs);}
 #endif
     _LIBCPP_INLINE_VISIBILITY 
-    void swap(basic_ios& __rhs);
+    void swap(basic_ios& __rhs) _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY 
     void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
 private:
     basic_ostream<char_type, traits_type>* __tie_;
-    char_type __fill_;
+     mutable int_type __fill_;
 };
 
 template <class _CharT, class _Traits>
@@ -659,7 +659,7 @@
 {
     ios_base::init(__sb);
     __tie_ = 0;
-    __fill_ = widen(' ');
+    __fill_ = traits_type::eof();
 }
 
 template <class _CharT, class _Traits>
@@ -731,6 +731,8 @@
 _CharT
 basic_ios<_CharT, _Traits>::fill() const
 {
+    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
+        __fill_ = widen(' ');
     return __fill_;
 }
 
@@ -774,7 +776,7 @@
 template <class _CharT, class _Traits>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs)
+basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
 {
     ios_base::swap(__rhs);
     _VSTD::swap(__tie_, __rhs.__tie_);

Modified: trunk/contrib/libc++/include/iosfwd
===================================================================
--- trunk/contrib/libc++/include/iosfwd	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/iosfwd	2016-01-07 17:22:14 UTC (rev 7405)
@@ -95,49 +95,49 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class ios_base;
+class _LIBCPP_TYPE_VIS ios_base;
 
-template<class _CharT>  struct _LIBCPP_VISIBLE char_traits;
-template<class _Tp>     class _LIBCPP_VISIBLE allocator;
+template<class _CharT>  struct _LIBCPP_TYPE_VIS char_traits;
+template<class _Tp>     class _LIBCPP_TYPE_VIS allocator;
 
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_ios;
+    class _LIBCPP_TYPE_VIS basic_ios;
 
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_streambuf;
+    class _LIBCPP_TYPE_VIS basic_streambuf;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_istream;
+    class _LIBCPP_TYPE_VIS basic_istream;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_ostream;
+    class _LIBCPP_TYPE_VIS basic_ostream;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_iostream;
+    class _LIBCPP_TYPE_VIS basic_iostream;
 
 template <class _CharT, class _Traits = char_traits<_CharT>,
           class _Allocator = allocator<_CharT> >
-    class _LIBCPP_VISIBLE basic_stringbuf;
+    class _LIBCPP_TYPE_VIS basic_stringbuf;
 template <class _CharT, class _Traits = char_traits<_CharT>,
           class _Allocator = allocator<_CharT> >
-    class _LIBCPP_VISIBLE basic_istringstream;
+    class _LIBCPP_TYPE_VIS basic_istringstream;
 template <class _CharT, class _Traits = char_traits<_CharT>,
           class _Allocator = allocator<_CharT> >
-    class _LIBCPP_VISIBLE basic_ostringstream;
+    class _LIBCPP_TYPE_VIS basic_ostringstream;
 template <class _CharT, class _Traits = char_traits<_CharT>,
           class _Allocator = allocator<_CharT> >
-    class _LIBCPP_VISIBLE basic_stringstream;
+    class _LIBCPP_TYPE_VIS basic_stringstream;
 
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_filebuf;
+    class _LIBCPP_TYPE_VIS basic_filebuf;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_ifstream;
+    class _LIBCPP_TYPE_VIS basic_ifstream;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_ofstream;
+    class _LIBCPP_TYPE_VIS basic_ofstream;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE basic_fstream;
+    class _LIBCPP_TYPE_VIS basic_fstream;
 
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE istreambuf_iterator;
+    class _LIBCPP_TYPE_VIS istreambuf_iterator;
 template <class _CharT, class _Traits = char_traits<_CharT> >
-    class _LIBCPP_VISIBLE ostreambuf_iterator;
+    class _LIBCPP_TYPE_VIS ostreambuf_iterator;
 
 typedef basic_ios<char>              ios;
 typedef basic_ios<wchar_t>           wios;
@@ -172,7 +172,7 @@
 typedef basic_ofstream<wchar_t>      wofstream;
 typedef basic_fstream<wchar_t>       wfstream;
 
-template <class _State>             class _LIBCPP_VISIBLE fpos;
+template <class _State>             class _LIBCPP_TYPE_VIS fpos;
 typedef fpos<mbstate_t>    streampos;
 typedef fpos<mbstate_t>    wstreampos;
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
@@ -185,7 +185,7 @@
 template <class _CharT,             // for <stdexcept>
           class _Traits = char_traits<_CharT>,
           class _Allocator = allocator<_CharT> >
-    class _LIBCPP_VISIBLE basic_string;
+    class _LIBCPP_TYPE_VIS basic_string;
 typedef basic_string<char, char_traits<char>, allocator<char> > string;
 typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
 

Modified: trunk/contrib/libc++/include/iostream
===================================================================
--- trunk/contrib/libc++/include/iostream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/iostream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -46,14 +46,14 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-extern _LIBCPP_VISIBLE istream cin;
-extern _LIBCPP_VISIBLE ostream cout;
-extern _LIBCPP_VISIBLE ostream cerr;
-extern _LIBCPP_VISIBLE ostream clog;
-extern _LIBCPP_VISIBLE wistream wcin;
-extern _LIBCPP_VISIBLE wostream wcout;
-extern _LIBCPP_VISIBLE wostream wcerr;
-extern _LIBCPP_VISIBLE wostream wclog;
+extern _LIBCPP_FUNC_VIS istream cin;
+extern _LIBCPP_FUNC_VIS ostream cout;
+extern _LIBCPP_FUNC_VIS ostream cerr;
+extern _LIBCPP_FUNC_VIS ostream clog;
+extern _LIBCPP_FUNC_VIS wistream wcin;
+extern _LIBCPP_FUNC_VIS wostream wcout;
+extern _LIBCPP_FUNC_VIS wostream wcerr;
+extern _LIBCPP_FUNC_VIS wostream wclog;
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/istream
===================================================================
--- trunk/contrib/libc++/include/istream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/istream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -164,7 +164,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_istream
+class _LIBCPP_TYPE_VIS basic_istream
     : virtual public basic_ios<_CharT, _Traits>
 {
     streamsize __gc_;
@@ -194,7 +194,7 @@
 public:
 
     // 27.7.1.1.3 Prefix/suffix:
-    class sentry;
+    class _LIBCPP_TYPE_VIS sentry;
 
     // 27.7.1.2 Formatted input:
     basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
@@ -244,7 +244,7 @@
 };
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_istream<_CharT, _Traits>::sentry
+class _LIBCPP_TYPE_VIS basic_istream<_CharT, _Traits>::sentry
 {
     bool __ok_;
 
@@ -1144,8 +1144,7 @@
                        break;
                     }
                     ++__gc_;
-                    char_type __ch = traits_type::to_char_type(__i);
-                    if (traits_type::eq(__ch, static_cast<char_type>(__dlm)))
+                    if (traits_type::eq_int_type(__i, __dlm))
                         break;
                 }
             }
@@ -1160,8 +1159,7 @@
                        break;
                     }
                     ++__gc_;
-                    char_type __ch = traits_type::to_char_type(__i);
-                    if (traits_type::eq(__ch, static_cast<char_type>(__dlm)))
+                    if (traits_type::eq_int_type(__i, __dlm))
                         break;
                 }
             }
@@ -1189,7 +1187,11 @@
 #endif  // _LIBCPP_NO_EXCEPTIONS
         sentry __sen(*this, true);
         if (__sen)
+        {
             __r = this->rdbuf()->sgetc();
+            if (traits_type::eq_int_type(__r, traits_type::eof()))
+                this->setstate(ios_base::eofbit);
+        }
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
@@ -1212,16 +1214,9 @@
         sentry __sen(*this, true);
         if (__sen)
         {
-            for (; __gc_ < __n; ++__gc_)
-            {
-                typename traits_type::int_type __i = this->rdbuf()->sbumpc();
-                if (traits_type::eq_int_type(__i, traits_type::eof()))
-                {
-                   this->setstate(ios_base::failbit | ios_base::eofbit);
-                   break;
-                }
-                *__s++ = traits_type::to_char_type(__i);
-            }
+            __gc_ = this->rdbuf()->sgetn(__s, __n);
+            if (__gc_ != __n)
+                this->setstate(ios_base::failbit | ios_base::eofbit);
         }
         else
             this->setstate(ios_base::failbit);
@@ -1239,6 +1234,7 @@
 streamsize
 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
 {
+    __gc_ = 0;
     streamsize __c = this->rdbuf()->in_avail();
     switch (__c)
     {
@@ -1263,6 +1259,7 @@
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
+        this->clear(this->rdstate() & ~ios_base::eofbit);
         sentry __sen(*this, true);
         if (__sen)
         {
@@ -1290,6 +1287,7 @@
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
+        this->clear(this->rdstate() & ~ios_base::eofbit);
         sentry __sen(*this, true);
         if (__sen)
         {
@@ -1368,6 +1366,7 @@
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
+        this->clear(this->rdstate() & ~ios_base::eofbit);
         sentry __sen(*this, true);
         if (__sen)
             if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
@@ -1452,7 +1451,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_iostream
+class _LIBCPP_TYPE_VIS basic_iostream
     : public basic_istream<_CharT, _Traits>,
       public basic_ostream<_CharT, _Traits>
 {
@@ -1703,9 +1702,9 @@
     return __is;
 }
 
-extern template class basic_istream<char>;
-extern template class basic_istream<wchar_t>;
-extern template class basic_iostream<char>;
+_LIBCPP_EXTERN_TEMPLATE(class basic_istream<char>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_istream<wchar_t>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_iostream<char>)
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/iterator
===================================================================
--- trunk/contrib/libc++/include/iterator	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/iterator	2016-01-07 17:22:14 UTC (rev 7405)
@@ -263,10 +263,10 @@
     typedef basic_streambuf<charT,traits> streambuf_type;
     typedef basic_istream<charT,traits>   istream_type;
 
-    istreambuf_iterator() throw();
-    istreambuf_iterator(istream_type& s) throw();
-    istreambuf_iterator(streambuf_type* s) throw();
-    istreambuf_iterator(a-private-type) throw();
+    istreambuf_iterator() noexcept;
+    istreambuf_iterator(istream_type& s) noexcept;
+    istreambuf_iterator(streambuf_type* s) noexcept;
+    istreambuf_iterator(a-private-type) noexcept;
 
     charT                operator*() const;
     pointer operator->() const;
@@ -293,13 +293,13 @@
     typedef basic_streambuf<charT,traits> streambuf_type;
     typedef basic_ostream<charT,traits>   ostream_type;
 
-    ostreambuf_iterator(ostream_type& s) throw();
-    ostreambuf_iterator(streambuf_type* s) throw();
+    ostreambuf_iterator(ostream_type& s) noexcept;
+    ostreambuf_iterator(streambuf_type* s) noexcept;
     ostreambuf_iterator& operator=(charT c);
     ostreambuf_iterator& operator*();
     ostreambuf_iterator& operator++();
     ostreambuf_iterator& operator++(int);
-    bool failed() const throw();
+    bool failed() const noexcept;
 };
 
 template <class C> auto begin(C& c) -> decltype(c.begin());
@@ -317,6 +317,10 @@
 #include <type_traits>
 #include <cstddef>
 #include <iosfwd>
+#ifdef __APPLE__
+#include <Availability.h>
+#endif
+
 #ifdef _LIBCPP_DEBUG
 #include <cassert>
 #endif
@@ -327,17 +331,17 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-struct _LIBCPP_VISIBLE input_iterator_tag {};
-struct _LIBCPP_VISIBLE output_iterator_tag {};
-struct _LIBCPP_VISIBLE forward_iterator_tag       : public input_iterator_tag {};
-struct _LIBCPP_VISIBLE bidirectional_iterator_tag : public forward_iterator_tag {};
-struct _LIBCPP_VISIBLE random_access_iterator_tag : public bidirectional_iterator_tag {};
+struct _LIBCPP_TYPE_VIS input_iterator_tag {};
+struct _LIBCPP_TYPE_VIS output_iterator_tag {};
+struct _LIBCPP_TYPE_VIS forward_iterator_tag       : public input_iterator_tag {};
+struct _LIBCPP_TYPE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
+struct _LIBCPP_TYPE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
 
 template <class _Tp>
 struct __has_iterator_category
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::iterator_category* = 0);
 public:
@@ -374,11 +378,11 @@
 //    the client expects instead of failing at compile time.
 
 template <class _Iter>
-struct _LIBCPP_VISIBLE iterator_traits
+struct _LIBCPP_TYPE_VIS iterator_traits
     : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
 
 template<class _Tp>
-struct _LIBCPP_VISIBLE iterator_traits<_Tp*>
+struct _LIBCPP_TYPE_VIS iterator_traits<_Tp*>
 {
     typedef ptrdiff_t difference_type;
     typedef typename remove_const<_Tp>::type value_type;
@@ -409,7 +413,7 @@
 
 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
          class _Pointer = _Tp*, class _Reference = _Tp&>
-struct _LIBCPP_VISIBLE iterator
+struct _LIBCPP_TYPE_VIS iterator
 {
     typedef _Tp        value_type;
     typedef _Distance  difference_type;
@@ -506,7 +510,7 @@
 }
 
 template <class _Iter>
-class _LIBCPP_VISIBLE reverse_iterator
+class _LIBCPP_TYPE_VIS reverse_iterator
     : public iterator<typename iterator_traits<_Iter>::iterator_category,
                       typename iterator_traits<_Iter>::value_type,
                       typename iterator_traits<_Iter>::difference_type,
@@ -613,7 +617,7 @@
 }
 
 template <class _Container>
-class _LIBCPP_VISIBLE back_insert_iterator
+class _LIBCPP_TYPE_VIS back_insert_iterator
     : public iterator<output_iterator_tag,
                       void,
                       void,
@@ -646,7 +650,7 @@
 }
 
 template <class _Container>
-class _LIBCPP_VISIBLE front_insert_iterator
+class _LIBCPP_TYPE_VIS front_insert_iterator
     : public iterator<output_iterator_tag,
                       void,
                       void,
@@ -679,7 +683,7 @@
 }
 
 template <class _Container>
-class _LIBCPP_VISIBLE insert_iterator
+class _LIBCPP_TYPE_VIS insert_iterator
     : public iterator<output_iterator_tag,
                       void,
                       void,
@@ -715,7 +719,7 @@
 
 template <class _Tp, class _CharT = char,
           class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
-class _LIBCPP_VISIBLE istream_iterator
+class _LIBCPP_TYPE_VIS istream_iterator
     : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
 {
 public:
@@ -754,7 +758,7 @@
 };
 
 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
-class _LIBCPP_VISIBLE ostream_iterator
+class _LIBCPP_TYPE_VIS ostream_iterator
     : public iterator<output_iterator_tag, void, void, void, void>
 {
 public:
@@ -783,7 +787,7 @@
 };
 
 template<class _CharT, class _Traits>
-class _LIBCPP_VISIBLE istreambuf_iterator
+class _LIBCPP_TYPE_VIS istreambuf_iterator
     : public iterator<input_iterator_tag, _CharT,
                       typename _Traits::off_type, _CharT*,
                       _CharT>
@@ -795,7 +799,7 @@
     typedef basic_streambuf<_CharT,_Traits> streambuf_type;
     typedef basic_istream<_CharT,_Traits>   istream_type;
 private:
-    streambuf_type* __sbuf_;
+    mutable streambuf_type* __sbuf_;
 
     class __proxy
     {
@@ -809,18 +813,19 @@
     };
 
     _LIBCPP_INLINE_VISIBILITY
-    void __test_for_eof()
+    bool __test_for_eof() const
     {
         if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
             __sbuf_ = 0;
+        return __sbuf_ == 0;
     }
 public:
-    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator() throw() : __sbuf_(0) {}
-    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) throw()
-        : __sbuf_(__s.rdbuf()) {__test_for_eof();}
-    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) throw()
-        : __sbuf_(__s) {__test_for_eof();}
-    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) throw()
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
+        : __sbuf_(__s.rdbuf()) {}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
+        : __sbuf_(__s) {}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
         : __sbuf_(__p.__sbuf_) {}
 
     _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
@@ -828,19 +833,16 @@
     _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
         {
-            if (traits_type::eq_int_type(__sbuf_->snextc(), traits_type::eof()))
-                __sbuf_ = 0;
+            __sbuf_->sbumpc();
             return *this;
         }
     _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
         {
-            char_type __c = __sbuf_->sgetc();
-            ++(*this);
-            return __proxy(__c, __sbuf_);
+            return __proxy(__sbuf_->sbumpc(), __sbuf_);
         }
 
     _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
-        {return (__sbuf_ == 0) == (__b.__sbuf_ == 0);}
+        {return __test_for_eof() == __b.__test_for_eof();}
 };
 
 template <class _CharT, class _Traits>
@@ -856,7 +858,7 @@
                 {return !__a.equal(__b);}
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE ostreambuf_iterator
+class _LIBCPP_TYPE_VIS ostreambuf_iterator
     : public iterator<output_iterator_tag, void, void, void, void>
 {
 public:
@@ -867,9 +869,9 @@
 private:
     streambuf_type* __sbuf_;
 public:
-    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) throw()
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
         : __sbuf_(__s.rdbuf()) {}
-    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) throw()
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
         : __sbuf_(__s) {}
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
         {
@@ -880,11 +882,24 @@
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
-    _LIBCPP_INLINE_VISIBILITY bool failed() const throw() {return __sbuf_ == 0;}
+    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
+
+#if !defined(__APPLE__) || \
+    (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
+    (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
+
+    template <class _Ch, class _Tr>
+    friend
+    _LIBCPP_HIDDEN
+    ostreambuf_iterator<_Ch, _Tr>
+    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
+                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
+                     ios_base& __iob, _Ch __fl);
+#endif
 };
 
 template <class _Iter>
-class _LIBCPP_VISIBLE move_iterator
+class _LIBCPP_TYPE_VIS move_iterator
 {
 private:
     _Iter __i;
@@ -1009,43 +1024,52 @@
 template <class _Iter> class __wrap_iter;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 typename __wrap_iter<_Iter1>::difference_type
 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
 
 template <class _Iter>
+_LIBCPP_INLINE_VISIBILITY
 __wrap_iter<_Iter>
 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
 
-template <class _Ip, class _Op> _Op copy(_Ip, _Ip, _Op);
-template <class _B1, class _B2> _B2 copy_backward(_B1, _B1, _B2);
-template <class _Ip, class _Op> _Op move(_Ip, _Ip, _Op);
-template <class _B1, class _B2> _B2 move_backward(_B1, _B1, _B2);
+template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
+template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
+template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
+template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
 
 template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_trivially_copy_assignable<_Tp>::value,
@@ -1111,7 +1135,14 @@
 #endif
         return *__i;
     }
-    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const _NOEXCEPT {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const _NOEXCEPT
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to dereference a non-dereferenceable iterator");
+#endif
+        return (pointer)&reinterpret_cast<const volatile char&>(*__i);
+    }
     _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1284,6 +1315,38 @@
     return !(__y < __x);
 }
 
+template <class _Iter1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
+{
+    return !(__x == __y);
+}
+
+template <class _Iter1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
+{
+    return __y < __x;
+}
+
+template <class _Iter1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
+{
+    return !(__x < __y);
+}
+
+template <class _Iter1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
+{
+    return !(__y < __x);
+}
+
 template <class _Iter1, class _Iter2>
 inline _LIBCPP_INLINE_VISIBILITY
 typename __wrap_iter<_Iter1>::difference_type
@@ -1313,34 +1376,42 @@
 template <class _Container, class _Iter> class __debug_iter;
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator==(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator<(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator!=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator>(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator>=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator<=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter1, class _Iter2>
+_LIBCPP_INLINE_VISIBILITY
 typename __debug_iter<_Container, _Iter1>::difference_type
 operator-(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
 
 template <class _Container, class _Iter>
+_LIBCPP_INLINE_VISIBILITY
 __debug_iter<_Container, _Iter>
 operator+(typename __debug_iter<_Container, _Iter>::difference_type, const __debug_iter<_Container, _Iter>&);
 

Modified: trunk/contrib/libc++/include/limits
===================================================================
--- trunk/contrib/libc++/include/limits	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/limits	2016-01-07 17:22:14 UTC (rev 7405)
@@ -433,7 +433,7 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE numeric_limits
+class _LIBCPP_TYPE_VIS numeric_limits
     : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
 {
     typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base;
@@ -479,7 +479,54 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE numeric_limits<const _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_specialized;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_signed;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_integer;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_exact;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::radix;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_infinity;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_quiet_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_signaling_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<_Tp>::has_denorm;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_denorm_loss;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_iec559;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_bounded;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_modulo;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::traps;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::tinyness_before;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style;
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS numeric_limits<const _Tp>
     : private numeric_limits<_Tp>
 {
     typedef numeric_limits<_Tp> __base;
@@ -525,7 +572,54 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE numeric_limits<volatile _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_specialized;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_signed;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_integer;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_exact;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::radix;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_infinity;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_quiet_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_signaling_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const _Tp>::has_denorm;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_denorm_loss;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_iec559;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_bounded;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_modulo;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::traps;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::tinyness_before;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_round_style numeric_limits<const _Tp>::round_style;
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS numeric_limits<volatile _Tp>
     : private numeric_limits<_Tp>
 {
     typedef numeric_limits<_Tp> __base;
@@ -571,7 +665,54 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE numeric_limits<const volatile _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_specialized;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_digits10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_signed;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_integer;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_exact;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::radix;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_infinity;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_quiet_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_signaling_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<volatile _Tp>::has_denorm;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_denorm_loss;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_iec559;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_bounded;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_modulo;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::traps;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::tinyness_before;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_round_style numeric_limits<volatile _Tp>::round_style;
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS numeric_limits<const volatile _Tp>
     : private numeric_limits<_Tp>
 {
     typedef numeric_limits<_Tp> __base;
@@ -616,6 +757,53 @@
     static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
 };
 
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_specialized;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits;
+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;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_signed;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_integer;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_exact;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::radix;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent10;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_infinity;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_quiet_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_signaling_NaN;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const volatile _Tp>::has_denorm;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_denorm_loss;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_iec559;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_bounded;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_modulo;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::traps;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::tinyness_before;
+template <class _Tp>
+    _LIBCPP_CONSTEXPR const float_round_style numeric_limits<const volatile _Tp>::round_style;
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_LIMITS

Modified: trunk/contrib/libc++/include/list
===================================================================
--- trunk/contrib/libc++/include/list	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/list	2016-01-07 17:22:14 UTC (rev 7405)
@@ -196,13 +196,20 @@
         rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
 #endif
 
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node_base> __base_pointer;
+#else
+        rebind<__list_node_base>::other __base_pointer;
+#endif
+
     pointer __prev_;
     pointer __next_;
 
     _LIBCPP_INLINE_VISIBILITY
     __list_node_base()
-        : __prev_(static_cast<pointer>(this)),
-          __next_(static_cast<pointer>(this))
+        : __prev_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))),
+          __next_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this)))
           {}
 };
 
@@ -213,12 +220,12 @@
     _Tp __value_;
 };
 
-template <class _Tp, class _Alloc> class list;
+template <class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS list;
 template <class _Tp, class _Alloc> class __list_imp;
-template <class _Tp, class _VoidPtr> class __list_const_iterator;
+template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS __list_const_iterator;
 
 template <class _Tp, class _VoidPtr>
-class _LIBCPP_VISIBLE __list_iterator
+class _LIBCPP_TYPE_VIS __list_iterator
 {
     typedef typename pointer_traits<_VoidPtr>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
@@ -305,7 +312,14 @@
         return __ptr_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return &(operator*());}
+    pointer operator->() const
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to dereference a non-dereferenceable list::iterator");
+#endif
+        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
+    }
 
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator& operator++()
@@ -348,13 +362,13 @@
 };
 
 template <class _Tp, class _VoidPtr>
-class _LIBCPP_VISIBLE __list_const_iterator
+class _LIBCPP_TYPE_VIS __list_const_iterator
 {
     typedef typename pointer_traits<_VoidPtr>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-        rebind<const __list_node<_Tp, _VoidPtr> > __node_pointer;
+        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
 #else
-        rebind<const __list_node<_Tp, _VoidPtr> >::other __node_pointer;
+        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
 #endif
 
     __node_pointer __ptr_;
@@ -394,7 +408,7 @@
 #endif
     }
     _LIBCPP_INLINE_VISIBILITY
-    __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) _NOEXCEPT
+    __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
         : __ptr_(__p.__ptr_)
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -439,7 +453,14 @@
         return __ptr_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return &(operator*());}
+    pointer operator->() const
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to dereference a non-dereferenceable list::iterator");
+#endif
+        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
+    }
 
     _LIBCPP_INLINE_VISIBILITY
     __list_const_iterator& operator++()
@@ -505,11 +526,20 @@
                                                                      __node_allocator;
     typedef allocator_traits<__node_allocator>                       __node_alloc_traits;
     typedef typename __node_alloc_traits::pointer                    __node_pointer;
-    typedef typename __node_alloc_traits::const_pointer              __node_const_pointer;
+    typedef typename __node_alloc_traits::pointer                    __node_const_pointer;
     typedef typename __alloc_traits::pointer                         pointer;
     typedef typename __alloc_traits::const_pointer                   const_pointer;
     typedef typename __alloc_traits::difference_type                 difference_type;
 
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<__node_base>
+#else
+                rebind_alloc<__node_base>::other
+#endif
+                                                                     __node_base_allocator;
+    typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
+
     __node_base __end_;
     __compressed_pair<size_type, __node_allocator> __size_alloc_;
 
@@ -525,7 +555,7 @@
     const __node_allocator& __node_alloc() const _NOEXCEPT
         {return __size_alloc_.second();}
 
-    static void __unlink_nodes(__node_base& __f, __node_base& __l) _NOEXCEPT;
+    static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
 
     __list_imp()
         _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
@@ -557,9 +587,11 @@
     iterator end() _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        return iterator(static_cast<__node_pointer>(&__end_), this);
+        return iterator(static_cast<__node_pointer>(
+                pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
 #else
-        return iterator(static_cast<__node_pointer>(&__end_));
+        return iterator(static_cast<__node_pointer>(
+                      pointer_traits<__node_base_pointer>::pointer_to(__end_)));
 #endif
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -566,9 +598,11 @@
     const_iterator end() const _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        return const_iterator(static_cast<__node_const_pointer>(&__end_), this);
+        return const_iterator(static_cast<__node_const_pointer>(
+        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
 #else
-        return const_iterator(static_cast<__node_const_pointer>(&__end_));
+        return const_iterator(static_cast<__node_const_pointer>(
+        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
 #endif
     }
 
@@ -637,11 +671,11 @@
 template <class _Tp, class _Alloc>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l)
+__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
     _NOEXCEPT
 {
-    __f.__prev_->__next_ = __l.__next_;
-    __l.__next_->__prev_ = __f.__prev_;
+    __f->__prev_->__next_ = __l->__next_;
+    __l->__next_->__prev_ = __f->__prev_;
 }
 
 template <class _Tp, class _Alloc>
@@ -676,15 +710,16 @@
     {
         __node_allocator& __na = __node_alloc();
         __node_pointer __f = __end_.__next_;
-        __node_pointer __l = static_cast<__node_pointer>(&__end_);
-        __unlink_nodes(*__f, *__l->__prev_);
+        __node_pointer __l = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
+        __unlink_nodes(__f, __l->__prev_);
         __sz() = 0;
         while (__f != __l)
         {
-            __node& __n = *__f;
+            __node_pointer __n = __f;
             __f = __f->__next_;
-            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_));
-            __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1);
+            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+            __node_alloc_traits::deallocate(__na, __n, 1);
         }
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __c_node* __c = __get_db()->__find_c_and_lock(this);
@@ -719,16 +754,20 @@
     swap(__sz(), __c.__sz());
     swap(__end_, __c.__end_);
     if (__sz() == 0)
-        __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_);
+        __end_.__next_ = __end_.__prev_ = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
     else
         __end_.__prev_->__next_ = __end_.__next_->__prev_
-                                = &static_cast<__node&>(__end_);
+                                = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
     if (__c.__sz() == 0)
         __c.__end_.__next_ = __c.__end_.__prev_
-                           = &static_cast<__node&>(__c.__end_);
+                           = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_));
     else
         __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_
-                                    = &static_cast<__node&>(__c.__end_);
+                                    = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_));
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __libcpp_db* __db = __get_db();
     __c_node* __cn1 = __db->__find_c_and_lock(this);
@@ -740,7 +779,8 @@
     {
         --__p;
         const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == static_cast<__node_pointer>(&__c.__end_))
+        if (__i->__ptr_ == static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
         {
             __cn2->__add(*__p);
             if (--__cn1->end_ != __p)
@@ -753,7 +793,8 @@
     {
         --__p;
         const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == static_cast<__node_pointer>(&__end_))
+        if (__i->__ptr_ == static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_)))
         {
             __cn1->__add(*__p);
             if (--__cn2->end_ != __p)
@@ -767,7 +808,7 @@
 }
 
 template <class _Tp, class _Alloc = allocator<_Tp> >
-class _LIBCPP_VISIBLE list
+class _LIBCPP_TYPE_VIS list
     : private __list_imp<_Tp, _Alloc>
 {
     typedef __list_imp<_Tp, _Alloc> base;
@@ -775,6 +816,8 @@
     typedef typename base::__node_allocator    __node_allocator;
     typedef typename base::__node_pointer      __node_pointer;
     typedef typename base::__node_alloc_traits __node_alloc_traits;
+    typedef typename base::__node_base         __node_base;
+    typedef typename base::__node_base_pointer __node_base_pointer;
 
 public:
     typedef _Tp                                      value_type;
@@ -1014,7 +1057,7 @@
 #endif  // _LIBCPP_DEBUG_LEVEL >= 2
 
 private:
-    static void __link_nodes(__node& __p, __node& __f, __node& __l);
+    static void __link_nodes(__node_pointer __p, __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);
@@ -1028,12 +1071,12 @@
 template <class _Tp, class _Alloc>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l)
+list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
 {
-    __p.__prev_->__next_ = &__f;
-    __f.__prev_ = __p.__prev_;
-    __p.__prev_ = &__l;
-    __l.__next_ = &__p;
+    __p->__prev_->__next_ = __f;
+    __f->__prev_ = __p->__prev_;
+    __p->__prev_ = __l;
+    __l->__next_ = __p;
 }
 
 template <class _Tp, class _Alloc>
@@ -1290,9 +1333,13 @@
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator(__hold.release(), this);
+#else
     return iterator(__hold.release());
+#endif
 }
 
 template <class _Tp, class _Alloc>
@@ -1303,9 +1350,9 @@
     _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
         "list::insert(iterator, n, x) called with an iterator not"
         " referring to this list");
-    iterator __r(const_cast<__node_pointer>(__p.__ptr_), this);
+    iterator __r(__p.__ptr_, this);
 #else
-    iterator __r(const_cast<__node_pointer>(__p.__ptr_));
+    iterator __r(__p.__ptr_);
 #endif
     if (__n > 0)
     {
@@ -1355,7 +1402,7 @@
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_);
+        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
     return __r;
@@ -1371,9 +1418,9 @@
     _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
         "list::insert(iterator, range) called with an iterator not"
         " referring to this list");
-    iterator __r(const_cast<__node_pointer>(__p.__ptr_), this);
+    iterator __r(__p.__ptr_, this);
 #else
-    iterator __r(const_cast<__node_pointer>(__p.__ptr_));
+    iterator __r(__p.__ptr_);
 #endif
     if (__f != __l)
     {
@@ -1423,7 +1470,7 @@
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_);
+        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
     return __r;
@@ -1437,7 +1484,7 @@
     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, *__hold);
+    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1450,7 +1497,8 @@
     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&>(base::__end_), *__hold, *__hold);
+    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1465,7 +1513,7 @@
     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, *__hold);
+    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1478,7 +1526,8 @@
     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&>(base::__end_), *__hold, *__hold);
+    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1494,7 +1543,7 @@
     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, *__hold);
+    __link_nodes(base::__end_.__next_, __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1508,7 +1557,8 @@
     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&>(base::__end_), *__hold, *__hold);
+    __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1518,12 +1568,17 @@
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
 {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "list::emplace(iterator, args...) called with an iterator not"
+        " referring to this list");
+#endif
     __node_allocator& __na = base::__node_alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
     return iterator(__hold.release(), this);
@@ -1548,7 +1603,7 @@
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
     return iterator(__hold.release(), this);
@@ -1565,7 +1620,7 @@
 {
     _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
     __node_allocator& __na = base::__node_alloc();
-    __node& __n = *base::__end_.__next_;
+    __node_pointer __n = base::__end_.__next_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1574,7 +1629,7 @@
     {
         --__p;
         iterator* __i = static_cast<iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == &__n)
+        if (__i->__ptr_ == __n)
         {
             (*__p)->__c_ = nullptr;
             if (--__c->end_ != __p)
@@ -1583,8 +1638,8 @@
     }
     __get_db()->unlock();
 #endif
-    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_));
-    __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 }
 
 template <class _Tp, class _Alloc>
@@ -1591,9 +1646,9 @@
 void
 list<_Tp, _Alloc>::pop_back()
 {
-    _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
+    _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
     __node_allocator& __na = base::__node_alloc();
-    __node& __n = *base::__end_.__prev_;
+    __node_pointer __n = base::__end_.__prev_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1602,7 +1657,7 @@
     {
         --__p;
         iterator* __i = static_cast<iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == &__n)
+        if (__i->__ptr_ == __n)
         {
             (*__p)->__c_ = nullptr;
             if (--__c->end_ != __p)
@@ -1611,8 +1666,8 @@
     }
     __get_db()->unlock();
 #endif
-    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_));
-    __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 }
 
 template <class _Tp, class _Alloc>
@@ -1624,9 +1679,11 @@
         "list::erase(iterator) called with an iterator not"
         " referring to this list");
 #endif
+    _LIBCPP_ASSERT(__p != end(),
+        "list::erase(iterator) called with a non-dereferenceable iterator");
     __node_allocator& __na = base::__node_alloc();
-    __node& __n = const_cast<__node&>(*__p.__ptr_);
-    __node_pointer __r = __n.__next_;
+    __node_pointer __n = __p.__ptr_;
+    __node_pointer __r = __n->__next_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1635,7 +1692,7 @@
     {
         --__p;
         iterator* __i = static_cast<iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == &__n)
+        if (__i->__ptr_ == __n)
         {
             (*__p)->__c_ = nullptr;
             if (--__c->end_ != __p)
@@ -1644,8 +1701,8 @@
     }
     __get_db()->unlock();
 #endif
-    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_));
-    __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 #if _LIBCPP_DEBUG_LEVEL >= 2
     return iterator(__r, this);
 #else
@@ -1665,10 +1722,10 @@
     if (__f != __l)
     {
         __node_allocator& __na = base::__node_alloc();
-        base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_);
+        base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
         while (__f != __l)
         {
-            __node& __n = const_cast<__node&>(*__f.__ptr_);
+            __node_pointer __n = __f.__ptr_;
             ++__f;
             --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1677,7 +1734,7 @@
             {
                 --__p;
                 iterator* __i = static_cast<iterator*>((*__p)->__i_);
-                if (__i->__ptr_ == &__n)
+                if (__i->__ptr_ == __n)
                 {
                     (*__p)->__c_ = nullptr;
                     if (--__c->end_ != __p)
@@ -1686,14 +1743,14 @@
             }
             __get_db()->unlock();
 #endif
-            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_));
-            __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1);
+            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+            __node_alloc_traits::deallocate(__na, __n, 1);
         }
     }
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    return iterator(const_cast<__node_pointer>(__l.__ptr_), this);
+    return iterator(__l.__ptr_, this);
 #else
-    return iterator(const_cast<__node_pointer>(__l.__ptr_));
+    return iterator(__l.__ptr_);
 #endif
 }
 
@@ -1751,7 +1808,8 @@
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_);
+        __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
 }
@@ -1810,7 +1868,8 @@
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_);
+        __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
 }
@@ -1828,10 +1887,10 @@
 #endif
     if (!__c.empty())
     {
-        __node& __f = *__c.__end_.__next_;
-        __node& __l = *__c.__end_.__prev_;
+        __node_pointer __f = __c.__end_.__next_;
+        __node_pointer __l = __c.__end_.__prev_;
         base::__unlink_nodes(__f, __l);
-        __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l);
+        __link_nodes(__p.__ptr_, __f, __l);
         base::__sz() += __c.__sz();
         __c.__sz() = 0;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1842,7 +1901,8 @@
         {
             --__p;
             iterator* __i = static_cast<iterator*>((*__p)->__i_);
-            if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_))
+            if (__i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
             {
                 __cn1->__add(*__p);
                 (*__p)->__c_ = __cn1;
@@ -1872,9 +1932,9 @@
 #endif
     if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
     {
-        __node& __f = const_cast<__node&>(*__i.__ptr_);
+        __node_pointer __f = __i.__ptr_;
         base::__unlink_nodes(__f, __f);
-        __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f);
+        __link_nodes(__p.__ptr_, __f, __f);
         --__c.__sz();
         ++base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1885,7 +1945,7 @@
         {
             --__p;
             iterator* __j = static_cast<iterator*>((*__p)->__i_);
-            if (__j->__ptr_ == &__f)
+            if (__j->__ptr_ == __f)
             {
                 __cn1->__add(*__p);
                 (*__p)->__c_ = __cn1;
@@ -1926,11 +1986,11 @@
             __c.__sz() -= __s;
             base::__sz() += __s;
         }
-        __node& __first = const_cast<__node&>(*__f.__ptr_);
+        __node_pointer __first = __f.__ptr_;
         --__l;
-        __node& __last = const_cast<__node&>(*__l.__ptr_);
+        __node_pointer __last = __l.__ptr_;
         base::__unlink_nodes(__first, __last);
-        __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last);
+        __link_nodes(__p.__ptr_, __first, __last);
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __libcpp_db* __db = __get_db();
         __c_node* __cn1 = __db->__find_c_and_lock(this);
@@ -1939,7 +1999,7 @@
         {
             --__p;
             iterator* __j = static_cast<iterator*>((*__p)->__i_);
-            for (__node_pointer __k = const_cast<__node_pointer>(__f.__ptr_);
+            for (__node_pointer __k = __f.__ptr_;
                                           __k != __l.__ptr_; __k = __k->__next_)
             {
                 if (__j->__ptr_ == __k)
@@ -2045,12 +2105,12 @@
                     ;
                 base::__sz() += __ds;
                 __c.__sz() -= __ds;
-                __node& __f = *__f2.__ptr_;
-                __node& __l = *__m2.__ptr_->__prev_;
+                __node_pointer __f = __f2.__ptr_;
+                __node_pointer __l = __m2.__ptr_->__prev_;
                 __f2 = __m2;
                 base::__unlink_nodes(__f, __l);
                 __m2 = _VSTD::next(__f1);
-                __link_nodes(*__f1.__ptr_, __f, __l);
+                __link_nodes(__f1.__ptr_, __f, __l);
                 __f1 = __m2;
             }
             else
@@ -2065,7 +2125,8 @@
         {
             --__p;
             iterator* __i = static_cast<iterator*>((*__p)->__i_);
-            if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_))
+            if (__i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
             {
                 __cn1->__add(*__p);
                 (*__p)->__c_ = __cn1;
@@ -2108,9 +2169,9 @@
     case 2:
         if (__comp(*--__e2, *__f1))
         {
-            __node& __f = *__e2.__ptr_;
+            __node_pointer __f = __e2.__ptr_;
             base::__unlink_nodes(__f, __f);
-            __link_nodes(*__f1.__ptr_, __f, __f);
+            __link_nodes(__f1.__ptr_, __f, __f);
             return __e2;
         }
         return __f1;
@@ -2124,13 +2185,13 @@
         iterator __m2 = _VSTD::next(__f2);
         for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
             ;
-        __node& __f = *__f2.__ptr_;
-        __node& __l = *__m2.__ptr_->__prev_;
+        __node_pointer __f = __f2.__ptr_;
+        __node_pointer __l = __m2.__ptr_->__prev_;
         __r = __f2;
         __e1 = __f2 = __m2;
         base::__unlink_nodes(__f, __l);
         __m2 = _VSTD::next(__f1);
-        __link_nodes(*__f1.__ptr_, __f, __l);
+        __link_nodes(__f1.__ptr_, __f, __l);
         __f1 = __m2;
     }
     else
@@ -2142,14 +2203,14 @@
             iterator __m2 = _VSTD::next(__f2);
             for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
                 ;
-            __node& __f = *__f2.__ptr_;
-            __node& __l = *__m2.__ptr_->__prev_;
+            __node_pointer __f = __f2.__ptr_;
+            __node_pointer __l = __m2.__ptr_->__prev_;
             if (__e1 == __f2)
                 __e1 = __m2;
             __f2 = __m2;
             base::__unlink_nodes(__f, __l);
             __m2 = _VSTD::next(__f1);
-            __link_nodes(*__f1.__ptr_, __f, __l);
+            __link_nodes(__f1.__ptr_, __f, __l);
             __f1 = __m2;
         }
         else
@@ -2187,7 +2248,8 @@
 bool
 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
 {
-    return __i->__ptr_ != &this->__end_;
+    return __i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
 }
 
 template <class _Tp, class _Alloc>

Modified: trunk/contrib/libc++/include/locale
===================================================================
--- trunk/contrib/libc++/include/locale	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/locale	2016-01-07 17:22:14 UTC (rev 7405)
@@ -181,17 +181,21 @@
 #include <streambuf>
 #include <iterator>
 #include <limits>
-#if !__APPLE__
+#ifndef __APPLE__
 #include <cstdarg>
 #endif
 #include <cstdlib>
 #include <ctime>
-#if _WIN32
+#ifdef _WIN32
 #include <support/win32/locale_win32.h>
 #else // _WIN32
 #include <nl_types.h>
 #endif  // !_WIN32
 
+#ifdef __APPLE__
+#include <Availability.h>
+#endif
+
 #include <__undef_min_max>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -200,8 +204,10 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __APPLE__ || __FreeBSD__
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #  define _LIBCPP_GET_C_LOCALE 0
+#elif defined(__NetBSD__)
+#  define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
 #else
 #  define _LIBCPP_GET_C_LOCALE __cloc()
    // Get the C locale object
@@ -218,7 +224,7 @@
 // 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.
-#ifdef __linux__
+#if defined(__linux__) || defined(EMSCRIPTEN)
 
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
 decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
@@ -350,21 +356,7 @@
 #endif
 }
 
-_LIBCPP_ALWAYS_INLINE inline
-int __sprintf_l(char *__s, locale_t __l, const char *__format, ...) {
-  va_list __va;
-  va_start(__va, __format);
-#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-  int __res = vsprintf_l(__s, __l, __format, __va);
-#else
-  __locale_raii __current(uselocale(__l), uselocale);
-  int __res = vsprintf(__s, __format, __va);
-#endif
-  va_end(__va);
-  return __res;
-}
-
-_LIBCPP_ALWAYS_INLINE inline
+inline
 int __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
   va_list __va;
   va_start(__va, __format);
@@ -378,7 +370,7 @@
   return __res;
 }
 
-_LIBCPP_ALWAYS_INLINE inline
+inline
 int __asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
   va_list __va;
   va_start(__va, __format);
@@ -392,7 +384,7 @@
   return __res;
 }
 
-_LIBCPP_ALWAYS_INLINE inline
+inline
 int __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
   va_list __va;
   va_start(__va, __format);
@@ -630,8 +622,7 @@
         }
         return -1;
     }
-    if (__a_end-__a < __num_get_buf_sz - 1)
-        *__a_end++ = __src[__f];
+    *__a_end++ = __src[__f];
     ++__dc;
     return 0;
 }
@@ -669,7 +660,7 @@
     char __x = __src[__f];
     if (__x == '-' || __x == '+')
     {
-        if (__a_end == __a || (__a_end[-1] & 0xDF) == __exp)
+        if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F))
         {
             *__a_end++ = __x;
             return 0;
@@ -676,16 +667,19 @@
         }
         return -1;
     }
-    if (__a_end-__a < __num_get_buf_sz - 1)
-        *__a_end++ = __x;
     if (__x == 'x' || __x == 'X')
         __exp = 'P';
-    else if ((__x & 0xDF) == __exp)
+    else if ((__x & 0x5F) == __exp)
     {
-        __in_units = false;
-        if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
-            *__g_end++ = __dc;
+        __exp |= 0x80;
+        if (__in_units)
+        {
+            __in_units = false;
+            if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
+                *__g_end++ = __dc;
+        }
     }
+    *__a_end++ = __x;
     if (__f >= 22)
         return 0;
     ++__dc;
@@ -692,11 +686,11 @@
     return 0;
 }
 
-extern template struct __num_get<char>;
-extern template struct __num_get<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(struct __num_get<char>)
+_LIBCPP_EXTERN_TEMPLATE(struct __num_get<wchar_t>)
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE num_get
+class _LIBCPP_TYPE_VIS num_get
     : public locale::facet,
       private __num_get<_CharT>
 {
@@ -826,11 +820,11 @@
 {
     if (__a != __a_end)
     {
-        int __save_errno = errno;
+        typename remove_reference<decltype(errno)>::type __save_errno = errno;
         errno = 0;
         char *__p2;
         long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
-        int __current_errno = errno;
+        typename remove_reference<decltype(errno)>::type __current_errno = errno;
         if (__current_errno == 0)
             errno = __save_errno;
         if (__p2 != __a_end)
@@ -866,11 +860,11 @@
             __err = ios_base::failbit;
             return 0;
         }
-        int __save_errno = errno;
+        typename remove_reference<decltype(errno)>::type __save_errno = errno;
         errno = 0;
         char *__p2;
         unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
-        int __current_errno = errno;
+        typename remove_reference<decltype(errno)>::type __current_errno = errno;
         if (__current_errno == 0)
             errno = __save_errno;
         if (__p2 != __a_end)
@@ -896,13 +890,20 @@
 {
     if (__a != __a_end)
     {
+        typename remove_reference<decltype(errno)>::type __save_errno = errno;
+        errno = 0;
         char *__p2;
         long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE);
+        typename remove_reference<decltype(errno)>::type __current_errno = errno;
+        if (__current_errno == 0)
+            errno = __save_errno;
         if (__p2 != __a_end)
         {
             __err = ios_base::failbit;
             return 0;
         }
+        else if (__current_errno == ERANGE)
+            __err = ios_base::failbit;
         return static_cast<_Tp>(__ld);
     }
     __err = ios_base::failbit;
@@ -958,16 +959,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -993,16 +1006,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1028,16 +1053,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1063,16 +1100,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1098,16 +1147,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1133,16 +1194,28 @@
     char_type __atoms[26];
     char_type __thousands_sep;
     string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping, __g, __g_end,
                                     __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1170,7 +1243,9 @@
     string __grouping = this->__stage2_float_prep(__iob, __atoms,
                                                   __decimal_point,
                                                   __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
@@ -1178,11 +1253,21 @@
     bool __in_units = true;
     char __exp = 'E';
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
                                       __decimal_point, __thousands_sep,
                                       __grouping, __g, __g_end,
                                       __dc, __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1210,7 +1295,9 @@
     string __grouping = this->__stage2_float_prep(__iob, __atoms,
                                                   __decimal_point,
                                                   __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
@@ -1218,11 +1305,21 @@
     bool __in_units = true;
     char __exp = 'E';
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
                                       __decimal_point, __thousands_sep,
                                       __grouping, __g, __g_end,
                                       __dc, __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1250,7 +1347,9 @@
     string __grouping = this->__stage2_float_prep(__iob, __atoms,
                                                   __decimal_point,
                                                   __thousands_sep);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
@@ -1258,11 +1357,21 @@
     bool __in_units = true;
     char __exp = 'E';
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
                                       __decimal_point, __thousands_sep,
                                       __grouping, __g, __g_end,
                                       __dc, __atoms))
             break;
+    }
     if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
         *__g_end++ = __dc;
     // Stage 3
@@ -1290,16 +1399,28 @@
     string __grouping;
     use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
                                                     __num_get_base::__src + 26, __atoms);
-    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    string __buf;
+    __buf.resize(__buf.capacity());
+    char* __a = &__buf[0];
     char* __a_end = __a;
     unsigned __g[__num_get_base::__num_get_buf_sz];
     unsigned* __g_end = __g;
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
+    {
+        if (__a_end - __a == __buf.size())
+        {
+            size_t __tmp = __buf.size();
+            __buf.resize(2*__buf.size());
+            __buf.resize(__buf.capacity());
+            __a = &__buf[0];
+            __a_end = __a + __tmp;
+        }
         if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
                                     __thousands_sep, __grouping,
                                     __g, __g_end, __atoms))
             break;
+    }
     // Stage 3
     __a[sizeof(__a)-1] = 0;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
@@ -1314,8 +1435,8 @@
     return __b;
 }
 
-extern template class num_get<char>;
-extern template class num_get<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class num_get<char>)
+_LIBCPP_EXTERN_TEMPLATE(class num_get<wchar_t>)
 
 struct __num_put_base
 {
@@ -1464,11 +1585,11 @@
         __op = __ob + (__np - __nb);
 }
 
-extern template struct __num_put<char>;
-extern template struct __num_put<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(struct __num_put<char>)
+_LIBCPP_EXTERN_TEMPLATE(struct __num_put<wchar_t>)
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE num_put
+class _LIBCPP_TYPE_VIS num_put
     : public locale::facet,
       private __num_put<_CharT>
 {
@@ -1587,6 +1708,58 @@
     return __s;
 }
 
+#if !defined(__APPLE__) || \
+    (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
+    (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
+
+template <class _CharT, class _Traits>
+_LIBCPP_HIDDEN
+ostreambuf_iterator<_CharT, _Traits>
+__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
+                 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
+                 ios_base& __iob, _CharT __fl)
+{
+    if (__s.__sbuf_ == nullptr)
+        return __s;
+    streamsize __sz = __oe - __ob;
+    streamsize __ns = __iob.width();
+    if (__ns > __sz)
+        __ns -= __sz;
+    else
+        __ns = 0;
+    streamsize __np = __op - __ob;
+    if (__np > 0)
+    {
+        if (__s.__sbuf_->sputn(__ob, __np) != __np)
+        {
+            __s.__sbuf_ = nullptr;
+            return __s;
+        }
+    }
+    if (__ns > 0)
+    {
+        basic_string<_CharT, _Traits> __sp(__ns, __fl);
+        if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns)
+        {
+            __s.__sbuf_ = nullptr;
+            return __s;
+        }
+    }
+    __np = __oe - __op;
+    if (__np > 0)
+    {
+        if (__s.__sbuf_->sputn(__op, __np) != __np)
+        {
+            __s.__sbuf_ = nullptr;
+            return __s;
+        }
+    }
+    __iob.width(0);
+    return __s;
+}
+
+#endif
+
 template <class _CharT, class _OutputIterator>
 _OutputIterator
 num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
@@ -1616,9 +1789,9 @@
                           + 1;
     char __nar[__nbuf];
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
 #else
-    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+    int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v);
 #endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
@@ -1646,9 +1819,9 @@
                           + 1;
     char __nar[__nbuf];
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
 #else
-    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+    int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v);
 #endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
@@ -1676,9 +1849,9 @@
                           + 1;
     char __nar[__nbuf];
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
 #else
-    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+    int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v);
 #endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
@@ -1706,9 +1879,9 @@
                           + 1;
     char __nar[__nbuf];
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
 #else
-    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+    int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v);
 #endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
@@ -1870,9 +2043,9 @@
     const unsigned __nbuf = 20;
     char __nar[__nbuf];
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
 #else
-    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+    int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v);
 #endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
@@ -1892,8 +2065,8 @@
     return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
 }
 
-extern template class num_put<char>;
-extern template class num_put<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class num_put<char>)
+_LIBCPP_EXTERN_TEMPLATE(class num_put<wchar_t>)
 
 template <class _CharT, class _InputIterator>
 _LIBCPP_HIDDEN
@@ -1928,7 +2101,7 @@
     return __r;
 }
 
-class _LIBCPP_VISIBLE time_base
+class _LIBCPP_TYPE_VIS time_base
 {
 public:
     enum dateorder {no_order, dmy, mdy, ymd, ydm};
@@ -1950,7 +2123,7 @@
 };
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE time_get
+class _LIBCPP_TYPE_VIS time_get
     : public locale::facet,
       public time_base,
       private __time_get_c_storage<_CharT>
@@ -2559,8 +2732,8 @@
     return __b;
 }
 
-extern template class time_get<char>;
-extern template class time_get<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class time_get<char>)
+_LIBCPP_EXTERN_TEMPLATE(class time_get<wchar_t>)
 
 class __time_get
 {
@@ -2600,7 +2773,7 @@
 };
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE time_get_byname
+class _LIBCPP_TYPE_VIS time_get_byname
     : public time_get<_CharT, _InputIterator>,
       private __time_get_storage<_CharT>
 {
@@ -2642,8 +2815,8 @@
     virtual const string_type& __X() const      {return this->__X_;}
 };
 
-extern template class time_get_byname<char>;
-extern template class time_get_byname<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class time_get_byname<char>)
+_LIBCPP_EXTERN_TEMPLATE(class time_get_byname<wchar_t>)
 
 class __time_put
 {
@@ -2660,7 +2833,7 @@
 };
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE time_put
+class _LIBCPP_TYPE_VIS time_put
     : public locale::facet,
       private __time_put
 {
@@ -2755,11 +2928,11 @@
     return _VSTD::copy(__nb, __ne, __s);
 }
 
-extern template class time_put<char>;
-extern template class time_put<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class time_put<char>)
+_LIBCPP_EXTERN_TEMPLATE(class time_put<wchar_t>)
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE time_put_byname
+class _LIBCPP_TYPE_VIS time_put_byname
     : public time_put<_CharT, _OutputIterator>
 {
 public:
@@ -2776,12 +2949,12 @@
     ~time_put_byname() {}
 };
 
-extern template class time_put_byname<char>;
-extern template class time_put_byname<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class time_put_byname<char>)
+_LIBCPP_EXTERN_TEMPLATE(class time_put_byname<wchar_t>)
 
 // money_base
 
-class _LIBCPP_VISIBLE money_base
+class _LIBCPP_TYPE_VIS money_base
 {
 public:
     enum part {none, space, symbol, sign, value};
@@ -2793,7 +2966,7 @@
 // moneypunct
 
 template <class _CharT, bool _International = false>
-class _LIBCPP_VISIBLE moneypunct
+class _LIBCPP_TYPE_VIS moneypunct
     : public locale::facet,
       public money_base
 {
@@ -2830,9 +3003,9 @@
     virtual string_type do_negative_sign() const {return string_type(1, '-');}
     virtual int         do_frac_digits()   const {return 0;}
     virtual pattern     do_pos_format()    const
-        {pattern __p = {symbol, sign, none, value}; return __p;}
+        {pattern __p = {{symbol, sign, none, value}}; return __p;}
     virtual pattern     do_neg_format()    const
-        {pattern __p = {symbol, sign, none, value}; return __p;}
+        {pattern __p = {{symbol, sign, none, value}}; return __p;}
 };
 
 template <class _CharT, bool _International>
@@ -2839,15 +3012,19 @@
 locale::id
 moneypunct<_CharT, _International>::id;
 
-extern template class moneypunct<char, false>;
-extern template class moneypunct<char, true>;
-extern template class moneypunct<wchar_t, false>;
-extern template class moneypunct<wchar_t, true>;
+template <class _CharT, bool _International>
+const bool
+moneypunct<_CharT, _International>::intl;
 
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct<char, false>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct<char, true>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct<wchar_t, false>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct<wchar_t, true>)
+
 // moneypunct_byname
 
 template <class _CharT, bool _International = false>
-class _LIBCPP_VISIBLE moneypunct_byname
+class _LIBCPP_TYPE_VIS moneypunct_byname
     : public moneypunct<_CharT, _International>
 {
 public:
@@ -2896,10 +3073,10 @@
 template<> void moneypunct_byname<wchar_t, false>::init(const char*);
 template<> void moneypunct_byname<wchar_t, true>::init(const char*);
 
-extern template class moneypunct_byname<char, false>;
-extern template class moneypunct_byname<char, true>;
-extern template class moneypunct_byname<wchar_t, false>;
-extern template class moneypunct_byname<wchar_t, true>;
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<char, false>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<char, true>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<wchar_t, false>)
+_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<wchar_t, true>)
 
 // money_get
 
@@ -2955,11 +3132,11 @@
     }
 }
 
-extern template class __money_get<char>;
-extern template class __money_get<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class __money_get<char>)
+_LIBCPP_EXTERN_TEMPLATE(class __money_get<wchar_t>)
 
 template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE money_get
+class _LIBCPP_TYPE_VIS money_get
     : public locale::facet,
       private __money_get<_CharT>
 {
@@ -3146,7 +3323,6 @@
             bool __sb = __flags & ios_base::showbase;
             if (__sb || __more_needed)
             {
-                ios_base::iostate __et = ios_base::goodbit;
                 typename string_type::const_iterator __sym_space_end = __sym.begin();
                 if (__p > 0 && (__pat.field[__p - 1] == money_base::none ||
                                 __pat.field[__p - 1] == money_base::space)) {
@@ -3294,7 +3470,7 @@
         if (__neg)
             *__nc++ = '-';
         for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
-            *__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms];
+            *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms];
         *__nc = char();
         if (sscanf(__nbuf, "%Lf", &__v) != 1)
             __throw_runtime_error("money_get error");
@@ -3337,8 +3513,8 @@
     return __b;
 }
 
-extern template class money_get<char>;
-extern template class money_get<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class money_get<char>)
+_LIBCPP_EXTERN_TEMPLATE(class money_get<wchar_t>)
 
 // money_put
 
@@ -3512,11 +3688,11 @@
         __mi = __mb;
 }
 
-extern template class __money_put<char>;
-extern template class __money_put<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class __money_put<char>)
+_LIBCPP_EXTERN_TEMPLATE(class __money_put<wchar_t>)
 
 template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
-class _LIBCPP_VISIBLE money_put
+class _LIBCPP_TYPE_VIS money_put
     : public locale::facet,
       private __money_put<_CharT>
 {
@@ -3669,12 +3845,12 @@
     return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
 }
 
-extern template class money_put<char>;
-extern template class money_put<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class money_put<char>)
+_LIBCPP_EXTERN_TEMPLATE(class money_put<wchar_t>)
 
 // messages
 
-class _LIBCPP_VISIBLE messages_base
+class _LIBCPP_TYPE_VIS messages_base
 {
 public:
     typedef ptrdiff_t catalog;
@@ -3683,7 +3859,7 @@
 };
 
 template <class _CharT>
-class _LIBCPP_VISIBLE messages
+class _LIBCPP_TYPE_VIS messages
     : public locale::facet,
       public messages_base
 {
@@ -3734,7 +3910,7 @@
 typename messages<_CharT>::catalog
 messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
 {
-#if _WIN32
+#ifdef _WIN32
     return -1;
 #else // _WIN32
     catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
@@ -3749,7 +3925,7 @@
 messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
                          const string_type& __dflt) const
 {
-#if _WIN32
+#ifdef _WIN32
     return __dflt;
 #else // _WIN32
     string __ndflt;
@@ -3771,7 +3947,7 @@
 void
 messages<_CharT>::do_close(catalog __c) const
 {
-#if !_WIN32
+#if !defined(_WIN32)
     if (__c != -1)
         __c <<= 1;
     nl_catd __cat = (nl_catd)__c;
@@ -3779,11 +3955,11 @@
 #endif // !_WIN32
 }
 
-extern template class messages<char>;
-extern template class messages<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class messages<char>)
+_LIBCPP_EXTERN_TEMPLATE(class messages<wchar_t>)
 
 template <class _CharT>
-class _LIBCPP_VISIBLE messages_byname
+class _LIBCPP_TYPE_VIS messages_byname
     : public messages<_CharT>
 {
 public:
@@ -3803,13 +3979,13 @@
     ~messages_byname() {}
 };
 
-extern template class messages_byname<char>;
-extern template class messages_byname<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class messages_byname<char>)
+_LIBCPP_EXTERN_TEMPLATE(class messages_byname<wchar_t>)
 
 template<class _Codecvt, class _Elem = wchar_t,
          class _Wide_alloc = allocator<_Elem>,
          class _Byte_alloc = allocator<char> >
-class _LIBCPP_VISIBLE wstring_convert
+class _LIBCPP_TYPE_VIS wstring_convert
 {
 public:
     typedef basic_string<char, char_traits<char>, _Byte_alloc>   byte_string;
@@ -3920,7 +4096,8 @@
     if (__cvtptr_ != nullptr)
     {
         wide_string __ws(2*(__frm_end - __frm), _Elem());
-        __ws.resize(__ws.capacity());
+        if (__frm != __frm_end)
+            __ws.resize(__ws.capacity());
         codecvt_base::result __r = codecvt_base::ok;
         state_type __st = __cvtstate_;
         if (__frm != __frm_end)
@@ -3980,7 +4157,8 @@
     if (__cvtptr_ != nullptr)
     {
         byte_string __bs(2*(__frm_end - __frm), char());
-        __bs.resize(__bs.capacity());
+        if (__frm != __frm_end)
+            __bs.resize(__bs.capacity());
         codecvt_base::result __r = codecvt_base::ok;
         state_type __st = __cvtstate_;
         if (__frm != __frm_end)
@@ -4060,7 +4238,7 @@
 }
 
 template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
-class _LIBCPP_VISIBLE wbuffer_convert
+class _LIBCPP_TYPE_VIS wbuffer_convert
     : public basic_streambuf<_Elem, _Tr>
 {
 public:

Modified: trunk/contrib/libc++/include/map
===================================================================
--- trunk/contrib/libc++/include/map	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/map	2016-01-07 17:22:14 UTC (rev 7405)
@@ -381,7 +381,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::value
+template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value
 #if __has_feature(is_final)
                                                         && !__is_final(_Compare)
 #endif
@@ -389,8 +389,6 @@
 class __map_value_compare
     : private _Compare
 {
-    typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _CP;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __map_value_compare()
@@ -404,41 +402,20 @@
     const _Compare& key_comp() const _NOEXCEPT {return *this;}
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _CP& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+        {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _CP& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _Key& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y);}
+        {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _CP& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return static_cast<const _Compare&>(*this)(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
-        {return static_cast<const _Compare&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return static_cast<const _Compare&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return static_cast<const _Compare&>(*this)(__x, __y);}
+        {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);}
 };
 
-template <class _Key, class _Tp, class _Compare>
-class __map_value_compare<_Key, _Tp, _Compare, false>
+template <class _Key, class _CP, class _Compare>
+class __map_value_compare<_Key, _CP, _Compare, false>
 {
     _Compare comp;
 
-    typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _CP;
-
 public:
     _LIBCPP_INLINE_VISIBILITY
     __map_value_compare()
@@ -453,31 +430,13 @@
 
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _CP& __y) const
-        {return comp(__x.first, __y.first);}
+        {return comp(__x.__cc.first, __y.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _CP& __x, const _Pp& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _CP& __x, const _Key& __y) const
-        {return comp(__x.first, __y);}
+        {return comp(__x.__cc.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _CP& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return comp(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return comp(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _CP& __y) const
-        {return comp(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return comp(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return comp(__x, __y);}
+        {return comp(__x, __y.__cc.first);}
 };
 
 template <class _Allocator>
@@ -489,8 +448,8 @@
 public:
     typedef typename __alloc_traits::pointer    pointer;
 private:
-    typedef typename value_type::first_type     first_type;
-    typedef typename value_type::second_type    second_type;
+    typedef typename value_type::value_type::first_type     first_type;
+    typedef typename value_type::value_type::second_type    second_type;
 
     allocator_type& __na_;
 
@@ -522,9 +481,9 @@
     void operator()(pointer __p) _NOEXCEPT
     {
         if (__second_constructed)
-            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
         if (__first_constructed)
-            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
         if (__p)
             __alloc_traits::deallocate(__na_, __p, 1);
     }
@@ -537,13 +496,13 @@
 template <class _TreeIterator> class __map_const_iterator;
 
 template <class _TreeIterator>
-class _LIBCPP_VISIBLE __map_iterator
+class _LIBCPP_TYPE_VIS __map_iterator
 {
     _TreeIterator __i_;
 
     typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
-    typedef const typename _TreeIterator::value_type::first_type __key_type;
-    typedef typename _TreeIterator::value_type::second_type      __mapped_type;
+    typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
+    typedef typename _TreeIterator::value_type::value_type::second_type      __mapped_type;
 public:
     typedef bidirectional_iterator_tag                           iterator_category;
     typedef pair<__key_type, __mapped_type>                      value_type;
@@ -564,9 +523,9 @@
     __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return *operator->();}
+    reference operator*() const {return __i_->__cc;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return (pointer)__i_.operator->();}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
 
     _LIBCPP_INLINE_VISIBILITY
     __map_iterator& operator++() {++__i_; return *this;}
@@ -596,19 +555,19 @@
     bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
-    template <class> friend class _LIBCPP_VISIBLE __map_const_iterator;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __map_const_iterator;
 };
 
 template <class _TreeIterator>
-class _LIBCPP_VISIBLE __map_const_iterator
+class _LIBCPP_TYPE_VIS __map_const_iterator
 {
     _TreeIterator __i_;
 
     typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
-    typedef const typename _TreeIterator::value_type::first_type __key_type;
-    typedef typename _TreeIterator::value_type::second_type      __mapped_type;
+    typedef const typename _TreeIterator::value_type::value_type::first_type __key_type;
+    typedef typename _TreeIterator::value_type::value_type::second_type      __mapped_type;
 public:
     typedef bidirectional_iterator_tag                           iterator_category;
     typedef pair<__key_type, __mapped_type>                      value_type;
@@ -634,9 +593,9 @@
                 : __i_(__i.__i_) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return *operator->();}
+    reference operator*() const {return __i_->__cc;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return (pointer)__i_.operator->();}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
 
     _LIBCPP_INLINE_VISIBILITY
     __map_const_iterator& operator++() {++__i_; return *this;}
@@ -665,14 +624,14 @@
     bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE map;
-    template <class, class, class, class> friend class _LIBCPP_VISIBLE multimap;
-    template <class, class, class> friend class _LIBCPP_VISIBLE __tree_const_iterator;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS __tree_const_iterator;
 };
 
 template <class _Key, class _Tp, class _Compare = less<_Key>,
           class _Allocator = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE map
+class _LIBCPP_TYPE_VIS map
 {
 public:
     // types:
@@ -679,12 +638,13 @@
     typedef _Key                                     key_type;
     typedef _Tp                                      mapped_type;
     typedef pair<const key_type, mapped_type>        value_type;
+    typedef pair<key_type, mapped_type>              __nc_value_type;
     typedef _Compare                                 key_compare;
     typedef _Allocator                               allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    class _LIBCPP_VISIBLE value_compare
+    class _LIBCPP_TYPE_VIS value_compare
         : public binary_function<value_type, value_type, bool>
     {
         friend class map;
@@ -699,8 +659,51 @@
     };
 
 private:
-    typedef pair<key_type, mapped_type>                             __value_type;
-    typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
+
+#if __cplusplus >= 201103L
+    union __value_type
+    {
+        typedef typename map::value_type value_type;
+        typedef typename map::__nc_value_type __nc_value_type;
+        value_type __cc;
+        __nc_value_type __nc;
+
+        template <class ..._Args>
+        __value_type(_Args&& ...__args)
+            : __cc(std::forward<_Args>(__args)...) {}
+
+        __value_type(const __value_type& __v)
+            : __cc(std::move(__v.__cc)) {}
+
+        __value_type(__value_type&& __v)
+            : __nc(std::move(__v.__nc)) {}
+
+        __value_type& operator=(const __value_type& __v)
+            {__nc = __v.__cc; return *this;}
+
+        __value_type& operator=(__value_type&& __v)
+            {__nc = std::move(__v.__nc); return *this;}
+
+        ~__value_type() {__cc.~value_type();}
+    };
+#else
+    struct __value_type
+    {
+        typedef typename map::value_type value_type;
+        value_type __cc;
+
+        __value_type() {}
+
+        template <class _A0>
+        __value_type(const _A0& __a0)
+            : __cc(__a0) {}
+
+        template <class _A0, class _A1>
+        __value_type(const _A0& __a0, const _A1& __a1)
+            : __cc(__a0, __a1) {}
+    };
+#endif
+    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
     typedef typename allocator_traits<allocator_type>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind_alloc<__value_type>
@@ -764,7 +767,14 @@
     _LIBCPP_INLINE_VISIBILITY
     map& operator=(const map& __m)
         {
+#if __cplusplus >= 201103L
             __tree_ = __m.__tree_;
+#else
+            __tree_.clear();
+            __tree_.value_comp() = __m.__tree_.value_comp();
+            __tree_.__copy_assign_alloc(__m.__tree_);
+            insert(__m.begin(), __m.end());
+#endif
             return *this;
         }
 
@@ -880,46 +890,16 @@
     value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-        emplace() {return __tree_.__emplace_unique();}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        pair<iterator, bool>
-        emplace(_A0&& __a0)
-            {return __tree_.__emplace_unique(_VSTD::forward<_A0>(__a0));}
-
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
+    template <class ..._Args>
         pair<iterator, bool>
-        emplace(_A0&& __a0, _Args&& ...__args);
+        emplace(_Args&& ...__args);
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    emplace_hint(const_iterator __p)
-        {return __tree_.__emplace_hint_unique(__p.__i_);}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
+    template <class ..._Args>
         iterator
-        emplace_hint(const_iterator __p, _A0&& __a0)
-            {return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_A0>(__a0));}
+        emplace_hint(const_iterator __p, _Args&& ...__args);
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        iterator
-        emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
-
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
     template <class _Pp,
@@ -1015,23 +995,18 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     __node_holder __construct_node();
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
+    template <class _A0>
         __node_holder __construct_node(_A0&& __a0);
+    __node_holder __construct_node_with_key(key_type&& __k);
 #ifndef _LIBCPP_HAS_NO_VARIADICS
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
 #endif  // _LIBCPP_HAS_NO_VARIADICS
-#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    __node_holder __construct_node(const key_type& __k);
 #endif
+    __node_holder __construct_node_with_key(const key_type& __k);
 
     __node_base_pointer&
         __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
-    __node_base_pointer&
-        __find_equal_key(const_iterator __hint,
-                         __node_base_pointer& __parent, const key_type& __k);
     __node_base_const_pointer
         __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
 };
@@ -1050,97 +1025,37 @@
     {
         while (true)
         {
-            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
+            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
             {
                 if (__nd->__left_ != nullptr)
                     __nd = static_cast<__node_pointer>(__nd->__left_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__left_;
                 }
             }
-            else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
+            else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
             {
                 if (__nd->__right_ != nullptr)
                     __nd = static_cast<__node_pointer>(__nd->__right_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return __parent->__right_;
                 }
             }
             else
             {
-                __parent = __nd;
+                __parent = static_cast<__node_base_pointer>(__nd);
                 return __parent;
             }
         }
     }
-    __parent = __tree_.__end_node();
+    __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
     return __parent->__left_;
 }
 
-// Find place to insert if __k doesn't exist
-// First check prior to __hint.
-// Next check after __hint.
-// Next do O(log N) search.
-// Set __parent to parent of null leaf
-// Return reference to null leaf
-// If __k exists, set parent to node of __k and return reference to node of __k
-template <class _Key, class _Tp, class _Compare, class _Allocator>
-typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
-map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint,
-                                                       __node_base_pointer& __parent,
-                                                       const key_type& __k)
-{
-    if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first))  // check before
-    {
-        // __k < *__hint
-        const_iterator __prior = __hint;
-        if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k))
-        {
-            // *prev(__hint) < __k < *__hint
-            if (__hint.__ptr_->__left_ == nullptr)
-            {
-                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
-                return __parent->__left_;
-            }
-            else
-            {
-                __parent = const_cast<__node_pointer&>(__prior.__ptr_);
-                return __parent->__right_;
-            }
-        }
-        // __k <= *prev(__hint)
-        return __find_equal_key(__parent, __k);
-    }
-    else if (__tree_.value_comp().key_comp()(__hint->first, __k))  // check after
-    {
-        // *__hint < __k
-        const_iterator __next = _VSTD::next(__hint);
-        if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first))
-        {
-            // *__hint < __k < *next(__hint)
-            if (__hint.__ptr_->__right_ == nullptr)
-            {
-                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
-                return __parent->__right_;
-            }
-            else
-            {
-                __parent = const_cast<__node_pointer&>(__next.__ptr_);
-                return __parent->__left_;
-            }
-        }
-        // *next(__hint) <= __k
-        return __find_equal_key(__parent, __k);
-    }
-    // else __k == *__hint
-    __parent = const_cast<__node_pointer&>(__hint.__ptr_);
-    return __parent;
-}
-
 // Find __k
 // Set __parent to parent of null leaf and
 //    return reference to null leaf iv __k does not exist.
@@ -1155,34 +1070,34 @@
     {
         while (true)
         {
-            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
+            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
             {
                 if (__nd->__left_ != nullptr)
                     __nd = static_cast<__node_pointer>(__nd->__left_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return const_cast<const __node_base_const_pointer&>(__parent->__left_);
                 }
             }
-            else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
+            else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
             {
                 if (__nd->__right_ != nullptr)
                     __nd = static_cast<__node_pointer>(__nd->__right_);
                 else
                 {
-                    __parent = __nd;
+                    __parent = static_cast<__node_base_pointer>(__nd);
                     return const_cast<const __node_base_const_pointer&>(__parent->__right_);
                 }
             }
             else
             {
-                __parent = __nd;
+                __parent = static_cast<__node_base_pointer>(__nd);
                 return __parent;
             }
         }
     }
-    __parent = __tree_.__end_node();
+    __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
     return const_cast<const __node_base_const_pointer&>(__parent->__left_);
 }
 
@@ -1207,16 +1122,15 @@
 {
     __node_allocator& __na = __tree_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0,
-          class>
+template <class _A0>
 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
 map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
 {
@@ -1228,19 +1142,32 @@
     return __h;
 }
 
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return _VSTD::move(__h);
+}
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class>
+template <class _A0, class _A1, class ..._Args>
 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
-map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
 {
     __node_allocator& __na = __tree_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
@@ -1247,23 +1174,21 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
-map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k)
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
 {
     __node_allocator& __na = __tree_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
     __h.get_deleter().__second_constructed = true;
     return _VSTD::move(__h);
 }
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 _Tp&
 map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
@@ -1273,11 +1198,11 @@
     __node_pointer __r = static_cast<__node_pointer>(__child);
     if (__child == nullptr)
     {
-        __node_holder __h = __construct_node(__k);
-        __tree_.__insert_node_at(__parent, __child, __h.get());
+        __node_holder __h = __construct_node_with_key(__k);
+        __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
     }
-    return __r->__value_.second;
+    return __r->__value_.__cc.second;
 }
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1291,11 +1216,11 @@
     __node_pointer __r = static_cast<__node_pointer>(__child);
     if (__child == nullptr)
     {
-        __node_holder __h = __construct_node(_VSTD::move(__k));
-        __tree_.__insert_node_at(__parent, __child, __h.get());
+        __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
+        __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
         __r = __h.release();
     }
-    return __r->__value_.second;
+    return __r->__value_.__cc.second;
 }
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1310,7 +1235,7 @@
     if (__child == nullptr)
         throw out_of_range("map::at:  key not found");
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    return static_cast<__node_pointer>(__child)->__value_.second;
+    return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
@@ -1323,20 +1248,17 @@
     if (__child == nullptr)
         throw out_of_range("map::at:  key not found");
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    return static_cast<__node_const_pointer>(__child)->__value_.second;
+    return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
 }
 
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
-         >
+template <class ..._Args>
 pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
-map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
+map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
     if (__r.second)
         __h.release();
@@ -1344,15 +1266,12 @@
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
-         >
+template <class ..._Args>
 typename map<_Key, _Tp, _Compare, _Allocator>::iterator
 map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
-                                                   _A0&& __a0, _Args&& ...__args)
+                                                   _Args&& ...__args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
     if (__r.__i_.__ptr_ == __h.get())
         __h.release();
@@ -1427,7 +1346,7 @@
 
 template <class _Key, class _Tp, class _Compare = less<_Key>,
           class _Allocator = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE multimap
+class _LIBCPP_TYPE_VIS multimap
 {
 public:
     // types:
@@ -1434,12 +1353,13 @@
     typedef _Key                                     key_type;
     typedef _Tp                                      mapped_type;
     typedef pair<const key_type, mapped_type>        value_type;
+    typedef pair<key_type, mapped_type>              __nc_value_type;
     typedef _Compare                                 key_compare;
     typedef _Allocator                               allocator_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    class _LIBCPP_VISIBLE value_compare
+    class _LIBCPP_TYPE_VIS value_compare
         : public binary_function<value_type, value_type, bool>
     {
         friend class multimap;
@@ -1455,8 +1375,50 @@
     };
 
 private:
-    typedef pair<key_type, mapped_type>                             __value_type;
-    typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
+#if __cplusplus >= 201103L
+    union __value_type
+    {
+        typedef typename multimap::value_type value_type;
+        typedef typename multimap::__nc_value_type __nc_value_type;
+        value_type __cc;
+        __nc_value_type __nc;
+
+        template <class ..._Args>
+        __value_type(_Args&& ...__args)
+            : __cc(std::forward<_Args>(__args)...) {}
+
+        __value_type(const __value_type& __v)
+            : __cc(std::move(__v.__cc)) {}
+
+        __value_type(__value_type&& __v)
+            : __nc(std::move(__v.__nc)) {}
+
+        __value_type& operator=(const __value_type& __v)
+            {__nc = __v.__cc; return *this;}
+
+        __value_type& operator=(__value_type&& __v)
+            {__nc = std::move(__v.__nc); return *this;}
+
+        ~__value_type() {__cc.~value_type();}
+    };
+#else
+    struct __value_type
+    {
+        typedef typename multimap::value_type value_type;
+        value_type __cc;
+
+        __value_type() {}
+
+        template <class _A0>
+        __value_type(const _A0& __a0)
+            : __cc(__a0) {}
+
+        template <class _A0, class _A1>
+        __value_type(const _A0& __a0, const _A1& __a1)
+            : __cc(__a0, __a1) {}
+    };
+#endif
+    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
     typedef typename allocator_traits<allocator_type>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind_alloc<__value_type>
@@ -1521,7 +1483,14 @@
     _LIBCPP_INLINE_VISIBILITY
     multimap& operator=(const multimap& __m)
         {
+#if __cplusplus >= 201103L
             __tree_ = __m.__tree_;
+#else
+            __tree_.clear();
+            __tree_.value_comp() = __m.__tree_.value_comp();
+            __tree_.__copy_assign_alloc(__m.__tree_);
+            insert(__m.begin(), __m.end());
+#endif
             return *this;
         }
 
@@ -1629,44 +1598,16 @@
         {return value_compare(__tree_.value_comp().key_comp());}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace() {return __tree_.__emplace_multi();}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        iterator
-        emplace(_A0&& __a0)
-            {return __tree_.__emplace_multi(_VSTD::forward<_A0>(__a0));}
-
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
+    template <class ..._Args>
         iterator
-        emplace(_A0&& __a0, _Args&& ...__args);
+        emplace(_Args&& ...__args);
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator __p)
-        {return __tree_.__emplace_hint_multi(__p.__i_);}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
+    template <class ..._Args>
         iterator
-        emplace_hint(const_iterator __p, _A0&& __a0)
-            {return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));}
+        emplace_hint(const_iterator __p, _Args&& ...__args);
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        iterator
-        emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
-
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
     template <class _Pp,
@@ -1757,13 +1698,12 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     __node_holder __construct_node();
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0);
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
 #ifndef _LIBCPP_HAS_NO_VARIADICS
-    template <class _A0, class ..._Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
@@ -1789,17 +1729,15 @@
 {
     __node_allocator& __na = __tree_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0,
-          class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
-         >
+template <class _A0>
 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
 multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
 {
@@ -1814,17 +1752,16 @@
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
+template <class _A0, class _A1, class ..._Args>
 typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
-multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
 {
     __node_allocator& __na = __tree_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
@@ -1835,14 +1772,11 @@
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
-         >
+template <class ..._Args>
 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
-multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
+multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __tree_.__node_insert_multi(__h.get());
     __h.release();
     return __r;
@@ -1849,16 +1783,12 @@
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-template <class _A0, class ..._Args,
-          class //= typename enable_if<is_constructible<_Key, _A0>::value>::type
-         >
+template <class ..._Args>
 typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
 multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
-                                                        _A0&& __a0,
                                                         _Args&& ...__args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
     __h.release();
     return __r;

Modified: trunk/contrib/libc++/include/memory
===================================================================
--- trunk/contrib/libc++/include/memory	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/memory	2016-01-07 17:22:14 UTC (rev 7405)
@@ -350,6 +350,10 @@
     bad_weak_ptr() noexcept;
 };
 
+template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);     // C++14
+template<class T>                unique_ptr<T> make_unique(size_t n);           // C++14
+template<class T, class... Args> unspecified   make_unique(Args&&...) = delete; // C++14, T == U[N]
+
 template<class T>
 class shared_ptr
 {
@@ -602,6 +606,10 @@
     #include <cassert>
 #endif
 
+#if __has_feature(cxx_atomic)
+#  include <atomic>
+#endif
+
 #include <__undef_min_max>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -617,7 +625,7 @@
 _Tp*
 addressof(_Tp& __x) _NOEXCEPT
 {
-    return (_Tp*)&(char&)__x;
+    return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
 }
 
 #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
@@ -663,7 +671,7 @@
 template <class _Tp> class allocator;
 
 template <>
-class _LIBCPP_VISIBLE allocator<void>
+class _LIBCPP_TYPE_VIS allocator<void>
 {
 public:
     typedef void*             pointer;
@@ -674,7 +682,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE allocator<const void>
+class _LIBCPP_TYPE_VIS allocator<const void>
 {
 public:
     typedef const void*       pointer;
@@ -690,7 +698,7 @@
 struct __has_element_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::element_type* = 0);
 public:
@@ -778,7 +786,7 @@
 struct __has_difference_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::difference_type* = 0);
 public:
@@ -801,7 +809,7 @@
 struct __has_rebind
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Xp> static __two __test(...);
     template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
 public:
@@ -909,7 +917,7 @@
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Ptr>
-struct _LIBCPP_VISIBLE pointer_traits
+struct _LIBCPP_TYPE_VIS pointer_traits
 {
     typedef _Ptr                                                     pointer;
     typedef typename __pointer_traits_element_type<pointer>::type    element_type;
@@ -932,7 +940,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE pointer_traits<_Tp*>
+struct _LIBCPP_TYPE_VIS pointer_traits<_Tp*>
 {
     typedef _Tp*      pointer;
     typedef _Tp       element_type;
@@ -994,7 +1002,7 @@
 struct __has_const_pointer
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::const_pointer* = 0);
 public:
@@ -1021,7 +1029,7 @@
 struct __has_void_pointer
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::void_pointer* = 0);
 public:
@@ -1048,7 +1056,7 @@
 struct __has_const_void_pointer
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
 public:
@@ -1091,7 +1099,7 @@
 struct __has_size_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::size_type* = 0);
 public:
@@ -1114,7 +1122,7 @@
 struct __has_propagate_on_container_copy_assignment
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
 public:
@@ -1137,7 +1145,7 @@
 struct __has_propagate_on_container_move_assignment
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
 public:
@@ -1160,7 +1168,7 @@
 struct __has_propagate_on_container_swap
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
 public:
@@ -1183,7 +1191,7 @@
 struct __has_rebind_other
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Xp> static __two __test(...);
     template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
 public:
@@ -1439,7 +1447,7 @@
 };
 
 template <class _Alloc>
-struct _LIBCPP_VISIBLE allocator_traits
+struct _LIBCPP_TYPE_VIS allocator_traits
 {
     typedef _Alloc                              allocator_type;
     typedef typename allocator_type::value_type value_type;
@@ -1567,7 +1575,10 @@
         __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
         {
             while (__end1 != __begin1)
-                construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
+            {
+                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
+                --__end2;
+            }
         }
 
     template <class _Tp>
@@ -1642,7 +1653,7 @@
 // allocator
 
 template <class _Tp>
-class _LIBCPP_VISIBLE allocator
+class _LIBCPP_TYPE_VIS allocator
 {
 public:
     typedef size_t            size_type;
@@ -1734,7 +1745,7 @@
 };
 
 template <class _Tp>
-class _LIBCPP_VISIBLE allocator<const _Tp>
+class _LIBCPP_TYPE_VIS allocator<const _Tp>
 {
 public:
     typedef size_t            size_type;
@@ -1743,7 +1754,7 @@
     typedef const _Tp*        const_pointer;
     typedef const _Tp&        reference;
     typedef const _Tp&        const_reference;
-    typedef _Tp               value_type;
+    typedef const _Tp         value_type;
 
     typedef true_type propagate_on_container_move_assignment;
 
@@ -1832,7 +1843,7 @@
 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
 
 template <class _OutputIterator, class _Tp>
-class _LIBCPP_VISIBLE raw_storage_iterator
+class _LIBCPP_TYPE_VIS raw_storage_iterator
     : public iterator<output_iterator_tag,
                       _Tp,                                         // purposefully not C++03
                       ptrdiff_t,                                   // purposefully not C++03
@@ -1885,7 +1896,7 @@
 };
 
 template<class _Tp>
-class _LIBCPP_VISIBLE auto_ptr
+class _LIBCPP_TYPE_VIS auto_ptr
 {
 private:
     _Tp* __ptr_;
@@ -1929,7 +1940,7 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE auto_ptr<void>
+class _LIBCPP_TYPE_VIS auto_ptr<void>
 {
 public:
     typedef void element_type;
@@ -2029,6 +2040,10 @@
             return *this;
         }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2044,10 +2059,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
     _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
     _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
 
@@ -2124,6 +2135,10 @@
             return *this;
         }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2139,10 +2154,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
     _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
     _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
 
@@ -2220,6 +2231,10 @@
             return *this;
         }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2236,10 +2251,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
     _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
     _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
 
@@ -2314,6 +2325,10 @@
             return *this;
         }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2329,10 +2344,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
     _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
     _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
 
@@ -2402,6 +2413,10 @@
             return *this;
         }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class... _Args1, class... _Args2>
@@ -2415,10 +2430,6 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
     _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
     _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
 
@@ -2465,9 +2476,13 @@
 // default_delete
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE default_delete
+struct _LIBCPP_TYPE_VIS default_delete
 {
-    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
+#else
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
+#endif
     template <class _Up>
         _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
              typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
@@ -2474,15 +2489,20 @@
     _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
         {
             static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
             delete __ptr;
         }
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE default_delete<_Tp[]>
+struct _LIBCPP_TYPE_VIS default_delete<_Tp[]>
 {
 public:
-    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
+#else
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
+#endif
     template <class _Up>
         _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
              typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
@@ -2492,12 +2512,13 @@
                          typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
         {
             static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
             delete [] __ptr;
         }
 };
 
 template <class _Tp, class _Dp = default_delete<_Tp> >
-class _LIBCPP_VISIBLE unique_ptr
+class _LIBCPP_TYPE_VIS unique_ptr
 {
 public:
     typedef _Tp element_type;
@@ -2520,13 +2541,13 @@
     typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
     typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
 public:
-    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
         : __ptr_(pointer())
         {
             static_assert(!is_pointer<deleter_type>::value,
                 "unique_ptr constructed with null function pointer deleter");
         }
-    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
         : __ptr_(pointer())
         {
             static_assert(!is_pointer<deleter_type>::value,
@@ -2676,7 +2697,7 @@
 };
 
 template <class _Tp, class _Dp>
-class _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp>
+class _LIBCPP_TYPE_VIS unique_ptr<_Tp[], _Dp>
 {
 public:
     typedef _Tp element_type;
@@ -2699,13 +2720,13 @@
     typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
     typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
 public:
-    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
         : __ptr_(pointer())
         {
             static_assert(!is_pointer<deleter_type>::value,
                 "unique_ptr constructed with null function pointer deleter");
         }
-    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
         : __ptr_(pointer())
         {
             static_assert(!is_pointer<deleter_type>::value,
@@ -2955,7 +2976,7 @@
 template <class _T1, class _D1>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
-operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
 {
     return !__x;
 }
@@ -2963,7 +2984,7 @@
 template <class _T1, class _D1>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
-operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
 {
     return !__x;
 }
@@ -2971,7 +2992,7 @@
 template <class _T1, class _D1>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
-operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
 {
     return static_cast<bool>(__x);
 }
@@ -2979,7 +3000,7 @@
 template <class _T1, class _D1>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
-operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
 {
     return static_cast<bool>(__x);
 }
@@ -3062,8 +3083,61 @@
 
 #endif
 
+#if _LIBCPP_STD_VER > 11
+
+template<class _Tp>
+struct __unique_if
+{
+    typedef unique_ptr<_Tp> __unique_single;
+};
+
+template<class _Tp>
+struct __unique_if<_Tp[]>
+{
+    typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
+};
+
+template<class _Tp, size_t _Np>
+struct __unique_if<_Tp[_Np]>
+{
+    typedef void __unique_array_known_bound;
+};
+
+template<class _Tp, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __unique_if<_Tp>::__unique_single
+make_unique(_Args&&... __args)
+{
+    return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __unique_if<_Tp>::__unique_array_unknown_bound
+make_unique(size_t __n)
+{
+    typedef typename remove_extent<_Tp>::type _Up;
+    return unique_ptr<_Tp>(new _Up[__n]());
+}
+
+template<class _Tp, class... _Args>
+    typename __unique_if<_Tp>::__unique_array_known_bound
+    make_unique(_Args&&...) = delete;
+
+#endif  // _LIBCPP_STD_VER > 11
+
 template <class _Tp> struct hash;
 
+template <class _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+_Size
+__loadword(const void* __p)
+{
+    _Size __r;
+    std::memcpy(&__r, __p, sizeof(__r));
+    return __r;
+}
+
 // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
 // is 64 bits.  This is because cityhash64 uses 64bit x 64bit
 // multiplication, which can be very slow on 32-bit systems.
@@ -3087,7 +3161,7 @@
     const unsigned char* __data = static_cast<const unsigned char*>(__key);
     for (; __len >= 4; __data += 4, __len -= 4)
     {
-        _Size __k = *(const _Size*)__data;
+        _Size __k = __loadword<_Size>(__data);
         __k *= __m;
         __k ^= __k >> __r;
         __k *= __m;
@@ -3146,13 +3220,13 @@
 
   static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
     if (__len > 8) {
-      const _Size __a = *(const _Size*)__s;
-      const _Size __b = *(const _Size*)(__s + __len - 8);
+      const _Size __a = __loadword<_Size>(__s);
+      const _Size __b = __loadword<_Size>(__s + __len - 8);
       return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
     }
     if (__len >= 4) {
-      const uint32_t __a = *(const uint32_t*)(__s);
-      const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
+      const uint32_t __a = __loadword<uint32_t>(__s);
+      const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
       return __hash_len_16(__len + (__a << 3), __b);
     }
     if (__len > 0) {
@@ -3168,10 +3242,10 @@
   }
 
   static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
-    const _Size __a = *(const _Size*)(__s) * __k1;
-    const _Size __b = *(const _Size*)(__s + 8);
-    const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
-    const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
+    const _Size __a = __loadword<_Size>(__s) * __k1;
+    const _Size __b = __loadword<_Size>(__s + 8);
+    const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
+    const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
     return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
                          __a + __rotate(__b ^ __k3, 20) - __c + __len);
   }
@@ -3192,10 +3266,10 @@
   // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
   static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
       const char* __s, _Size __a, _Size __b) {
-    return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
-                                         *(const _Size*)(__s + 8),
-                                         *(const _Size*)(__s + 16),
-                                         *(const _Size*)(__s + 24),
+    return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
+                                         __loadword<_Size>(__s + 8),
+                                         __loadword<_Size>(__s + 16),
+                                         __loadword<_Size>(__s + 24),
                                          __a,
                                          __b);
   }
@@ -3202,23 +3276,23 @@
 
   // Return an 8-byte hash for 33 to 64 bytes.
   static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
-    _Size __z = *(const _Size*)(__s + 24);
-    _Size __a = *(const _Size*)(__s) +
-                (__len + *(const _Size*)(__s + __len - 16)) * __k0;
+    _Size __z = __loadword<_Size>(__s + 24);
+    _Size __a = __loadword<_Size>(__s) +
+                (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
     _Size __b = __rotate(__a + __z, 52);
     _Size __c = __rotate(__a, 37);
-    __a += *(const _Size*)(__s + 8);
+    __a += __loadword<_Size>(__s + 8);
     __c += __rotate(__a, 7);
-    __a += *(const _Size*)(__s + 16);
+    __a += __loadword<_Size>(__s + 16);
     _Size __vf = __a + __z;
     _Size __vs = __b + __rotate(__a, 31) + __c;
-    __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
-    __z += *(const _Size*)(__s + __len - 8);
+    __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
+    __z += __loadword<_Size>(__s + __len - 8);
     __b = __rotate(__a + __z, 52);
     __c = __rotate(__a, 37);
-    __a += *(const _Size*)(__s + __len - 24);
+    __a += __loadword<_Size>(__s + __len - 24);
     __c += __rotate(__a, 7);
-    __a += *(const _Size*)(__s + __len - 16);
+    __a += __loadword<_Size>(__s + __len - 16);
     _Size __wf = __a + __z;
     _Size __ws = __b + __rotate(__a, 31) + __c;
     _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
@@ -3244,26 +3318,26 @@
 
   // For strings over 64 bytes we hash the end first, and then as we
   // loop we keep 56 bytes of state: v, w, x, y, and z.
-  _Size __x = *(const _Size*)(__s + __len - 40);
-  _Size __y = *(const _Size*)(__s + __len - 16) +
-              *(const _Size*)(__s + __len - 56);
-  _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
-                          *(const _Size*)(__s + __len - 24));
+  _Size __x = __loadword<_Size>(__s + __len - 40);
+  _Size __y = __loadword<_Size>(__s + __len - 16) +
+              __loadword<_Size>(__s + __len - 56);
+  _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
+                          __loadword<_Size>(__s + __len - 24));
   pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
   pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
-  __x = __x * __k1 + *(const _Size*)(__s);
+  __x = __x * __k1 + __loadword<_Size>(__s);
 
   // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
   __len = (__len - 1) & ~static_cast<_Size>(63);
   do {
-    __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
-    __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
+    __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
+    __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
     __x ^= __w.second;
-    __y += __v.first + *(const _Size*)(__s + 40);
+    __y += __v.first + __loadword<_Size>(__s + 40);
     __z = __rotate(__z + __w.first, 33) * __k1;
     __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
     __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
-                                        __y + *(const _Size*)(__s + 16));
+                                        __y + __loadword<_Size>(__s + 16));
     std::swap(__z, __x);
     __s += 64;
     __len -= 64;
@@ -3378,13 +3452,24 @@
 };
 
 template<class _Tp>
-struct _LIBCPP_VISIBLE hash<_Tp*>
-    : public __scalar_hash<_Tp*>
+struct _LIBCPP_TYPE_VIS hash<_Tp*>
+    : public unary_function<_Tp*, size_t>
 {
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(_Tp* __v) const _NOEXCEPT
+    {
+        union
+        {
+            _Tp* __t;
+            size_t __a;
+        } __u;
+        __u.__t = __v;
+        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
+    }
 };
 
 template <class _Tp, class _Dp>
-struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
+struct _LIBCPP_TYPE_VIS hash<unique_ptr<_Tp, _Dp> >
 {
     typedef unique_ptr<_Tp, _Dp> argument_type;
     typedef size_t               result_type;
@@ -3557,7 +3642,7 @@
     virtual const char* what() const  _NOEXCEPT;
 };
 
-template<class _Tp> class weak_ptr;
+template<class _Tp> class _LIBCPP_TYPE_VIS weak_ptr;
 
 class __shared_count
 {
@@ -3603,7 +3688,13 @@
     long use_count() const _NOEXCEPT {return __shared_count::use_count();}
     __shared_weak_count* lock() _NOEXCEPT;
 
+    // Define the function out only if we build static libc++ without RTTI.
+    // Otherwise we may break clients who need to compile their projects with
+    // -fno-rtti and yet link against a libc++.dylib compiled
+    // without -fno-rtti.
+#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
     virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
+#endif
 private:
     virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
 };
@@ -3720,10 +3811,10 @@
     __a.deallocate(this, 1);
 }
 
-template<class _Tp> class enable_shared_from_this;
+template<class _Tp> class _LIBCPP_TYPE_VIS enable_shared_from_this;
 
 template<class _Tp>
-class _LIBCPP_VISIBLE shared_ptr
+class _LIBCPP_TYPE_VIS shared_ptr
 {
 public:
     typedef _Tp element_type;
@@ -3733,8 +3824,8 @@
 
     struct __nat {int __for_bool_;};
 public:
-    shared_ptr() _NOEXCEPT;
-    shared_ptr(nullptr_t) _NOEXCEPT;
+    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
+    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
     template<class _Yp,
              class = typename enable_if
                      <
@@ -3923,6 +4014,10 @@
         _LIBCPP_INLINE_VISIBILITY
         bool owner_before(weak_ptr<_Up> const& __p) const
         {return __cntrl_ < __p.__cntrl_;}
+    _LIBCPP_INLINE_VISIBILITY
+    bool
+    __owner_equivalent(const shared_ptr& __p) const
+        {return __cntrl_ == __p.__cntrl_;}
 
 #ifndef _LIBCPP_NO_RTTI
     template <class _Dp>
@@ -3988,12 +4083,13 @@
     _LIBCPP_INLINE_VISIBILITY
     void __enable_weak_this(const void*) _NOEXCEPT {}
 
-    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
-    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
+    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
+    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
 };
 
 template<class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
     : __ptr_(0),
       __cntrl_(0)
@@ -4002,6 +4098,7 @@
 
 template<class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
     : __ptr_(0),
       __cntrl_(0)
@@ -4883,7 +4980,7 @@
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Tp>
-class _LIBCPP_VISIBLE weak_ptr
+class _LIBCPP_TYPE_VIS weak_ptr
 {
 public:
     typedef _Tp element_type;
@@ -4892,7 +4989,7 @@
     __shared_weak_count* __cntrl_;
 
 public:
-    weak_ptr() _NOEXCEPT;
+    _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
     template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
                         _NOEXCEPT;
@@ -4958,12 +5055,13 @@
         bool owner_before(const weak_ptr<_Up>& __r) const
         {return __cntrl_ < __r.__cntrl_;}
 
-    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
-    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
+    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
+    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
 };
 
 template<class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
     : __ptr_(0),
       __cntrl_(0)
@@ -5158,7 +5256,7 @@
 template <class _Tp> struct owner_less;
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> >
+struct _LIBCPP_TYPE_VIS owner_less<shared_ptr<_Tp> >
     : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
 {
     typedef bool result_type;
@@ -5174,7 +5272,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> >
+struct _LIBCPP_TYPE_VIS owner_less<weak_ptr<_Tp> >
     : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
 {
     typedef bool result_type;
@@ -5190,11 +5288,11 @@
 };
 
 template<class _Tp>
-class _LIBCPP_VISIBLE enable_shared_from_this
+class _LIBCPP_TYPE_VIS enable_shared_from_this
 {
     mutable weak_ptr<_Tp> __weak_this_;
 protected:
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
     enable_shared_from_this() _NOEXCEPT {}
     _LIBCPP_INLINE_VISIBILITY
     enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
@@ -5215,7 +5313,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
+struct _LIBCPP_TYPE_VIS hash<shared_ptr<_Tp> >
 {
     typedef shared_ptr<_Tp>      argument_type;
     typedef size_t               result_type;
@@ -5231,10 +5329,138 @@
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
 
+#if __has_feature(cxx_atomic)
+
+class __sp_mut
+{
+    void* __lx;
+public:
+    void lock() _NOEXCEPT;
+    void unlock() _NOEXCEPT;
+
+private:
+    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
+    __sp_mut(const __sp_mut&);
+    __sp_mut& operator=(const __sp_mut&);
+
+    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
+};
+
+_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_is_lock_free(const shared_ptr<_Tp>*)
+{
+    return false;
+}
+
+template <class _Tp>
+shared_ptr<_Tp>
+atomic_load(const shared_ptr<_Tp>* __p)
+{
+    __sp_mut& __m = __get_sp_mut(__p);
+    __m.lock();
+    shared_ptr<_Tp> __q = *__p;
+    __m.unlock();
+    return __q;
+}
+  
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
+{
+    return atomic_load(__p);
+}
+
+template <class _Tp>
+void
+atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
+{
+    __sp_mut& __m = __get_sp_mut(__p);
+    __m.lock();
+    __p->swap(__r);
+    __m.unlock();
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
+{
+    atomic_store(__p, __r);
+}
+
+template <class _Tp>
+shared_ptr<_Tp>
+atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
+{
+    __sp_mut& __m = __get_sp_mut(__p);
+    __m.lock();
+    __p->swap(__r);
+    __m.unlock();
+    return __r;
+}
+  
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
+{
+    return atomic_exchange(__p, __r);
+}
+
+template <class _Tp>
+bool
+atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
+{
+    __sp_mut& __m = __get_sp_mut(__p);
+    __m.lock();
+    if (__p->__owner_equivalent(*__v))
+    {
+        *__p = __w;
+        __m.unlock();
+        return true;
+    }
+    *__v = *__p;
+    __m.unlock();
+    return false;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
+{
+    return atomic_compare_exchange_strong(__p, __v, __w);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
+                                        shared_ptr<_Tp> __w, memory_order, memory_order)
+{
+    return atomic_compare_exchange_strong(__p, __v, __w);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
+                                      shared_ptr<_Tp> __w, memory_order, memory_order)
+{
+    return atomic_compare_exchange_weak(__p, __v, __w);
+}
+
+#endif  // __has_feature(cxx_atomic)
+
 //enum class
-struct _LIBCPP_VISIBLE pointer_safety
+struct _LIBCPP_TYPE_VIS pointer_safety
 {
-    enum _
+    enum __lx
     {
         relaxed,
         preferred,
@@ -5241,10 +5467,10 @@
         strict
     };
 
-    _ __v_;
+    __lx __v_;
 
     _LIBCPP_INLINE_VISIBILITY
-    pointer_safety(_ __v) : __v_(__v) {}
+    pointer_safety(__lx __v) : __v_(__v) {}
     _LIBCPP_INLINE_VISIBILITY
     operator int() const {return __v_;}
 };

Modified: trunk/contrib/libc++/include/mutex
===================================================================
--- trunk/contrib/libc++/include/mutex	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/mutex	2016-01-07 17:22:14 UTC (rev 7405)
@@ -20,7 +20,7 @@
 class mutex
 {
 public:
-     mutex();
+     constexpr mutex() noexcept;
      ~mutex();
 
     mutex(const mutex&) = delete;
@@ -44,7 +44,7 @@
     recursive_mutex& operator=(const recursive_mutex&) = delete;
 
     void lock();
-    bool try_lock();
+    bool try_lock() noexcept;
     void unlock();
 
     typedef pthread_mutex_t* native_handle_type;
@@ -79,7 +79,7 @@
     recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
 
     void lock();
-    bool try_lock();
+    bool try_lock() noexcept;
     template <class Rep, class Period>
         bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
     template <class Clock, class Duration>
@@ -114,9 +114,9 @@
 {
 public:
     typedef Mutex mutex_type;
-    unique_lock();
+    unique_lock() noexcept;
     explicit unique_lock(mutex_type& m);
-    unique_lock(mutex_type& m, defer_lock_t);
+    unique_lock(mutex_type& m, defer_lock_t) noexcept;
     unique_lock(mutex_type& m, try_to_lock_t);
     unique_lock(mutex_type& m, adopt_lock_t);
     template <class Clock, class Duration>
@@ -128,8 +128,8 @@
     unique_lock(unique_lock const&) = delete;
     unique_lock& operator=(unique_lock const&) = delete;
 
-    unique_lock(unique_lock&& u);
-    unique_lock& operator=(unique_lock&& u);
+    unique_lock(unique_lock&& u) noexcept;
+    unique_lock& operator=(unique_lock&& u) noexcept;
 
     void lock();
     bool try_lock();
@@ -141,16 +141,16 @@
 
     void unlock();
 
-    void swap(unique_lock& u);
-    mutex_type* release();
+    void swap(unique_lock& u) noexcept;
+    mutex_type* release() noexcept;
 
-    bool owns_lock() const;
-    explicit operator bool () const;
-    mutex_type* mutex() const;
+    bool owns_lock() const noexcept;
+    explicit operator bool () const noexcept;
+    mutex_type* mutex() const noexcept;
 };
 
 template <class Mutex>
-  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);
+  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
 
 template <class L1, class L2, class... L3>
   int try_lock(L1&, L2&, L3&...);
@@ -159,7 +159,7 @@
 
 struct once_flag
 {
-    constexpr once_flag();
+    constexpr once_flag() noexcept;
 
     once_flag(const once_flag&) = delete;
     once_flag& operator=(const once_flag&) = delete;
@@ -187,7 +187,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_VISIBLE recursive_mutex
+class _LIBCPP_TYPE_VIS recursive_mutex
 {
     pthread_mutex_t __m_;
 
@@ -201,8 +201,8 @@
 
 public:
     void lock();
-    bool try_lock();
-    void unlock();
+    bool try_lock() _NOEXCEPT;
+    void unlock()  _NOEXCEPT;
 
     typedef pthread_mutex_t* native_handle_type;
     _LIBCPP_INLINE_VISIBILITY
@@ -209,7 +209,7 @@
     native_handle_type native_handle() {return &__m_;}
 };
 
-class _LIBCPP_VISIBLE timed_mutex
+class _LIBCPP_TYPE_VIS timed_mutex
 {
     mutex              __m_;
     condition_variable __cv_;
@@ -224,7 +224,7 @@
 
 public:
     void lock();
-    bool try_lock();
+    bool try_lock() _NOEXCEPT;
     template <class _Rep, class _Period>
         _LIBCPP_INLINE_VISIBILITY
         bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
@@ -231,7 +231,7 @@
             {return try_lock_until(chrono::steady_clock::now() + __d);}
     template <class _Clock, class _Duration>
         bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
-    void unlock();
+    void unlock() _NOEXCEPT;
 };
 
 template <class _Clock, class _Duration>
@@ -251,7 +251,7 @@
     return false;
 }
 
-class _LIBCPP_VISIBLE recursive_timed_mutex
+class _LIBCPP_TYPE_VIS recursive_timed_mutex
 {
     mutex              __m_;
     condition_variable __cv_;
@@ -267,7 +267,7 @@
 
 public:
     void lock();
-    bool try_lock();
+    bool try_lock() _NOEXCEPT;
     template <class _Rep, class _Period>
         _LIBCPP_INLINE_VISIBILITY
         bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
@@ -274,7 +274,7 @@
             {return try_lock_until(chrono::steady_clock::now() + __d);}
     template <class _Clock, class _Duration>
         bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
-    void unlock();
+    void unlock() _NOEXCEPT;
 };
 
 template <class _Clock, class _Duration>
@@ -425,25 +425,27 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-struct once_flag;
+struct _LIBCPP_TYPE_VIS once_flag;
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template<class _Callable, class... _Args>
-  void call_once(once_flag&, _Callable&&, _Args&&...);
+_LIBCPP_INLINE_VISIBILITY
+void call_once(once_flag&, _Callable&&, _Args&&...);
 
 #else  // _LIBCPP_HAS_NO_VARIADICS
 
 template<class _Callable>
-  void call_once(once_flag&, _Callable);
+_LIBCPP_INLINE_VISIBILITY
+void call_once(once_flag&, _Callable);
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-struct _LIBCPP_VISIBLE once_flag
+struct _LIBCPP_TYPE_VIS once_flag
 {
     _LIBCPP_INLINE_VISIBILITY
-    // constexpr
-        once_flag() {}
+    _LIBCPP_CONSTEXPR
+        once_flag() _NOEXCEPT : __state_(0) {}
 
 private:
     once_flag(const once_flag&); // = delete;

Modified: trunk/contrib/libc++/include/new
===================================================================
--- trunk/contrib/libc++/include/new	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/new	2016-01-07 17:22:14 UTC (rev 7405)
@@ -83,31 +83,31 @@
 
 void __throw_bad_alloc();  // not in C++ spec
 
-struct _LIBCPP_VISIBLE nothrow_t {};
-extern _LIBCPP_VISIBLE const nothrow_t nothrow;
+struct _LIBCPP_TYPE_VIS nothrow_t {};
+extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
 typedef void (*new_handler)();
-_LIBCPP_VISIBLE new_handler set_new_handler(new_handler) _NOEXCEPT;
-_LIBCPP_VISIBLE new_handler get_new_handler() _NOEXCEPT;
+_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
+_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
 
 }  // std
 
-_LIBCPP_VISIBLE void* operator new(std::size_t __sz)
+_LIBCPP_FUNC_VIS void* operator new(std::size_t __sz)
 #if !__has_feature(cxx_noexcept)
     throw(std::bad_alloc)
 #endif
 ;
-_LIBCPP_VISIBLE void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT;
-_LIBCPP_VISIBLE void  operator delete(void* __p) _NOEXCEPT;
-_LIBCPP_VISIBLE void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
+_LIBCPP_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
+_LIBCPP_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
 
-_LIBCPP_VISIBLE void* operator new[](std::size_t __sz)
+_LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz)
 #if !__has_feature(cxx_noexcept)
     throw(std::bad_alloc)
 #endif
 ;
-_LIBCPP_VISIBLE void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT;
-_LIBCPP_VISIBLE void  operator delete[](void* __p) _NOEXCEPT;
-_LIBCPP_VISIBLE void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
+_LIBCPP_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
+_LIBCPP_FUNC_VIS void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
 
 _LIBCPP_INLINE_VISIBILITY inline void* operator new  (std::size_t, void* __p) _NOEXCEPT {return __p;}
 _LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}

Modified: trunk/contrib/libc++/include/ostream
===================================================================
--- trunk/contrib/libc++/include/ostream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ostream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -140,7 +140,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_ostream
+class _LIBCPP_TYPE_VIS basic_ostream
     : virtual public basic_ios<_CharT, _Traits>
 {
 public:
@@ -169,7 +169,7 @@
 public:
 
     // 27.7.2.4 Prefix/suffix:
-    class sentry;
+    class _LIBCPP_TYPE_VIS sentry;
 
     // 27.7.2.6 Formatted output:
     basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
@@ -207,7 +207,7 @@
 };
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_ostream<_CharT, _Traits>::sentry
+class _LIBCPP_TYPE_VIS basic_ostream<_CharT, _Traits>::sentry
 {
     bool __ok_;
     basic_ostream<_CharT, _Traits>& __os_;
@@ -1100,17 +1100,8 @@
         sentry __sen(*this);
         if (__sen && __n)
         {
-            typedef ostreambuf_iterator<_CharT, _Traits> _Op;
-            _Op __o(*this);
-            for (; __n; --__n, ++__o, ++__s)
-            {
-                *__o = *__s;
-                if (__o.failed())
-                {
-                    this->setstate(ios_base::badbit);
-                    break;
-                }
-            }
+            if (this->rdbuf()->sputn(__s, __n) != __n)
+                this->setstate(ios_base::badbit);
         }
 #ifndef _LIBCPP_NO_EXCEPTIONS
     }
@@ -1287,8 +1278,8 @@
                          use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
 }
 
-extern template class basic_ostream<char>;
-extern template class basic_ostream<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class basic_ostream<char>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_ostream<wchar_t>)
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/queue
===================================================================
--- trunk/contrib/libc++/include/queue	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/queue	2016-01-07 17:22:14 UTC (rev 7405)
@@ -177,18 +177,20 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp, class _Container> class queue;
+template <class _Tp, class _Container> class _LIBCPP_TYPE_VIS queue;
 
 template <class _Tp, class _Container>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
 
 template <class _Tp, class _Container>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
 
 template <class _Tp, class _Container = deque<_Tp> >
-class _LIBCPP_VISIBLE queue
+class _LIBCPP_TYPE_VIS queue
 {
 public:
     typedef _Container                               container_type;
@@ -374,7 +376,7 @@
 }
 
 template <class _Tp, class _Container, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
+struct _LIBCPP_TYPE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
     : public uses_allocator<_Container, _Alloc>
 {
 };
@@ -381,7 +383,7 @@
 
 template <class _Tp, class _Container = vector<_Tp>,
           class _Compare = less<typename _Container::value_type> >
-class _LIBCPP_VISIBLE priority_queue
+class _LIBCPP_TYPE_VIS priority_queue
 {
 public:
     typedef _Container                               container_type;
@@ -705,7 +707,7 @@
 }
 
 template <class _Tp, class _Container, class _Compare, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
+struct _LIBCPP_TYPE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
     : public uses_allocator<_Container, _Alloc>
 {
 };

Modified: trunk/contrib/libc++/include/random
===================================================================
--- trunk/contrib/libc++/include/random	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/random	2016-01-07 17:22:14 UTC (rev 7405)
@@ -217,7 +217,7 @@
     void discard(unsigned long long z);
 
     // property functions
-    const Engine& base() const;
+    const Engine& base() const noexcept;
 };
 
 template<class Engine, size_t p, size_t r>
@@ -269,7 +269,7 @@
     result_type operator()(); void discard(unsigned long long z);
 
     // property functions
-    const Engine& base() const;
+    const Engine& base() const noexcept;
 };
 
 template<class Engine, size_t w, class UIntType>
@@ -323,7 +323,7 @@
     void discard(unsigned long long z);
 
     // property functions
-    const Engine& base() const;
+    const Engine& base() const noexcept;
 };
 
 template<class Engine, size_t k>
@@ -392,7 +392,7 @@
     result_type operator()();
 
     // property functions
-    double entropy() const;
+    double entropy() const noexcept;
 
     // no copy functions
     random_device(const random_device& ) = delete;
@@ -1813,10 +1813,11 @@
 };
 
 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-class linear_congruential_engine;
+class _LIBCPP_TYPE_VIS linear_congruential_engine;
 
 template <class _CharT, class _Traits,
           class _Up, _Up _Ap, _Up _Cp, _Up _Np>
+_LIBCPP_INLINE_VISIBILITY
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&);
@@ -1828,7 +1829,7 @@
            linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
 
 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
-class _LIBCPP_VISIBLE linear_congruential_engine
+class _LIBCPP_TYPE_VIS linear_congruential_engine
 {
 public:
     // types
@@ -1879,7 +1880,7 @@
         seed(_Sseq& __q)
             {__seed(__q, integral_constant<unsigned,
                 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
-                             :  (__m-1) / 0x100000000ull)>());}
+                             :  (__m > 0x100000000ull))>());}
 
     // generating functions
     _LIBCPP_INLINE_VISIBILITY
@@ -1930,6 +1931,22 @@
 };
 
 template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+    _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
+    linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
 template<class _Sseq>
 void
 linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
@@ -1952,7 +1969,7 @@
     uint32_t __ar[__k+3];
     __q.generate(__ar, __ar + __k + 3);
     result_type __s = static_cast<result_type>((__ar[3] +
-                                                (uint64_t)__ar[4] << 32) % __m);
+                                              ((uint64_t)__ar[4] << 32)) % __m);
     __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
 }
 
@@ -1990,7 +2007,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     __os.fill(__os.widen(' '));
     return __os << __x.__x_;
@@ -2002,7 +2019,7 @@
 operator>>(basic_istream<_CharT, _Traits>& __is,
            linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     _UIntType __t;
     __is >> __t;
@@ -2021,7 +2038,7 @@
 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
           _UIntType __a, size_t __u, _UIntType __d, size_t __s,
           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-class mersenne_twister_engine;
+class _LIBCPP_TYPE_VIS mersenne_twister_engine;
 
 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
           _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
@@ -2035,6 +2052,7 @@
 template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp,
           _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp,
           _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
                                          _Bp, _Tp, _Cp, _Lp, _Fp>& __x,
@@ -2062,7 +2080,7 @@
 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
           _UIntType __a, size_t __u, _UIntType __d, size_t __s,
           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
-class _LIBCPP_VISIBLE mersenne_twister_engine
+class _LIBCPP_TYPE_VIS mersenne_twister_engine
 {
 public:
     // types
@@ -2228,6 +2246,90 @@
 template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
           _UIntType __a, size_t __u, _UIntType __d, size_t __s,
           _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const size_t 
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+    _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type
+    mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
 void
 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
     __t, __c, __l, __f>::seed(result_type __sd)
@@ -2375,7 +2477,7 @@
            const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
                                          _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     _CharT __sp = __os.widen(' ');
     __os.fill(__sp);
@@ -2396,7 +2498,7 @@
            mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp,
                                    _Bp, _Tp, _Cp, _Lp, _Fp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     _UI __t[_Np];
     for (size_t __i = 0; __i < _Np; ++__i)
@@ -2424,7 +2526,7 @@
 // subtract_with_carry_engine
 
 template<class _UIntType, size_t __w, size_t __s, size_t __r>
-class subtract_with_carry_engine;
+class _LIBCPP_TYPE_VIS subtract_with_carry_engine;
 
 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
 bool
@@ -2433,6 +2535,7 @@
     const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y);
 
 template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator!=(
     const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x,
@@ -2451,7 +2554,7 @@
            subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x);
 
 template<class _UIntType, size_t __w, size_t __s, size_t __r>
-class _LIBCPP_VISIBLE subtract_with_carry_engine
+class _LIBCPP_TYPE_VIS subtract_with_carry_engine
 {
 public:
     // types
@@ -2549,6 +2652,19 @@
 };
 
 template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+    _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
+    subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
 void
 subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
         integral_constant<unsigned, 1>)
@@ -2681,7 +2797,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     _CharT __sp = __os.widen(' ');
     __os.fill(__sp);
@@ -2700,7 +2816,7 @@
 operator>>(basic_istream<_CharT, _Traits>& __is,
            subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     _UI __t[_Rp+1];
     for (size_t __i = 0; __i < _Rp+1; ++__i)
@@ -2721,7 +2837,7 @@
 // discard_block_engine
 
 template<class _Engine, size_t __p, size_t __r>
-class _LIBCPP_VISIBLE discard_block_engine
+class _LIBCPP_TYPE_VIS discard_block_engine
 {
     _Engine __e_;
     int     __n_;
@@ -2788,7 +2904,7 @@
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const {return __e_;}
+    const _Engine& base() const _NOEXCEPT {return __e_;}
 
     template<class _Eng, size_t _Pp, size_t _Rp>
     friend
@@ -2820,6 +2936,12 @@
 };
 
 template<class _Engine, size_t __p, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
+
+template<class _Engine, size_t __p, size_t __r>
+    _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
+
+template<class _Engine, size_t __p, size_t __r>
 typename discard_block_engine<_Engine, __p, __r>::result_type
 discard_block_engine<_Engine, __p, __r>::operator()()
 {
@@ -2856,7 +2978,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const discard_block_engine<_Eng, _Pp, _Rp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     _CharT __sp = __os.widen(' ');
     __os.fill(__sp);
@@ -2869,7 +2991,7 @@
 operator>>(basic_istream<_CharT, _Traits>& __is,
            discard_block_engine<_Eng, _Pp, _Rp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     _Eng __e;
     int __n;
@@ -2888,7 +3010,7 @@
 // independent_bits_engine
 
 template<class _Engine, size_t __w, class _UIntType>
-class _LIBCPP_VISIBLE independent_bits_engine
+class _LIBCPP_TYPE_VIS independent_bits_engine
 {
     template <class _UI, _UI _R0, size_t _Wp, size_t _Mp>
     class __get_n
@@ -2993,7 +3115,7 @@
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const {return __e_;}
+    const _Engine& base() const _NOEXCEPT {return __e_;}
 
     template<class _Eng, size_t _Wp, class _UI>
     friend
@@ -3151,7 +3273,7 @@
 };
 
 template<class _Engine, size_t __k>
-class _LIBCPP_VISIBLE shuffle_order_engine
+class _LIBCPP_TYPE_VIS shuffle_order_engine
 {
     static_assert(0 < __k, "shuffle_order_engine invalid parameters");
 public:
@@ -3222,7 +3344,7 @@
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
-    const _Engine& base() const {return __e_;}
+    const _Engine& base() const _NOEXCEPT {return __e_;}
 
 private:
     template<class _Eng, size_t _Kp>
@@ -3311,6 +3433,9 @@
         }
 };
 
+template<class _Engine, size_t __k>
+    _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
+
 template<class _Eng, size_t _Kp>
 bool
 operator==(
@@ -3337,7 +3462,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const shuffle_order_engine<_Eng, _Kp>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     _CharT __sp = __os.widen(' ');
     __os.fill(__sp);
@@ -3354,7 +3479,7 @@
            shuffle_order_engine<_Eng, _Kp>& __x)
 {
     typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     _Eng __e;
     result_type _Vp[_Kp+1];
@@ -3375,7 +3500,7 @@
 
 // random_device
 
-class _LIBCPP_VISIBLE random_device
+class _LIBCPP_TYPE_VIS random_device
 {
     int __f_;
 public:
@@ -3399,7 +3524,7 @@
     result_type operator()();
 
     // property functions
-    double entropy() const;
+    double entropy() const _NOEXCEPT;
 
 private:
     // no copy functions
@@ -3409,7 +3534,7 @@
 
 // seed_seq
 
-class _LIBCPP_VISIBLE seed_seq
+class _LIBCPP_TYPE_VIS seed_seq
 {
 public:
     // types
@@ -3558,7 +3683,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const uniform_int_distribution<_IT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left);
     _CharT __sp = __os.widen(' ');
     __os.fill(__sp);
@@ -3573,7 +3698,7 @@
     typedef uniform_int_distribution<_IT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __a;
     result_type __b;
@@ -3586,13 +3711,13 @@
 // uniform_real_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE uniform_real_distribution
+class _LIBCPP_TYPE_VIS uniform_real_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __a_;
         result_type __b_;
@@ -3679,7 +3804,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const uniform_real_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -3695,7 +3820,7 @@
     typedef uniform_real_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __a;
     result_type __b;
@@ -3707,13 +3832,13 @@
 
 // bernoulli_distribution
 
-class _LIBCPP_VISIBLE bernoulli_distribution
+class _LIBCPP_TYPE_VIS bernoulli_distribution
 {
 public:
     // types
     typedef bool result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         double __p_;
     public:
@@ -3790,7 +3915,7 @@
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -3804,7 +3929,7 @@
 {
     typedef bernoulli_distribution _Eng;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     double __p;
     __is >> __p;
@@ -3816,13 +3941,13 @@
 // binomial_distribution
 
 template<class _IntType = int>
-class _LIBCPP_VISIBLE binomial_distribution
+class _LIBCPP_TYPE_VIS binomial_distribution
 {
 public:
     // types
     typedef _IntType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __t_;
         double __p_;
@@ -3952,7 +4077,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const binomial_distribution<_IntType>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -3968,7 +4093,7 @@
     typedef binomial_distribution<_IntType> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __t;
     double __p;
@@ -3981,13 +4106,13 @@
 // exponential_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE exponential_distribution
+class _LIBCPP_TYPE_VIS exponential_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __lambda_;
     public:
@@ -4070,7 +4195,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const exponential_distribution<_RealType>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     return __os << __x.lambda();
@@ -4084,7 +4209,7 @@
     typedef exponential_distribution<_RealType> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __lambda;
     __is >> __lambda;
@@ -4096,13 +4221,13 @@
 // normal_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE normal_distribution
+class _LIBCPP_TYPE_VIS normal_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __mean_;
         result_type __stddev_;
@@ -4224,7 +4349,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const normal_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -4243,7 +4368,7 @@
     typedef normal_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __mean;
     result_type __stddev;
@@ -4264,13 +4389,13 @@
 // lognormal_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE lognormal_distribution
+class _LIBCPP_TYPE_VIS lognormal_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         normal_distribution<result_type> __nd_;
     public:
@@ -4389,13 +4514,13 @@
 // poisson_distribution
 
 template<class _IntType = int>
-class _LIBCPP_VISIBLE poisson_distribution
+class _LIBCPP_TYPE_VIS poisson_distribution
 {
 public:
     // types
     typedef _IntType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         double __mean_;
         double __s_;
@@ -4595,7 +4720,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const poisson_distribution<_IntType>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     return __os << __x.mean();
@@ -4608,7 +4733,7 @@
 {
     typedef poisson_distribution<_IntType> _Eng;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     double __mean;
     __is >> __mean;
@@ -4620,13 +4745,13 @@
 // weibull_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE weibull_distribution
+class _LIBCPP_TYPE_VIS weibull_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __a_;
         result_type __b_;
@@ -4706,7 +4831,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const weibull_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -4723,7 +4848,7 @@
     typedef weibull_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __a;
     result_type __b;
@@ -4734,13 +4859,13 @@
 }
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE extreme_value_distribution
+class _LIBCPP_TYPE_VIS extreme_value_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __a_;
         result_type __b_;
@@ -4825,7 +4950,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const extreme_value_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -4842,7 +4967,7 @@
     typedef extreme_value_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __a;
     result_type __b;
@@ -4855,13 +4980,13 @@
 // gamma_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE gamma_distribution
+class _LIBCPP_TYPE_VIS gamma_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __alpha_;
         result_type __beta_;
@@ -4997,7 +5122,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const gamma_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -5014,7 +5139,7 @@
     typedef gamma_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __alpha;
     result_type __beta;
@@ -5027,13 +5152,13 @@
 // negative_binomial_distribution
 
 template<class _IntType = int>
-class _LIBCPP_VISIBLE negative_binomial_distribution
+class _LIBCPP_TYPE_VIS negative_binomial_distribution
 {
 public:
     // types
     typedef _IntType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __k_;
         double __p_;
@@ -5133,7 +5258,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const negative_binomial_distribution<_IntType>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -5149,7 +5274,7 @@
     typedef negative_binomial_distribution<_IntType> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __k;
     double __p;
@@ -5162,13 +5287,13 @@
 // geometric_distribution
 
 template<class _IntType = int>
-class _LIBCPP_VISIBLE geometric_distribution
+class _LIBCPP_TYPE_VIS geometric_distribution
 {
 public:
     // types
     typedef _IntType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         double __p_;
     public:
@@ -5239,7 +5364,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const geometric_distribution<_IntType>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     return __os << __x.p();
@@ -5252,7 +5377,7 @@
 {
     typedef geometric_distribution<_IntType> _Eng;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     double __p;
     __is >> __p;
@@ -5264,13 +5389,13 @@
 // chi_squared_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE chi_squared_distribution
+class _LIBCPP_TYPE_VIS chi_squared_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __n_;
     public:
@@ -5343,7 +5468,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const chi_squared_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     __os << __x.n();
@@ -5358,7 +5483,7 @@
     typedef chi_squared_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __n;
     __is >> __n;
@@ -5370,13 +5495,13 @@
 // cauchy_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE cauchy_distribution
+class _LIBCPP_TYPE_VIS cauchy_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __a_;
         result_type __b_;
@@ -5463,7 +5588,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const cauchy_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -5480,7 +5605,7 @@
     typedef cauchy_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __a;
     result_type __b;
@@ -5493,13 +5618,13 @@
 // fisher_f_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE fisher_f_distribution
+class _LIBCPP_TYPE_VIS fisher_f_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __m_;
         result_type __n_;
@@ -5585,7 +5710,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const fisher_f_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -5602,7 +5727,7 @@
     typedef fisher_f_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __m;
     result_type __n;
@@ -5615,13 +5740,13 @@
 // student_t_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE student_t_distribution
+class _LIBCPP_TYPE_VIS student_t_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         result_type __n_;
     public:
@@ -5701,7 +5826,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const student_t_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     __os << __x.n();
@@ -5716,7 +5841,7 @@
     typedef student_t_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     result_type __n;
     __is >> __n;
@@ -5728,13 +5853,13 @@
 // discrete_distribution
 
 template<class _IntType = int>
-class _LIBCPP_VISIBLE discrete_distribution
+class _LIBCPP_TYPE_VIS discrete_distribution
 {
 public:
     // types
     typedef _IntType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         vector<double> __p_;
     public:
@@ -5924,7 +6049,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const discrete_distribution<_IT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -5944,7 +6069,7 @@
     typedef discrete_distribution<_IT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     size_t __n;
     __is >> __n;
@@ -5959,13 +6084,13 @@
 // piecewise_constant_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE piecewise_constant_distribution
+class _LIBCPP_TYPE_VIS piecewise_constant_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         vector<result_type> __b_;
         vector<result_type> __densities_;
@@ -6228,7 +6353,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const piecewise_constant_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -6256,7 +6381,7 @@
     typedef piecewise_constant_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     size_t __n;
     __is >> __n;
@@ -6283,13 +6408,13 @@
 // piecewise_linear_distribution
 
 template<class _RealType = double>
-class _LIBCPP_VISIBLE piecewise_linear_distribution
+class _LIBCPP_TYPE_VIS piecewise_linear_distribution
 {
 public:
     // types
     typedef _RealType result_type;
 
-    class _LIBCPP_VISIBLE param_type
+    class _LIBCPP_TYPE_VIS param_type
     {
         vector<result_type> __b_;
         vector<result_type> __densities_;
@@ -6568,7 +6693,7 @@
 operator<<(basic_ostream<_CharT, _Traits>& __os,
            const piecewise_linear_distribution<_RT>& __x)
 {
-    __save_flags<_CharT, _Traits> _(__os);
+    __save_flags<_CharT, _Traits> __lx(__os);
     __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
                ios_base::scientific);
     _CharT __sp = __os.widen(' ');
@@ -6596,7 +6721,7 @@
     typedef piecewise_linear_distribution<_RT> _Eng;
     typedef typename _Eng::result_type result_type;
     typedef typename _Eng::param_type param_type;
-    __save_flags<_CharT, _Traits> _(__is);
+    __save_flags<_CharT, _Traits> __lx(__is);
     __is.flags(ios_base::dec | ios_base::skipws);
     size_t __n;
     __is >> __n;

Modified: trunk/contrib/libc++/include/ratio
===================================================================
--- trunk/contrib/libc++/include/ratio	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/ratio	2016-01-07 17:22:14 UTC (rev 7405)
@@ -231,7 +231,7 @@
 };
 
 template <intmax_t _Num, intmax_t _Den = 1>
-class _LIBCPP_VISIBLE ratio
+class _LIBCPP_TYPE_VIS ratio
 {
     static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
     static_assert(_Den != 0, "ratio divide by 0");
@@ -292,7 +292,7 @@
 #else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_multiply
+struct _LIBCPP_TYPE_VIS ratio_multiply
     : public __ratio_multiply<_R1, _R2>::type {};
 
 #endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
@@ -319,7 +319,7 @@
 #else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_divide
+struct _LIBCPP_TYPE_VIS ratio_divide
     : public __ratio_divide<_R1, _R2>::type {};
 
 #endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
@@ -354,7 +354,7 @@
 #else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_add
+struct _LIBCPP_TYPE_VIS ratio_add
     : public __ratio_add<_R1, _R2>::type {};
 
 #endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
@@ -389,7 +389,7 @@
 #else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_subtract
+struct _LIBCPP_TYPE_VIS ratio_subtract
     : public __ratio_subtract<_R1, _R2>::type {};
 
 #endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
@@ -397,11 +397,11 @@
 // ratio_equal
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_equal
+struct _LIBCPP_TYPE_VIS ratio_equal
     : public integral_constant<bool, _R1::num == _R2::num && _R1::den == _R2::den> {};
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_not_equal
+struct _LIBCPP_TYPE_VIS ratio_not_equal
     : public integral_constant<bool, !ratio_equal<_R1, _R2>::value> {};
 
 // ratio_less
@@ -460,19 +460,19 @@
 };
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_less
+struct _LIBCPP_TYPE_VIS ratio_less
     : public integral_constant<bool, __ratio_less<_R1, _R2>::value> {};
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_less_equal
+struct _LIBCPP_TYPE_VIS ratio_less_equal
     : public integral_constant<bool, !ratio_less<_R2, _R1>::value> {};
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_greater
+struct _LIBCPP_TYPE_VIS ratio_greater
     : public integral_constant<bool, ratio_less<_R2, _R1>::value> {};
 
 template <class _R1, class _R2>
-struct _LIBCPP_VISIBLE ratio_greater_equal
+struct _LIBCPP_TYPE_VIS ratio_greater_equal
     : public integral_constant<bool, !ratio_less<_R1, _R2>::value> {};
 
 template <class _R1, class _R2>

Modified: trunk/contrib/libc++/include/regex
===================================================================
--- trunk/contrib/libc++/include/regex	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/regex	2016-01-07 17:22:14 UTC (rev 7405)
@@ -147,7 +147,7 @@
     explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
     basic_regex(const charT* p, size_t len, flag_type f);
     basic_regex(const basic_regex&);
-    basic_regex(basic_regex&&);
+    basic_regex(basic_regex&&) noexcept;
     template <class ST, class SA>
         explicit basic_regex(const basic_string<charT, ST, SA>& p,
                              flag_type f = regex_constants::ECMAScript);
@@ -159,7 +159,7 @@
     ~basic_regex();
 
     basic_regex& operator=(const basic_regex&);
-    basic_regex& operator=(basic_regex&&);
+    basic_regex& operator=(basic_regex&&) noexcept;
     basic_regex& operator=(const charT* ptr);
     basic_regex& operator=(initializer_list<charT> il);
     template <class ST, class SA>
@@ -167,7 +167,7 @@
 
     // assign:
     basic_regex& assign(const basic_regex& that);
-    basic_regex& assign(basic_regex&& that);
+    basic_regex& assign(basic_regex&& that) noexcept;
     basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
     basic_regex& assign(const charT* p, size_t len, flag_type f);
     template <class string_traits, class A>
@@ -449,7 +449,7 @@
     // construct/copy/destroy:
     explicit match_results(const Allocator& a = Allocator());
     match_results(const match_results& m);
-    match_results(match_results&& m);
+    match_results(match_results&& m) noexcept;
     match_results& operator=(const match_results& m);
     match_results& operator=(match_results&& m);
     ~match_results();
@@ -760,15 +760,15 @@
 };
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 syntax_option_type
 operator~(syntax_option_type __x)
 {
-    return syntax_option_type(~int(__x));
+    return syntax_option_type(~int(__x) & 0x1FF);
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 syntax_option_type
 operator&(syntax_option_type __x, syntax_option_type __y)
 {
@@ -776,7 +776,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 syntax_option_type
 operator|(syntax_option_type __x, syntax_option_type __y)
 {
@@ -784,7 +784,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 syntax_option_type
 operator^(syntax_option_type __x, syntax_option_type __y)
 {
@@ -792,7 +792,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 syntax_option_type&
 operator&=(syntax_option_type& __x, syntax_option_type __y)
 {
@@ -801,7 +800,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 syntax_option_type&
 operator|=(syntax_option_type& __x, syntax_option_type __y)
 {
@@ -810,7 +808,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 syntax_option_type&
 operator^=(syntax_option_type& __x, syntax_option_type __y)
 {
@@ -839,15 +836,15 @@
 };
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 match_flag_type
 operator~(match_flag_type __x)
 {
-    return match_flag_type(~int(__x));
+    return match_flag_type(~int(__x) & 0x0FFF);
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 match_flag_type
 operator&(match_flag_type __x, match_flag_type __y)
 {
@@ -855,7 +852,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 match_flag_type
 operator|(match_flag_type __x, match_flag_type __y)
 {
@@ -863,7 +860,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
+_LIBCPP_CONSTEXPR
 match_flag_type
 operator^(match_flag_type __x, match_flag_type __y)
 {
@@ -871,7 +868,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 match_flag_type&
 operator&=(match_flag_type& __x, match_flag_type __y)
 {
@@ -880,7 +876,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 match_flag_type&
 operator|=(match_flag_type& __x, match_flag_type __y)
 {
@@ -889,7 +884,6 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-/*constexpr*/
 match_flag_type&
 operator^=(match_flag_type& __x, match_flag_type __y)
 {
@@ -931,7 +925,7 @@
 };
 
 template <class _CharT>
-struct _LIBCPP_VISIBLE regex_traits
+struct _LIBCPP_TYPE_VIS regex_traits
 {
 public:
     typedef _CharT                  char_type;
@@ -1015,6 +1009,10 @@
 };
 
 template <class _CharT>
+const typename regex_traits<_CharT>::char_class_type
+regex_traits<_CharT>::__regex_word;
+
+template <class _CharT>
 regex_traits<_CharT>::regex_traits()
 {
     __init();
@@ -1237,11 +1235,11 @@
 
 template <class _CharT> class __node;
 
-template <class _BidirectionalIterator> class sub_match;
+template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS sub_match;
 
 template <class _BidirectionalIterator,
           class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
-class match_results;
+class _LIBCPP_TYPE_VIS match_results;
 
 template <class _CharT>
 struct __state
@@ -2417,7 +2415,7 @@
 template <class _CharT, class _Traits> class __lookahead;
 
 template <class _CharT, class _Traits = regex_traits<_CharT> >
-class _LIBCPP_VISIBLE basic_regex
+class _LIBCPP_TYPE_VIS basic_regex
 {
 public:
     // types:
@@ -2439,16 +2437,16 @@
 
 public:
     // constants:
-    static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
-    static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
-    static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
-    static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
-    static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
-    static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
-    static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
-    static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
-    static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
-    static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
+    static const regex_constants::syntax_option_type icase = regex_constants::icase;
+    static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
+    static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
+    static const regex_constants::syntax_option_type collate = regex_constants::collate;
+    static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
+    static const regex_constants::syntax_option_type basic = regex_constants::basic;
+    static const regex_constants::syntax_option_type extended = regex_constants::extended;
+    static const regex_constants::syntax_option_type awk = regex_constants::awk;
+    static const regex_constants::syntax_option_type grep = regex_constants::grep;
+    static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
 
     // construct/copy/destroy:
     _LIBCPP_INLINE_VISIBILITY
@@ -2512,7 +2510,12 @@
     _LIBCPP_INLINE_VISIBILITY
     basic_regex& assign(const basic_regex& __that)
         {return *this = __that;}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
+    basic_regex& assign(basic_regex&& __that) _NOEXCEPT
+        {return *this = _VSTD::move(__that);}
+#endif
+    _LIBCPP_INLINE_VISIBILITY
     basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
         {return assign(__p, __p + __traits_.length(__p), __f);}
     _LIBCPP_INLINE_VISIBILITY
@@ -2563,6 +2566,7 @@
         {
             __member_init(__f);
             __parse(__first, __last);
+            return *this;
         }
 
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -2839,10 +2843,40 @@
                  const basic_regex<_Cp, _Tp>& __e,
                  regex_constants::match_flag_type __flags);
 
+    template <class _Iter, class _Ap, class _Cp, class _Tp>
+    friend
+    bool
+    regex_search(__wrap_iter<_Iter> __first,
+                 __wrap_iter<_Iter> __last,
+                 match_results<__wrap_iter<_Iter>, _Ap>& __m,
+                 const basic_regex<_Cp, _Tp>& __e,
+                 regex_constants::match_flag_type __flags);
+
     template <class, class> friend class __lookahead;
 };
 
 template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
+template <class _CharT, class _Traits>
+    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
+
+template <class _CharT, class _Traits>
 void
 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
 {
@@ -2896,7 +2930,7 @@
     bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
                                                   __m,
                                                   __s.__flags_ | regex_constants::match_continuous,
-                                                  true);
+                                                  __s.__at_first_ && __s.__current_ == __s.__first_);
     if (__matched != __invert_)
     {
         __s.__do_ = __state::__accept_but_not_consume;
@@ -3395,6 +3429,7 @@
                 case '+':
                 case '?':
                 case '{':
+                case '}':
                     __push_char(*__temp);
                     __first = ++__temp;
                     break;
@@ -3878,7 +3913,7 @@
         {
             __val = 8 * __val + *__first - '0';
             if (++__first != __last && ('0' <= *__first && *__first <= '7'))
-                __val = 8 * __val + *__first - '0';
+                __val = 8 * __val + *__first++ - '0';
         }
         if (__str)
             *__str = _CharT(__val);
@@ -4456,7 +4491,7 @@
                 ++__first;
             }
 #ifndef _LIBCPP_NO_EXCEPTIONS
-            else if (__str)
+            else
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
             break;
@@ -4728,7 +4763,7 @@
 // sub_match
 
 template <class _BidirectionalIterator>
-class _LIBCPP_VISIBLE sub_match
+class _LIBCPP_TYPE_VIS sub_match
     : public pair<_BidirectionalIterator, _BidirectionalIterator>
 {
 public:
@@ -4740,7 +4775,7 @@
     bool matched;
 
     _LIBCPP_INLINE_VISIBILITY
-    /*constexpr*/ sub_match() : matched() {}
+    _LIBCPP_CONSTEXPR sub_match() : matched() {}
 
     _LIBCPP_INLINE_VISIBILITY
     difference_type length() const
@@ -5151,7 +5186,7 @@
 }
 
 template <class _BidirectionalIterator, class _Allocator>
-class _LIBCPP_VISIBLE match_results
+class _LIBCPP_TYPE_VIS match_results
 {
 public:
     typedef _Allocator                                        allocator_type;
@@ -5782,6 +5817,21 @@
     return __r;
 }
 
+template <class _Iter, class _Allocator, class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+regex_search(__wrap_iter<_Iter> __first,
+             __wrap_iter<_Iter> __last,
+             match_results<__wrap_iter<_Iter>, _Allocator>& __m,
+             const basic_regex<_CharT, _Traits>& __e,
+             regex_constants::match_flag_type __flags = regex_constants::match_default)
+{
+    match_results<const _CharT*> __mc;
+    bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
+    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
+    return __r;
+}
+
 template <class _Allocator, class _CharT, class _Traits>
 inline _LIBCPP_INLINE_VISIBILITY
 bool
@@ -5937,7 +5987,7 @@
 template <class _BidirectionalIterator,
           class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
           class _Traits = regex_traits<_CharT> >
-class _LIBCPP_VISIBLE regex_iterator
+class _LIBCPP_TYPE_VIS regex_iterator
 {
 public:
     typedef basic_regex<_CharT, _Traits>          regex_type;
@@ -6019,7 +6069,7 @@
 {
     __flags_ |= regex_constants::__no_update_pos;
     _BidirectionalIterator __start = __match_[0].second;
-    if (__match_.length() == 0)
+    if (__match_.empty())
     {
         if (__start == __end_)
         {
@@ -6049,7 +6099,7 @@
 template <class _BidirectionalIterator,
           class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
           class _Traits = regex_traits<_CharT> >
-class _LIBCPP_VISIBLE regex_token_iterator
+class _LIBCPP_TYPE_VIS regex_token_iterator
 {
 public:
     typedef basic_regex<_CharT, _Traits>      regex_type;

Modified: trunk/contrib/libc++/include/scoped_allocator
===================================================================
--- trunk/contrib/libc++/include/scoped_allocator	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/scoped_allocator	2016-01-07 17:22:14 UTC (rev 7405)
@@ -365,7 +365,7 @@
 };
 
 template <class _OuterAlloc, class... _InnerAllocs>
-class _LIBCPP_VISIBLE scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
+class _LIBCPP_TYPE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
     : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
 {
     typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;

Modified: trunk/contrib/libc++/include/set
===================================================================
--- trunk/contrib/libc++/include/set	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/set	2016-01-07 17:22:14 UTC (rev 7405)
@@ -346,7 +346,7 @@
 
 template <class _Key, class _Compare = less<_Key>,
           class _Allocator = allocator<_Key> >
-class _LIBCPP_VISIBLE set
+class _LIBCPP_TYPE_VIS set
 {
 public:
     // types:
@@ -685,7 +685,7 @@
 
 template <class _Key, class _Compare = less<_Key>,
           class _Allocator = allocator<_Key> >
-class _LIBCPP_VISIBLE multiset
+class _LIBCPP_TYPE_VIS multiset
 {
 public:
     // types:

Modified: trunk/contrib/libc++/include/sstream
===================================================================
--- trunk/contrib/libc++/include/sstream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/sstream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -186,7 +186,7 @@
 // basic_stringbuf
 
 template <class _CharT, class _Traits, class _Allocator>
-class _LIBCPP_VISIBLE basic_stringbuf
+class _LIBCPP_TYPE_VIS basic_stringbuf
     : public basic_streambuf<_CharT, _Traits>
 {
 public:
@@ -260,17 +260,36 @@
 basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs)
     : __mode_(__rhs.__mode_)
 {
-    ptrdiff_t __ninp = __rhs.gptr()  - __rhs.eback();
-    ptrdiff_t __einp = __rhs.egptr() - __rhs.eback();
-    ptrdiff_t __nout = __rhs.pptr()  - __rhs.pbase();
-    ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase();
-    ptrdiff_t __hm   = __rhs.__hm_   - __rhs.pbase();
+    char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
+    ptrdiff_t __binp = -1;
+    ptrdiff_t __ninp = -1;
+    ptrdiff_t __einp = -1;
+    if (__rhs.eback() != nullptr)
+    {
+        __binp = __rhs.eback() - __p;
+        __ninp = __rhs.gptr() - __p;
+        __einp = __rhs.egptr() - __p;
+    }
+    ptrdiff_t __bout = -1;
+    ptrdiff_t __nout = -1;
+    ptrdiff_t __eout = -1;
+    if (__rhs.pbase() != nullptr)
+    {
+        __bout = __rhs.pbase() - __p;
+        __nout = __rhs.pptr() - __p;
+        __eout = __rhs.epptr() - __p;
+    }
+    ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
     __str_ = _VSTD::move(__rhs.__str_);
-    char_type* __p = const_cast<char_type*>(__str_.data());
-    this->setg(__p, __p + __ninp, __p + __einp);
-    this->setp(__p, __p + __eout);
-    this->pbump(__nout);
-    __hm_ = __p + __hm;
+    __p = const_cast<char_type*>(__str_.data());
+    if (__binp != -1)
+        this->setg(__p + __binp, __p + __ninp, __p + __einp);
+    if (__bout != -1)
+    {
+        this->setp(__p + __bout, __p + __eout);
+        this->pbump(__nout);
+    }
+    __hm_ = __hm == -1 ? nullptr : __p + __hm;
     __p = const_cast<char_type*>(__rhs.__str_.data());
     __rhs.setg(__p, __p, __p);
     __rhs.setp(__p, __p);
@@ -282,18 +301,37 @@
 basic_stringbuf<_CharT, _Traits, _Allocator>&
 basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
 {
-    ptrdiff_t __ninp = __rhs.gptr()  - __rhs.eback();
-    ptrdiff_t __einp = __rhs.egptr() - __rhs.eback();
-    ptrdiff_t __nout = __rhs.pptr()  - __rhs.pbase();
-    ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase();
-    ptrdiff_t __hm   = __rhs.__hm_   - __rhs.pbase();
+    char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
+    ptrdiff_t __binp = -1;
+    ptrdiff_t __ninp = -1;
+    ptrdiff_t __einp = -1;
+    if (__rhs.eback() != nullptr)
+    {
+        __binp = __rhs.eback() - __p;
+        __ninp = __rhs.gptr() - __p;
+        __einp = __rhs.egptr() - __p;
+    }
+    ptrdiff_t __bout = -1;
+    ptrdiff_t __nout = -1;
+    ptrdiff_t __eout = -1;
+    if (__rhs.pbase() != nullptr)
+    {
+        __bout = __rhs.pbase() - __p;
+        __nout = __rhs.pptr() - __p;
+        __eout = __rhs.epptr() - __p;
+    }
+    ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
+    __str_ = _VSTD::move(__rhs.__str_);
+    __p = const_cast<char_type*>(__str_.data());
+    if (__binp != -1)
+        this->setg(__p + __binp, __p + __ninp, __p + __einp);
+    if (__bout != -1)
+    {
+        this->setp(__p + __bout, __p + __eout);
+        this->pbump(__nout);
+    }
+    __hm_ = __hm == -1 ? nullptr : __p + __hm;
     __mode_ = __rhs.__mode_;
-    __str_ = _VSTD::move(__rhs.__str_);
-    char_type* __p = const_cast<char_type*>(__str_.data());
-    this->setg(__p, __p + __ninp, __p + __einp);
-    this->setp(__p, __p + __eout);
-    this->pbump(__nout);
-    __hm_ = __p + __hm;
     __p = const_cast<char_type*>(__rhs.__str_.data());
     __rhs.setg(__p, __p, __p);
     __rhs.setp(__p, __p);
@@ -308,28 +346,74 @@
 void
 basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
 {
-    ptrdiff_t __rninp = __rhs.gptr()  - __rhs.eback();
-    ptrdiff_t __reinp = __rhs.egptr() - __rhs.eback();
-    ptrdiff_t __rnout = __rhs.pptr()  - __rhs.pbase();
-    ptrdiff_t __reout = __rhs.epptr() - __rhs.pbase();
-    ptrdiff_t __rhm   = __rhs.__hm_   - __rhs.pbase();
-    ptrdiff_t __lninp = this->gptr()  - this->eback();
-    ptrdiff_t __leinp = this->egptr() - this->eback();
-    ptrdiff_t __lnout = this->pptr()  - this->pbase();
-    ptrdiff_t __leout = this->epptr() - this->pbase();
-    ptrdiff_t __lhm   = this->__hm_   - this->pbase();
+    char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
+    ptrdiff_t __rbinp = -1;
+    ptrdiff_t __rninp = -1;
+    ptrdiff_t __reinp = -1;
+    if (__rhs.eback() != nullptr)
+    {
+        __rbinp = __rhs.eback() - __p;
+        __rninp = __rhs.gptr() - __p;
+        __reinp = __rhs.egptr() - __p;
+    }
+    ptrdiff_t __rbout = -1;
+    ptrdiff_t __rnout = -1;
+    ptrdiff_t __reout = -1;
+    if (__rhs.pbase() != nullptr)
+    {
+        __rbout = __rhs.pbase() - __p;
+        __rnout = __rhs.pptr() - __p;
+        __reout = __rhs.epptr() - __p;
+    }
+    ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
+    __p = const_cast<char_type*>(__str_.data());
+    ptrdiff_t __lbinp = -1;
+    ptrdiff_t __lninp = -1;
+    ptrdiff_t __leinp = -1;
+    if (this->eback() != nullptr)
+    {
+        __lbinp = this->eback() - __p;
+        __lninp = this->gptr() - __p;
+        __leinp = this->egptr() - __p;
+    }
+    ptrdiff_t __lbout = -1;
+    ptrdiff_t __lnout = -1;
+    ptrdiff_t __leout = -1;
+    if (this->pbase() != nullptr)
+    {
+        __lbout = this->pbase() - __p;
+        __lnout = this->pptr() - __p;
+        __leout = this->epptr() - __p;
+    }
+    ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
     _VSTD::swap(__mode_, __rhs.__mode_);
     __str_.swap(__rhs.__str_);
-    char_type* __p = const_cast<char_type*>(__str_.data());
-    this->setg(__p, __p + __rninp, __p + __reinp);
-    this->setp(__p, __p + __reout);
-    this->pbump(__rnout);
-    __hm_ = __p + __rhm;
+    __p = const_cast<char_type*>(__str_.data());
+    if (__rbinp != -1)
+        this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
+    else
+        this->setg(nullptr, nullptr, nullptr);
+    if (__rbout != -1)
+    {
+        this->setp(__p + __rbout, __p + __reout);
+        this->pbump(__rnout);
+    }
+    else
+        this->setp(nullptr, nullptr);
+    __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
     __p = const_cast<char_type*>(__rhs.__str_.data());
-    __rhs.setg(__p, __p + __lninp, __p + __leinp);
-    __rhs.setp(__p, __p + __leout);
-    __rhs.pbump(__lnout);
-    __rhs.__hm_ = __p + __lhm;
+    if (__lbinp != -1)
+        __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
+    else
+        __rhs.setg(nullptr, nullptr, nullptr);
+    if (__lbout != -1)
+    {
+        __rhs.setp(__p + __lbout, __p + __leout);
+        __rhs.pbump(__lnout);
+    }
+    else
+        __rhs.setp(nullptr, nullptr);
+    __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
     locale __tl = __rhs.getloc();
     __rhs.pubimbue(this->getloc());
     this->pubimbue(__tl);
@@ -529,7 +613,7 @@
 // basic_istringstream
 
 template <class _CharT, class _Traits, class _Allocator>
-class _LIBCPP_VISIBLE basic_istringstream
+class _LIBCPP_TYPE_VIS basic_istringstream
     : public basic_istream<_CharT, _Traits>
 {
 public:
@@ -648,7 +732,7 @@
 // basic_ostringstream
 
 template <class _CharT, class _Traits, class _Allocator>
-class _LIBCPP_VISIBLE basic_ostringstream
+class _LIBCPP_TYPE_VIS basic_ostringstream
     : public basic_ostream<_CharT, _Traits>
 {
 public:
@@ -767,7 +851,7 @@
 // basic_stringstream
 
 template <class _CharT, class _Traits, class _Allocator>
-class _LIBCPP_VISIBLE basic_stringstream
+class _LIBCPP_TYPE_VIS basic_stringstream
     : public basic_iostream<_CharT, _Traits>
 {
 public:

Modified: trunk/contrib/libc++/include/stack
===================================================================
--- trunk/contrib/libc++/include/stack	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/stack	2016-01-07 17:22:14 UTC (rev 7405)
@@ -91,18 +91,20 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp, class _Container> class stack;
+template <class _Tp, class _Container> class _LIBCPP_TYPE_VIS stack;
 
 template <class _Tp, class _Container>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
 
 template <class _Tp, class _Container>
+_LIBCPP_INLINE_VISIBILITY
 bool
 operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
 
 template <class _Tp, class _Container = deque<_Tp> >
-class _LIBCPP_VISIBLE stack
+class _LIBCPP_TYPE_VIS stack
 {
 public:
     typedef _Container                               container_type;
@@ -280,7 +282,7 @@
 }
 
 template <class _Tp, class _Container, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator<stack<_Tp, _Container>, _Alloc>
+struct _LIBCPP_TYPE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc>
     : public uses_allocator<_Container, _Alloc>
 {
 };

Modified: trunk/contrib/libc++/include/streambuf
===================================================================
--- trunk/contrib/libc++/include/streambuf	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/streambuf	2016-01-07 17:22:14 UTC (rev 7405)
@@ -119,7 +119,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _CharT, class _Traits>
-class _LIBCPP_VISIBLE basic_streambuf
+class _LIBCPP_TYPE_VIS basic_streambuf
 {
 public:
     // types:
@@ -540,7 +540,7 @@
     {
         if (__nout_ < __eout_)
             *__nout_++ = *__s;
-        else if (overflow(*__s) == __eof)
+        else if (overflow(traits_type::to_int_type(*__s)) == __eof)
             break;
     }
     return __i;
@@ -553,11 +553,11 @@
     return traits_type::eof();
 }
 
-extern template class basic_streambuf<char>;
-extern template class basic_streambuf<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class basic_streambuf<char>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_streambuf<wchar_t>)
 
-extern template class basic_ios<char>;
-extern template class basic_ios<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class basic_ios<char>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_ios<wchar_t>)
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/string
===================================================================
--- trunk/contrib/libc++/include/string	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/string	2016-01-07 17:22:14 UTC (rev 7405)
@@ -51,8 +51,8 @@
     typedef mbstate_t state_type;
 
     static void assign(char_type& c1, const char_type& c2) noexcept;
-    static bool eq(char_type c1, char_type c2) noexcept;
-    static bool lt(char_type c1, char_type c2) noexcept;
+    static constexpr bool eq(char_type c1, char_type c2) noexcept;
+    static constexpr bool lt(char_type c1, char_type c2) noexcept;
 
     static int              compare(const char_type* s1, const char_type* s2, size_t n);
     static size_t           length(const char_type* s);
@@ -61,11 +61,11 @@
     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);
 
-    static int_type  not_eof(int_type c) noexcept;
-    static char_type to_char_type(int_type c) noexcept;
-    static int_type  to_int_type(char_type c) noexcept;
-    static bool      eq_int_type(int_type c1, int_type c2) noexcept;
-    static int_type  eof() noexcept;
+    static constexpr int_type  not_eof(int_type c) noexcept;
+    static constexpr char_type to_char_type(int_type c) noexcept;
+    static constexpr int_type  to_int_type(char_type c) noexcept;
+    static constexpr bool      eq_int_type(int_type c1, int_type c2) noexcept;
+    static constexpr int_type  eof() noexcept;
 };
 
 template <> struct char_traits<char>;
@@ -100,8 +100,8 @@
         noexcept(is_nothrow_move_constructible<allocator_type>::value);
     basic_string(const basic_string& str, size_type pos, size_type n = npos,
                  const allocator_type& a = allocator_type());
-    basic_string(const_pointer s, const allocator_type& a = allocator_type());
-    basic_string(const_pointer s, size_type n, const allocator_type& a = allocator_type());
+    basic_string(const value_type* s, const allocator_type& a = allocator_type());
+    basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
     basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
     template<class InputIterator>
         basic_string(InputIterator begin, InputIterator end,
@@ -117,7 +117,7 @@
         noexcept(
              allocator_type::propagate_on_container_move_assignment::value &&
              is_nothrow_move_assignable<allocator_type>::value);
-    basic_string& operator=(const_pointer s);
+    basic_string& operator=(const value_type* s);
     basic_string& operator=(value_type c);
     basic_string& operator=(initializer_list<value_type>);
 
@@ -156,14 +156,14 @@
     reference       at(size_type n);
 
     basic_string& operator+=(const basic_string& str);
-    basic_string& operator+=(const_pointer s);
+    basic_string& operator+=(const value_type* s);
     basic_string& operator+=(value_type c);
     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_pointer s, size_type n);
-    basic_string& append(const_pointer s);
+    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);
     template<class InputIterator>
         basic_string& append(InputIterator first, InputIterator last);
@@ -179,8 +179,8 @@
     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_pointer s, size_type n);
-    basic_string& assign(const_pointer s);
+    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);
     template<class InputIterator>
         basic_string& assign(InputIterator first, InputIterator last);
@@ -189,8 +189,8 @@
     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_pointer s, size_type n);
-    basic_string& insert(size_type pos, const_pointer s);
+    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);
     iterator      insert(const_iterator p, value_type c);
     iterator      insert(const_iterator p, size_type n, value_type c);
@@ -205,18 +205,18 @@
     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 pos, size_type n1, const_pointer s, size_type n2);
-    basic_string& replace(size_type pos, size_type n1, const_pointer s);
+    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);
     basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
-    basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s, size_type n);
-    basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s);
+    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
+    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
     basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
     template<class InputIterator>
         basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
     basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
 
-    size_type copy(pointer s, size_type n, size_type pos = 0) const;
+    size_type copy(value_type* s, size_type n, size_type pos = 0) const;
     basic_string substr(size_type pos = 0, size_type n = npos) const;
 
     void swap(basic_string& str)
@@ -223,39 +223,39 @@
         noexcept(!allocator_type::propagate_on_container_swap::value ||
                  __is_nothrow_swappable<allocator_type>::value)
 
-    const_pointer c_str() const noexcept;
-    const_pointer data() const noexcept;
+    const value_type* c_str() const noexcept;
+    const value_type* data() const noexcept;
 
     allocator_type get_allocator() const noexcept;
 
     size_type find(const basic_string& str, size_type pos = 0) const noexcept;
-    size_type find(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type find(const_pointer s, size_type pos = 0) const noexcept;
+    size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type find(const value_type* s, size_type pos = 0) const noexcept;
     size_type find(value_type c, size_type pos = 0) const noexcept;
 
     size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
-    size_type rfind(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type rfind(const_pointer s, size_type pos = npos) const noexcept;
+    size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
     size_type rfind(value_type c, size_type pos = npos) const noexcept;
 
     size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
-    size_type find_first_of(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type find_first_of(const_pointer s, size_type pos = 0) const noexcept;
+    size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
     size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
 
     size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
-    size_type find_last_of(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type find_last_of(const_pointer s, size_type pos = npos) const noexcept;
+    size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
     size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
 
     size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
-    size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type find_first_not_of(const_pointer s, size_type pos = 0) const noexcept;
+    size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
     size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
 
     size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
-    size_type find_last_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
-    size_type find_last_not_of(const_pointer s, size_type pos = npos) const noexcept;
+    size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
+    size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
     size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
 
     int compare(const basic_string& str) const noexcept;
@@ -262,9 +262,9 @@
     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(const_pointer s) const noexcept;
-    int compare(size_type pos1, size_type n1, const_pointer s) const;
-    int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) 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;
 
     bool __invariants() const;
 };
@@ -457,7 +457,7 @@
 // fpos
 
 template <class _StateT>
-class _LIBCPP_VISIBLE fpos
+class _LIBCPP_TYPE_VIS fpos
 {
 private:
     _StateT __st_;
@@ -494,7 +494,7 @@
 // char_traits
 
 template <class _CharT>
-struct _LIBCPP_VISIBLE char_traits
+struct _LIBCPP_TYPE_VIS char_traits
 {
     typedef _CharT    char_type;
     typedef int       int_type;
@@ -506,10 +506,10 @@
     static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static _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);
@@ -519,19 +519,20 @@
     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 int_type  not_eof(int_type __c) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
     _LIBCPP_INLINE_VISIBILITY
-    static char_type to_char_type(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  to_int_type(char_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static bool      eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool      eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  eof() _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
         {return int_type(EOF);}
 };
 
@@ -619,7 +620,7 @@
 // char_traits<char>
 
 template <>
-struct _LIBCPP_VISIBLE char_traits<char>
+struct _LIBCPP_TYPE_VIS char_traits<char>
 {
     typedef char      char_type;
     typedef int       int_type;
@@ -631,10 +632,10 @@
     static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
             {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return (unsigned char)__c1 < (unsigned char)__c2;}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -655,19 +656,20 @@
     static 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 int_type  not_eof(int_type __c) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY
+    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
     _LIBCPP_INLINE_VISIBILITY
-    static char_type to_char_type(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type to_int_type(char_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type((unsigned char)__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  eof() _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
         {return int_type(EOF);}
 };
 
@@ -674,7 +676,7 @@
 // char_traits<wchar_t>
 
 template <>
-struct _LIBCPP_VISIBLE char_traits<wchar_t>
+struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
 {
     typedef wchar_t   char_type;
     typedef wint_t    int_type;
@@ -686,10 +688,10 @@
     static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
     _LIBCPP_INLINE_VISIBILITY
@@ -712,19 +714,19 @@
         {return (char_type*)wmemset(__s, __a, __n);}
 
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  not_eof(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
     _LIBCPP_INLINE_VISIBILITY
-    static char_type to_char_type(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type to_int_type(char_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type eof() _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(WEOF);}
 };
 
@@ -731,7 +733,7 @@
 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
 
 template <>
-struct _LIBCPP_VISIBLE char_traits<char16_t>
+struct _LIBCPP_TYPE_VIS char_traits<char16_t>
 {
     typedef char16_t       char_type;
     typedef uint_least16_t int_type;
@@ -743,10 +745,10 @@
     static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static _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);
@@ -757,19 +759,19 @@
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  not_eof(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
     _LIBCPP_INLINE_VISIBILITY
-    static char_type to_char_type(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type to_int_type(char_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type eof() _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(0xDFFF);}
 };
 
@@ -851,7 +853,7 @@
 }
 
 template <>
-struct _LIBCPP_VISIBLE char_traits<char32_t>
+struct _LIBCPP_TYPE_VIS char_traits<char32_t>
 {
     typedef char32_t       char_type;
     typedef uint_least32_t int_type;
@@ -863,10 +865,10 @@
     static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
         {__c1 = __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
+    static _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);
@@ -877,19 +879,19 @@
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
     _LIBCPP_INLINE_VISIBILITY
-    static int_type  not_eof(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
         {return eq_int_type(__c, eof()) ? ~eof() : __c;}
     _LIBCPP_INLINE_VISIBILITY
-    static char_type to_char_type(int_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
         {return char_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type to_int_type(char_type __c) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
         {return int_type(__c);}
     _LIBCPP_INLINE_VISIBILITY
-    static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
+    static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
         {return __c1 == __c2;}
     _LIBCPP_INLINE_VISIBILITY
-    static int_type eof() _NOEXCEPT
+    static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
         {return int_type(0xFFFFFFFF);}
 };
 
@@ -1029,13 +1031,28 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _MSC_VER
-extern template class __basic_string_common<true>;
+_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
 #ifdef _MSC_VER
 #pragma warning( pop )
 #endif // _MSC_VER
 
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+
+template <class _CharT, size_t = sizeof(_CharT)>
+struct __padding
+{
+    unsigned char __xx[sizeof(_CharT)-1];
+};
+
+template <class _CharT>
+struct __padding<_CharT, 1>
+{
+};
+
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+
 template<class _CharT, class _Traits, class _Allocator>
-class _LIBCPP_VISIBLE basic_string
+class _LIBCPP_TYPE_VIS basic_string
     : private __basic_string_common<true>
 {
 public:
@@ -1067,9 +1084,42 @@
     typedef _VSTD::reverse_iterator<const_iterator>       const_reverse_iterator;
 
 private:
+
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+
     struct __long
     {
+        pointer   __data_;
+        size_type __size_;
         size_type __cap_;
+    };
+
+#if _LIBCPP_BIG_ENDIAN
+    enum {__short_mask = 0x01};
+    enum {__long_mask  = 0x1ul};
+#else  // _LIBCPP_BIG_ENDIAN
+    enum {__short_mask = 0x80};
+    enum {__long_mask  = ~(size_type(~0) >> 1)};
+#endif  // _LIBCPP_BIG_ENDIAN
+
+    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
+                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
+
+    struct __short
+    {
+        value_type __data_[__min_cap];
+        struct
+            : __padding<value_type>
+        {
+            unsigned char __size_;
+        };
+    };
+
+#else
+
+    struct __long
+    {
+        size_type __cap_;
         size_type __size_;
         pointer   __data_;
     };
@@ -1082,8 +1132,6 @@
     enum {__long_mask  = 0x1ul};
 #endif  // _LIBCPP_BIG_ENDIAN
 
-    enum {__mask = size_type(~0) >> 1};
-
     enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
                       (sizeof(__long) - 1)/sizeof(value_type) : 2};
 
@@ -1092,15 +1140,17 @@
         union
         {
             unsigned char __size_;
-            value_type _;
+            value_type __lx;
         };
         value_type __data_[__min_cap];
     };
 
-    union _{__long _; __short __;};
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
 
-    enum {__n_words = sizeof(_) / sizeof(size_type)};
+    union __lx{__long __lx; __short __lxx;};
 
+    enum {__n_words = sizeof(__lx) / sizeof(size_type)};
+
     struct __raw
     {
         size_type __words[__n_words];
@@ -1142,13 +1192,13 @@
     _LIBCPP_INLINE_VISIBILITY
     basic_string(basic_string&& __str, const allocator_type& __a);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s);
+    _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
     _LIBCPP_INLINE_VISIBILITY
-    basic_string(const_pointer __s, const allocator_type& __a);
+    basic_string(const value_type* __s, const allocator_type& __a);
     _LIBCPP_INLINE_VISIBILITY
-    basic_string(const_pointer __s, size_type __n);
+    basic_string(const value_type* __s, size_type __n);
     _LIBCPP_INLINE_VISIBILITY
-    basic_string(const_pointer __s, size_type __n, const allocator_type& __a);
+    basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
     _LIBCPP_INLINE_VISIBILITY
     basic_string(size_type __n, value_type __c);
     _LIBCPP_INLINE_VISIBILITY
@@ -1177,7 +1227,7 @@
         _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
                    is_nothrow_move_assignable<allocator_type>::value);
 #endif
-    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);}
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
     basic_string& operator=(value_type __c);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
@@ -1190,13 +1240,13 @@
         {return iterator(__get_pointer());}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin() const _NOEXCEPT
-        {return const_iterator(data());}
+        {return const_iterator(__get_pointer());}
     _LIBCPP_INLINE_VISIBILITY
     iterator end() _NOEXCEPT
         {return iterator(__get_pointer() + size());}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator end() const _NOEXCEPT
-        {return const_iterator(data() + size());}
+        {return const_iterator(__get_pointer() + size());}
 #else  // _LIBCPP_DEBUG
     _LIBCPP_INLINE_VISIBILITY iterator       begin()       {return iterator(this, __get_pointer());}
     _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
@@ -1253,7 +1303,7 @@
     reference       at(size_type __n);
 
     _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
-    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s)         {return append(__s);}
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s)         {return append(__s);}
     _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c)            {push_back(__c); return *this;}
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
@@ -1262,8 +1312,8 @@
     _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_pointer __s, size_type __n);
-    basic_string& append(const_pointer __s);
+    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);
     template<class _InputIterator>
         typename enable_if
@@ -1301,8 +1351,8 @@
         {*this = _VSTD::move(str); return *this;}
 #endif
     basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
-    basic_string& assign(const_pointer __s, size_type __n);
-    basic_string& assign(const_pointer __s);
+    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);
     template<class _InputIterator>
         typename enable_if
@@ -1327,8 +1377,8 @@
     _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 __pos, const_pointer __s, size_type __n);
-    basic_string& insert(size_type __pos, const_pointer __s);
+    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);
     iterator      insert(const_iterator __pos, value_type __c);
     _LIBCPP_INLINE_VISIBILITY
@@ -1363,15 +1413,15 @@
     _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 __pos, size_type __n1, const_pointer __s, size_type __n2);
-    basic_string& replace(size_type __pos, size_type __n1, const_pointer __s);
+    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);
     _LIBCPP_INLINE_VISIBILITY
     basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
     _LIBCPP_INLINE_VISIBILITY
-    basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n);
+    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
     _LIBCPP_INLINE_VISIBILITY
-    basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s);
+    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
     _LIBCPP_INLINE_VISIBILITY
     basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
     template<class _InputIterator>
@@ -1387,7 +1437,7 @@
         {return replace(__i1, __i2, __il.begin(), __il.end());}
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-    size_type copy(pointer __s, size_type __n, size_type __pos = 0) const;
+    size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
     _LIBCPP_INLINE_VISIBILITY
     basic_string substr(size_type __pos = 0, size_type __n = npos) const;
 
@@ -1397,9 +1447,9 @@
                    __is_nothrow_swappable<allocator_type>::value);
 
     _LIBCPP_INLINE_VISIBILITY
-    const_pointer c_str() const _NOEXCEPT {return data();}
+    const value_type* c_str() const _NOEXCEPT {return data();}
     _LIBCPP_INLINE_VISIBILITY
-    const_pointer data() const _NOEXCEPT  {return __get_pointer();}
+    const value_type* data() const _NOEXCEPT  {return _VSTD::__to_raw_pointer(__get_pointer());}
 
     _LIBCPP_INLINE_VISIBILITY
     allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
@@ -1406,47 +1456,47 @@
 
     _LIBCPP_INLINE_VISIBILITY
     size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
-    size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
+    size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
     size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
-    size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
+    size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
     size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
-    size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
+    size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
-    size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
+    size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
-    size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
+    size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
-    size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
+    size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
-    size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
+    size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY
     size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
 
@@ -1455,11 +1505,16 @@
     _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(const_pointer __s) const _NOEXCEPT;
-    int compare(size_type __pos1, size_type __n1, const_pointer __s) const;
-    int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) 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;
 
     _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
+
+    _LIBCPP_INLINE_VISIBILITY
+    bool __is_long() const _NOEXCEPT
+        {return bool(__r_.first().__s.__size_ & __short_mask);}
+
 private:
     _LIBCPP_INLINE_VISIBILITY
     allocator_type& __alloc() _NOEXCEPT
@@ -1468,24 +1523,44 @@
     const allocator_type& __alloc() const _NOEXCEPT
         {return __r_.second();}
 
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+
     _LIBCPP_INLINE_VISIBILITY
-    bool __is_long() const _NOEXCEPT
-        {return bool(__r_.first().__s.__size_ & __short_mask);}
+    void __set_short_size(size_type __s) _NOEXCEPT
+#   if _LIBCPP_BIG_ENDIAN
+        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
+#   else
+        {__r_.first().__s.__size_ = (unsigned char)(__s);}
+#   endif
 
     _LIBCPP_INLINE_VISIBILITY
+    size_type __get_short_size() const _NOEXCEPT
+#   if _LIBCPP_BIG_ENDIAN
+        {return __r_.first().__s.__size_ >> 1;}
+#   else
+        {return __r_.first().__s.__size_;}
+#   endif
+
+#else  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+
+    _LIBCPP_INLINE_VISIBILITY
     void __set_short_size(size_type __s) _NOEXCEPT
-#if _LIBCPP_BIG_ENDIAN
+#   if _LIBCPP_BIG_ENDIAN
         {__r_.first().__s.__size_ = (unsigned char)(__s);}
-#else
+#   else
         {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
-#endif
+#   endif
+
     _LIBCPP_INLINE_VISIBILITY
     size_type __get_short_size() const _NOEXCEPT
-#if _LIBCPP_BIG_ENDIAN
+#   if _LIBCPP_BIG_ENDIAN
         {return __r_.first().__s.__size_;}
-#else
+#   else
         {return __r_.first().__s.__size_ >> 1;}
-#endif
+#   endif
+
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+
     _LIBCPP_INLINE_VISIBILITY
     void __set_long_size(size_type __s) _NOEXCEPT
         {__r_.first().__l.__size_ = __s;}
@@ -1514,10 +1589,10 @@
         {return __r_.first().__l.__data_;}
     _LIBCPP_INLINE_VISIBILITY
     pointer __get_short_pointer() _NOEXCEPT
-        {return __r_.first().__s.__data_;}
+        {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
     _LIBCPP_INLINE_VISIBILITY
     const_pointer __get_short_pointer() const _NOEXCEPT
-        {return __r_.first().__s.__data_;}
+        {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
     _LIBCPP_INLINE_VISIBILITY
     pointer __get_pointer() _NOEXCEPT
         {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
@@ -1544,8 +1619,8 @@
                  __align<sizeof(value_type) < __alignment ?
                             __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
 
-    void __init(const_pointer __s, size_type __sz, size_type __reserve);
-    void __init(const_pointer __s, size_type __sz);
+    void __init(const value_type* __s, size_type __sz, size_type __reserve);
+    void __init(const value_type* __s, size_type __sz);
     void __init(size_type __n, value_type __c);
 
     template <class _InputIterator>
@@ -1569,7 +1644,7 @@
                    size_type __n_copy,  size_type __n_del,     size_type __n_add = 0);
     void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
                                size_type __n_copy,  size_type __n_del,
-                               size_type __n_add, const_pointer __p_new_stuff);
+                               size_type __n_add, const value_type* __p_new_stuff);
 
     _LIBCPP_INLINE_VISIBILITY
     void __erase_to_end(size_type __pos);
@@ -1726,7 +1801,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 void
-basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve)
+basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
 {
     if (__reserve > max_size())
         this->__throw_length_error();
@@ -1744,13 +1819,13 @@
         __set_long_cap(__cap+1);
         __set_long_size(__sz);
     }
-    traits_type::copy(__p, __s, __sz);
+    traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
     traits_type::assign(__p[__sz], value_type());
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 void
-basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz)
+basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
 {
     if (__sz > max_size())
         this->__throw_length_error();
@@ -1768,13 +1843,13 @@
         __set_long_cap(__cap+1);
         __set_long_size(__sz);
     }
-    traits_type::copy(__p, __s, __sz);
+    traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
     traits_type::assign(__p[__sz], value_type());
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -1784,7 +1859,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a)
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
     : __r_(__a)
 {
 #ifdef _LIBCPP_DEBUG
@@ -1795,7 +1870,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n)
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -1805,7 +1880,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a)
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
     : __r_(__a)
 {
 #ifdef _LIBCPP_DEBUG
@@ -1821,7 +1896,7 @@
     if (!__str.__is_long())
         __r_.first().__r = __str.__r_.first().__r;
     else
-        __init(__str.__get_long_pointer(), __str.__get_long_size());
+        __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -1831,7 +1906,7 @@
     if (!__str.__is_long())
         __r_.first().__r = __str.__r_.first().__r;
     else
-        __init(__str.__get_long_pointer(), __str.__get_long_size());
+        __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
 }
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1856,7 +1931,7 @@
     if (__a == __str.__alloc() || !__str.__is_long())
         __r_.first().__r = __str.__r_.first().__r;
     else
-        __init(__str.__get_long_pointer(), __str.__get_long_size());
+        __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
     __str.__zero();
 #ifdef _LIBCPP_DEBUG
     __str.__invalidate_all_iterators();
@@ -1885,7 +1960,7 @@
         __set_long_cap(__cap+1);
         __set_long_size(__n);
     }
-    traits_type::assign(__p, __n, __c);
+    traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
     traits_type::assign(__p[__n], value_type());
 }
 
@@ -2023,7 +2098,7 @@
 void
 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
     (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
-     size_type __n_copy,  size_type __n_del,     size_type __n_add, const_pointer __p_new_stuff)
+     size_type __n_copy,  size_type __n_del,     size_type __n_add, const value_type* __p_new_stuff)
 {
     size_type __ms = max_size();
     if (__delta_cap > __ms - __old_cap - 1)
@@ -2035,12 +2110,14 @@
     pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
     __invalidate_all_iterators();
     if (__n_copy != 0)
-        traits_type::copy(__p, __old_p, __n_copy);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p),
+                          _VSTD::__to_raw_pointer(__old_p), __n_copy);
     if (__n_add != 0)
-        traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
     size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
     if (__sec_cp_sz != 0)
-        traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
+                          _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
     if (__old_cap+1 != __min_cap)
         __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
     __set_long_pointer(__p);
@@ -2065,10 +2142,13 @@
     pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
     __invalidate_all_iterators();
     if (__n_copy != 0)
-        traits_type::copy(__p, __old_p, __n_copy);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p),
+                          _VSTD::__to_raw_pointer(__old_p), __n_copy);
     size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
     if (__sec_cp_sz != 0)
-        traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
+                          _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
+                          __sec_cp_sz);
     if (__old_cap+1 != __min_cap)
         __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
     __set_long_pointer(__p);
@@ -2079,7 +2159,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n)
+basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2087,7 +2167,7 @@
     size_type __cap = capacity();
     if (__cap >= __n)
     {
-        pointer __p = __get_pointer();
+        value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
         traits_type::move(__p, __s, __n);
         traits_type::assign(__p[__n], value_type());
         __set_size(__n);
@@ -2113,7 +2193,7 @@
     }
     else
         __invalidate_iterators_past(__n);
-    pointer __p = __get_pointer();
+    value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
     traits_type::assign(__p, __n, __c);
     traits_type::assign(__p[__n], value_type());
     __set_size(__n);
@@ -2206,6 +2286,7 @@
     clear();
     for (; __first != __last; ++__first)
         push_back(*__first);
+    return *this;
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2254,7 +2335,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2266,7 +2347,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n)
+basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2277,7 +2358,7 @@
     {
         if (__n)
         {
-            pointer __p = __get_pointer();
+            value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
             traits_type::copy(__p + __sz, __s, __n);
             __sz += __n;
             __set_size(__sz);
@@ -2300,7 +2381,7 @@
         if (__cap - __sz < __n)
             __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
         pointer __p = __get_pointer();
-        traits_type::assign(__p + __sz, __n, __c);
+        traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
         __sz += __n;
         __set_size(__sz);
         traits_type::assign(__p[__sz], value_type());
@@ -2312,14 +2393,37 @@
 void
 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
 {
-    size_type __cap = capacity();
-    size_type __sz = size();
+    bool __is_short = !__is_long();
+    size_type __cap;
+    size_type __sz;
+    if (__is_short)
+    {
+        __cap = __min_cap - 1;
+        __sz = __get_short_size();
+    }
+    else
+    {
+        __cap = __get_long_cap() - 1;
+        __sz = __get_long_size();
+    }
     if (__sz == __cap)
+    {
         __grow_by(__cap, 1, __sz, __sz, 0);
-    pointer __p = __get_pointer() + __sz;
+        __is_short = !__is_long();
+    }
+    pointer __p;
+    if (__is_short)
+    {
+        __p = __get_short_pointer() + __sz;
+        __set_short_size(__sz+1);
+    }
+    else
+    {
+        __p = __get_long_pointer() + __sz;
+        __set_long_size(__sz+1);
+    }
     traits_type::assign(*__p, __c);
     traits_type::assign(*++__p, value_type());
-    __set_size(__sz+1);
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -2382,7 +2486,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2394,7 +2498,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n)
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2407,7 +2511,7 @@
     {
         if (__n)
         {
-            pointer __p = __get_pointer();
+            value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
             size_type __n_move = __sz - __pos;
             if (__n_move != 0)
             {
@@ -2436,10 +2540,10 @@
     if (__n)
     {
         size_type __cap = capacity();
-        pointer __p;
+        value_type* __p;
         if (__cap - __sz >= __n)
         {
-            __p = __get_pointer();
+            __p = _VSTD::__to_raw_pointer(__get_pointer());
             size_type __n_move = __sz - __pos;
             if (__n_move != 0)
                 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
@@ -2447,7 +2551,7 @@
         else
         {
             __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
-            __p = __get_long_pointer();
+            __p = _VSTD::__to_raw_pointer(__get_long_pointer());
         }
         traits_type::assign(__p + __pos, __n, __c);
         __sz += __n;
@@ -2491,10 +2595,10 @@
     size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
     if (__n)
     {
-        pointer __p;
+        value_type* __p;
         if (__cap - __sz >= __n)
         {
-            __p = __get_pointer();
+            __p = _VSTD::__to_raw_pointer(__get_pointer());
             size_type __n_move = __sz - __ip;
             if (__n_move != 0)
                 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
@@ -2502,7 +2606,7 @@
         else
         {
             __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
-            __p = __get_long_pointer();
+            __p = _VSTD::__to_raw_pointer(__get_long_pointer());
         }
         __sz += __n;
         __set_size(__sz);
@@ -2534,7 +2638,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2549,15 +2653,15 @@
     size_type __ip = static_cast<size_type>(__pos - begin());
     size_type __sz = size();
     size_type __cap = capacity();
-    pointer __p;
+    value_type* __p;
     if (__cap == __sz)
     {
         __grow_by(__cap, 1, __sz, __ip, 0, 1);
-        __p = __get_long_pointer();
+        __p = _VSTD::__to_raw_pointer(__get_long_pointer());
     }
     else
     {
-        __p = __get_pointer();
+        __p = _VSTD::__to_raw_pointer(__get_pointer());
         size_type __n_move = __sz - __ip;
         if (__n_move != 0)
             traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
@@ -2582,7 +2686,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_pointer __s, size_type __n2)
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2594,7 +2698,7 @@
     size_type __cap = capacity();
     if (__cap - __sz + __n1 >= __n2)
     {
-        pointer __p = __get_pointer();
+        value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
         if (__n1 != __n2)
         {
             size_type __n_move = __sz - __pos - __n1;
@@ -2643,10 +2747,10 @@
         this->__throw_out_of_range();
     __n1 = _VSTD::min(__n1, __sz - __pos);
     size_type __cap = capacity();
-    pointer __p;
+    value_type* __p;
     if (__cap - __sz + __n1 >= __n2)
     {
-        __p = __get_pointer();
+        __p = _VSTD::__to_raw_pointer(__get_pointer());
         if (__n1 != __n2)
         {
             size_type __n_move = __sz - __pos - __n1;
@@ -2657,7 +2761,7 @@
     else
     {
         __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
-        __p = __get_long_pointer();
+        __p = _VSTD::__to_raw_pointer(__get_long_pointer());
     }
     traits_type::assign(__p + __pos, __n2, __c);
     __sz += __n2 - __n1;
@@ -2716,7 +2820,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_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -2736,7 +2840,7 @@
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n)
+basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
 {
     return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
 }
@@ -2744,7 +2848,7 @@
 template <class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 basic_string<_CharT, _Traits, _Allocator>&
-basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s)
+basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
 {
     return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
 }
@@ -2768,7 +2872,7 @@
         this->__throw_out_of_range();
     if (__n)
     {
-        pointer __p = __get_pointer();
+        value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
         __n = _VSTD::min(__n, __sz - __pos);
         size_type __n_move = __sz - __pos - __n;
         if (__n_move != 0)
@@ -2926,7 +3030,7 @@
                     return;
                 }
             #else  // _LIBCPP_NO_EXCEPTIONS
-                if (__new_data == 0)
+                if (__new_data == nullptr)
                     return;
             #endif  // _LIBCPP_NO_EXCEPTIONS
             }
@@ -2934,7 +3038,8 @@
             __was_long = __is_long();
             __p = __get_pointer();
         }
-        traits_type::copy(__new_data, __p, size()+1);
+        traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
+                          _VSTD::__to_raw_pointer(__p), size()+1);
         if (__was_long)
             __alloc_traits::deallocate(__alloc(), __p, __cap+1);
         if (__now_long)
@@ -3035,7 +3140,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const
+basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
 {
     size_type __sz = size();
     if (__pos > __sz)
@@ -3081,7 +3186,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
                                                 size_type __pos,
                                                 size_type __n) const _NOEXCEPT
 {
@@ -3093,8 +3198,8 @@
         return npos;
     if (__n == 0)
         return __pos;
-    const_pointer __p = data();
-    const_pointer __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
+    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;
@@ -3113,7 +3218,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
                                                 size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3130,8 +3235,8 @@
     size_type __sz = size();
     if (__pos >= __sz)
         return npos;
-    const_pointer __p = data();
-    const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c);
+    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);
@@ -3141,7 +3246,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
                                                  size_type __pos,
                                                  size_type __n) const _NOEXCEPT
 {
@@ -3154,8 +3259,8 @@
         __pos += __n;
     else
         __pos = __sz;
-    const_pointer __p = data();
-    const_pointer __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
+    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;
@@ -3174,7 +3279,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
                                                  size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3195,8 +3300,8 @@
             ++__pos;
         else
             __pos = __sz;
-        const_pointer __p = data();
-        for (const_pointer __ps = __p + __pos; __ps != __p;)
+        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);
@@ -3209,7 +3314,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
                                                          size_type __pos,
                                                          size_type __n) const _NOEXCEPT
 {
@@ -3219,8 +3324,8 @@
     size_type __sz = size();
     if (__pos >= __sz || __n == 0)
         return npos;
-    const_pointer __p = data();
-    const_pointer __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
+    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;
@@ -3239,7 +3344,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
                                                          size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3261,7 +3366,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
                                                         size_type __pos,
                                                         size_type __n) const _NOEXCEPT
 {
@@ -3275,10 +3380,10 @@
             ++__pos;
         else
             __pos = __sz;
-        const_pointer __p = data();
-        for (const_pointer __ps = __p + __pos; __ps != __p;)
+        const value_type* __p = data();
+        for (const value_type* __ps = __p + __pos; __ps != __p;)
         {
-            const_pointer __r = traits_type::find(__s, __n, *--__ps);
+            const value_type* __r = traits_type::find(__s, __n, *--__ps);
             if (__r)
                 return static_cast<size_type>(__ps - __p);
         }
@@ -3298,7 +3403,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
                                                         size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3320,7 +3425,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
                                                              size_type __pos,
                                                              size_type __n) const _NOEXCEPT
 {
@@ -3330,9 +3435,9 @@
     size_type __sz = size();
     if (__pos < __sz)
     {
-        const_pointer __p = data();
-        const_pointer __pe = __p + __sz;
-        for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
+        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);
     }
@@ -3351,7 +3456,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
                                                              size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3369,9 +3474,9 @@
     size_type __sz = size();
     if (__pos < __sz)
     {
-        const_pointer __p = data();
-        const_pointer __pe = __p + __sz;
-        for (const_pointer __ps = __p + __pos; __p != __pe; ++__ps)
+        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);
     }
@@ -3382,7 +3487,7 @@
 
 template<class _CharT, class _Traits, class _Allocator>
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
                                                             size_type __pos,
                                                             size_type __n) const _NOEXCEPT
 {
@@ -3394,8 +3499,8 @@
         ++__pos;
     else
         __pos = __sz;
-    const_pointer __p = data();
-    for (const_pointer __ps = __p + __pos; __ps != __p;)
+    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;
@@ -3413,7 +3518,7 @@
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 typename basic_string<_CharT, _Traits, _Allocator>::size_type
-basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
                                                             size_type __pos) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
@@ -3433,8 +3538,8 @@
         ++__pos;
     else
         __pos = __sz;
-    const_pointer __p = data();
-    for (const_pointer __ps = __p + __pos; __ps != __p;)
+    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;
@@ -3487,7 +3592,7 @@
 
 template <class _CharT, class _Traits, class _Allocator>
 int
-basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT
+basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -3499,7 +3604,7 @@
 int
 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
                                                    size_type __n1,
-                                                   const_pointer __s) const
+                                                   const value_type* __s) const
 {
 #ifdef _LIBCPP_DEBUG
     assert(__s != 0);
@@ -3511,7 +3616,7 @@
 int
 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
                                                    size_type __n1,
-                                                   const_pointer __s,
+                                                   const value_type* __s,
                                                    size_type __n2) const
 {
 #ifdef _LIBCPP_DEBUG
@@ -3558,11 +3663,31 @@
 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
            const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
 {
-    return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(),
-                                                            __rhs.data(),
-                                                            __lhs.size()) == 0;
+    size_t __lhs_sz = __lhs.size();
+    return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
+                                                        __rhs.data(),
+                                                        __lhs_sz) == 0;
 }
 
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
+           const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
+{
+    size_t __lhs_sz = __lhs.size();
+    if (__lhs_sz != __rhs.size())
+        return false;
+    const char* __lp = __lhs.data();
+    const char* __rp = __rhs.data();
+    if (__lhs.__is_long())
+        return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
+    for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
+        if (*__lp != *__rp)
+            return false;
+    return true;
+}
+
 template<class _CharT, class _Traits, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 bool
@@ -3920,7 +4045,7 @@
 }
 
 template<class _CharT, class _Traits, class _Allocator>
-struct _LIBCPP_VISIBLE hash<basic_string<_CharT, _Traits, _Allocator> >
+struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
     : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
 {
     size_t
@@ -3972,8 +4097,8 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-extern template class basic_string<char>;
-extern template class basic_string<wchar_t>;
+_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
+_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
 
 extern template
     string

Modified: trunk/contrib/libc++/include/strstream
===================================================================
--- trunk/contrib/libc++/include/strstream	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/strstream	2016-01-07 17:22:14 UTC (rev 7405)
@@ -137,7 +137,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_VISIBLE strstreambuf
+class _LIBCPP_TYPE_VIS strstreambuf
     : public streambuf
 {
 public:
@@ -228,7 +228,7 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-class _LIBCPP_VISIBLE istrstream
+class _LIBCPP_TYPE_VIS istrstream
     : public istream
 {
 public:
@@ -281,7 +281,7 @@
     strstreambuf __sb_;
 };
 
-class _LIBCPP_VISIBLE ostrstream
+class _LIBCPP_TYPE_VIS ostrstream
     : public ostream
 {
 public:
@@ -334,7 +334,7 @@
     strstreambuf __sb_; // exposition only
 };
 
-class _LIBCPP_VISIBLE strstream
+class _LIBCPP_TYPE_VIS strstream
     : public iostream
 {
 public:

Modified: trunk/contrib/libc++/include/system_error
===================================================================
--- trunk/contrib/libc++/include/system_error	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/system_error	2016-01-07 17:22:14 UTC (rev 7405)
@@ -232,13 +232,13 @@
 // is_error_code_enum
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_error_code_enum
+struct _LIBCPP_TYPE_VIS is_error_code_enum
     : public false_type {};
 
 // is_error_condition_enum
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_error_condition_enum
+struct _LIBCPP_TYPE_VIS is_error_condition_enum
     : public false_type {};
 
 // Some error codes are not present on all platforms, so we provide equivalents
@@ -345,23 +345,23 @@
 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc)
 
 template <>
-struct _LIBCPP_VISIBLE is_error_condition_enum<errc>
+struct _LIBCPP_TYPE_VIS is_error_condition_enum<errc>
     : true_type { };
 
 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
 template <>
-struct _LIBCPP_VISIBLE is_error_condition_enum<errc::_>
+struct _LIBCPP_TYPE_VIS is_error_condition_enum<errc::__lx>
     : true_type { };
 #endif
 
-class error_condition;
-class error_code;
+class _LIBCPP_TYPE_VIS error_condition;
+class _LIBCPP_TYPE_VIS error_code;
 
 // class error_category
 
-class __do_message;
+class _LIBCPP_HIDDEN __do_message;
 
-class _LIBCPP_VISIBLE error_category
+class _LIBCPP_TYPE_VIS error_category
 {
 public:
     virtual ~error_category() _NOEXCEPT;
@@ -387,7 +387,7 @@
     _LIBCPP_ALWAYS_INLINE
     bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
 
-    friend class __do_message;
+    friend class _LIBCPP_HIDDEN __do_message;
 };
 
 class _LIBCPP_HIDDEN __do_message
@@ -400,7 +400,7 @@
 const error_category& generic_category() _NOEXCEPT;
 const error_category& system_category() _NOEXCEPT;
 
-class _LIBCPP_VISIBLE error_condition
+class _LIBCPP_TYPE_VIS error_condition
 {
     int __val_;
     const error_category* __cat_;
@@ -472,7 +472,7 @@
 
 // error_code
 
-class _LIBCPP_VISIBLE error_code
+class _LIBCPP_TYPE_VIS error_code
 {
     int __val_;
     const error_category* __cat_;
@@ -597,7 +597,7 @@
 {return !(__x == __y);}
 
 template <>
-struct _LIBCPP_VISIBLE hash<error_code>
+struct _LIBCPP_TYPE_VIS hash<error_code>
     : public unary_function<error_code, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -609,7 +609,7 @@
 
 // system_error
 
-class _LIBCPP_VISIBLE system_error
+class _LIBCPP_TYPE_VIS system_error
     : public runtime_error
 {
     error_code __ec_;

Modified: trunk/contrib/libc++/include/thread
===================================================================
--- trunk/contrib/libc++/include/thread	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/thread	2016-01-07 17:22:14 UTC (rev 7405)
@@ -26,41 +26,41 @@
     class id;
     typedef pthread_t native_handle_type;
 
-    thread();
+    thread() noexcept;
     template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
     ~thread();
 
     thread(const thread&) = delete;
-    thread(thread&& t);
+    thread(thread&& t) noexcept;
 
     thread& operator=(const thread&) = delete;
-    thread& operator=(thread&& t);
+    thread& operator=(thread&& t) noexcept;
 
-    void swap(thread& t);
+    void swap(thread& t) noexcept;
 
-    bool joinable() const;
+    bool joinable() const noexcept;
     void join();
     void detach();
-    id get_id() const;
+    id get_id() const noexcept;
     native_handle_type native_handle();
 
-    static unsigned hardware_concurrency();
+    static unsigned hardware_concurrency() noexcept;
 };
 
-void swap(thread& x, thread& y);
+void swap(thread& x, thread& y) noexcept;
 
 class thread::id
 {
 public:
-    id();
+    id() noexcept;
 };
 
-bool operator==(thread::id x, thread::id y);
-bool operator!=(thread::id x, thread::id y);
-bool operator< (thread::id x, thread::id y);
-bool operator<=(thread::id x, thread::id y);
-bool operator> (thread::id x, thread::id y);
-bool operator>=(thread::id x, thread::id y);
+bool operator==(thread::id x, thread::id y) noexcept;
+bool operator!=(thread::id x, thread::id y) noexcept;
+bool operator< (thread::id x, thread::id y) noexcept;
+bool operator<=(thread::id x, thread::id y) noexcept;
+bool operator> (thread::id x, thread::id y) noexcept;
+bool operator>=(thread::id x, thread::id y) noexcept;
 
 template<class charT, class traits>
 basic_ostream<charT, traits>&
@@ -69,9 +69,9 @@
 namespace this_thread
 {
 
-thread::id get_id();
+thread::id get_id() noexcept;
 
-void yield();
+void yield() noexcept;
 
 template <class Clock, class Duration>
 void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
@@ -144,9 +144,11 @@
 __thread_specific_ptr<_Tp>::__thread_specific_ptr()
 {
     int __ec = pthread_key_create(&__key_, &__thread_specific_ptr::__at_thread_exit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__ec)
         throw system_error(error_code(__ec, system_category()),
                            "__thread_specific_ptr construction failed");
+#endif
 }
 
 template <class _Tp>
@@ -173,20 +175,20 @@
     delete __p_old;
 }
 
-class thread;
-class __thread_id;
+class _LIBCPP_TYPE_VIS thread;
+class _LIBCPP_TYPE_VIS __thread_id;
 
 namespace this_thread
 {
 
-__thread_id get_id();
+_LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
 
 }  // this_thread
 
-class _LIBCPP_VISIBLE __thread_id;
-template<> struct _LIBCPP_VISIBLE hash<__thread_id>;
+class _LIBCPP_TYPE_VIS __thread_id;
+template<> struct _LIBCPP_TYPE_VIS hash<__thread_id>;
 
-class _LIBCPP_VISIBLE __thread_id
+class _LIBCPP_TYPE_VIS __thread_id
 {
     // FIXME: pthread_t is a pointer on Darwin but a long on Linux.
     // NULL is the no-thread value on Darwin.  Someone needs to check
@@ -195,25 +197,25 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    __thread_id() : __id_(0) {}
+    __thread_id() _NOEXCEPT : __id_(0) {}
 
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator==(__thread_id __x, __thread_id __y)
+        bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return __x.__id_ == __y.__id_;}
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator!=(__thread_id __x, __thread_id __y)
+        bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return !(__x == __y);}
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator< (__thread_id __x, __thread_id __y)
+        bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
         {return __x.__id_ < __y.__id_;}
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator<=(__thread_id __x, __thread_id __y)
+        bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return !(__y < __x);}
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator> (__thread_id __x, __thread_id __y)
+        bool operator> (__thread_id __x, __thread_id __y) _NOEXCEPT
         {return   __y < __x ;}
     friend _LIBCPP_INLINE_VISIBILITY
-        bool operator>=(__thread_id __x, __thread_id __y)
+        bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return !(__x < __y);}
 
     template<class _CharT, class _Traits>
@@ -227,13 +229,13 @@
     _LIBCPP_INLINE_VISIBILITY
     __thread_id(pthread_t __id) : __id_(__id) {}
 
-    friend __thread_id this_thread::get_id();
-    friend class _LIBCPP_VISIBLE thread;
-    friend struct _LIBCPP_VISIBLE hash<__thread_id>;
+    friend __thread_id this_thread::get_id() _NOEXCEPT;
+    friend class _LIBCPP_TYPE_VIS thread;
+    friend struct _LIBCPP_TYPE_VIS hash<__thread_id>;
 };
 
 template<>
-struct _LIBCPP_VISIBLE hash<__thread_id>
+struct _LIBCPP_TYPE_VIS hash<__thread_id>
     : public unary_function<__thread_id, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY
@@ -248,7 +250,7 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 __thread_id
-get_id()
+get_id() _NOEXCEPT
 {
     return pthread_self();
 }
@@ -255,7 +257,7 @@
 
 }  // this_thread
 
-class _LIBCPP_VISIBLE thread
+class _LIBCPP_TYPE_VIS thread
 {
     pthread_t __t_;
 
@@ -266,7 +268,7 @@
     typedef pthread_t native_handle_type;
 
     _LIBCPP_INLINE_VISIBILITY
-    thread() : __t_(0) {}
+    thread() _NOEXCEPT : __t_(0) {}
 #ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class _Fp, class ..._Args,
               class = typename enable_if
@@ -282,23 +284,23 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    thread(thread&& __t) : __t_(__t.__t_) {__t.__t_ = 0;}
-    thread& operator=(thread&& __t);
+    thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = 0;}
+    thread& operator=(thread&& __t) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(thread& __t) {_VSTD::swap(__t_, __t.__t_);}
+    void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
 
     _LIBCPP_INLINE_VISIBILITY
-    bool joinable() const {return __t_ != 0;}
+    bool joinable() const _NOEXCEPT {return __t_ != 0;}
     void join();
     void detach();
     _LIBCPP_INLINE_VISIBILITY
-    id get_id() const {return __t_;}
+    id get_id() const _NOEXCEPT {return __t_;}
     _LIBCPP_INLINE_VISIBILITY
-    native_handle_type native_handle() {return __t_;}
+    native_handle_type native_handle() _NOEXCEPT {return __t_;}
 
-    static unsigned hardware_concurrency();
+    static unsigned hardware_concurrency() _NOEXCEPT;
 };
 
 class __assoc_sub_state;
@@ -326,7 +328,7 @@
 template <class _Fp, class ..._Args, size_t ..._Indices>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-__threaad_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>)
+__thread_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>)
 {
     __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
 }
@@ -338,7 +340,7 @@
     __thread_local_data().reset(new __thread_struct);
     std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
     typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
-    __threaad_execute(*__p, _Index());
+    __thread_execute(*__p, _Index());
     return nullptr;
 }
 
@@ -386,7 +388,7 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 thread&
-thread::operator=(thread&& __t)
+thread::operator=(thread&& __t) _NOEXCEPT
 {
     if (__t_ != 0)
         terminate();
@@ -398,7 +400,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 inline _LIBCPP_INLINE_VISIBILITY
-void swap(thread& __x, thread& __y) {__x.swap(__y);}
+void swap(thread& __x, thread& __y) _NOEXCEPT {__x.swap(__y);}
 
 namespace this_thread
 {
@@ -410,10 +412,20 @@
 sleep_for(const chrono::duration<_Rep, _Period>& __d)
 {
     using namespace chrono;
-    nanoseconds __ns = duration_cast<nanoseconds>(__d);
-    if (__ns < __d)
-        ++__ns;
-    sleep_for(__ns);
+    if (__d > duration<_Rep, _Period>::zero())
+    {
+        _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max();
+        nanoseconds __ns;
+        if (__d < _Max)
+        {
+            __ns = duration_cast<nanoseconds>(__d);
+            if (__ns < __d)
+                ++__ns;
+        }
+        else
+            __ns = nanoseconds::max();
+        sleep_for(__ns);
+    }
 }
 
 template <class _Clock, class _Duration>
@@ -438,7 +450,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-void yield() {sched_yield();}
+void yield() _NOEXCEPT {sched_yield();}
 
 }  // this_thread
 

Modified: trunk/contrib/libc++/include/tuple
===================================================================
--- trunk/contrib/libc++/include/tuple	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/tuple	2016-01-07 17:22:14 UTC (rev 7405)
@@ -128,9 +128,13 @@
 
 // allocator_arg_t
 
-struct _LIBCPP_VISIBLE allocator_arg_t { };
+struct _LIBCPP_TYPE_VIS allocator_arg_t { };
 
+#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
 extern const allocator_arg_t allocator_arg;
+#else
+constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+#endif
 
 // uses_allocator
 
@@ -138,7 +142,7 @@
 struct __has_allocator_type
 {
 private:
-    struct __two {char _; char __;};
+    struct __two {char __lx; char __lxx;};
     template <class _Up> static __two __test(...);
     template <class _Up> static char __test(typename _Up::allocator_type* = 0);
 public:
@@ -159,7 +163,7 @@
 };
 
 template <class _Tp, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator
+struct _LIBCPP_TYPE_VIS uses_allocator
     : public __uses_allocator<_Tp, _Alloc>
 {
 };
@@ -189,7 +193,7 @@
 // tuple_size
 
 template <class ..._Tp>
-class _LIBCPP_VISIBLE tuple_size<tuple<_Tp...> >
+class _LIBCPP_TYPE_VIS tuple_size<tuple<_Tp...> >
     : public integral_constant<size_t, sizeof...(_Tp)>
 {
 };
@@ -197,7 +201,7 @@
 // tuple_element
 
 template <size_t _Ip, class ..._Tp>
-class _LIBCPP_VISIBLE tuple_element<_Ip, tuple<_Tp...> >
+class _LIBCPP_TYPE_VIS tuple_element<_Ip, tuple<_Tp...> >
 {
 public:
     typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
@@ -227,7 +231,8 @@
 
     __tuple_leaf& operator=(const __tuple_leaf&);
 public:
-    _LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value()
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
+             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
        {static_assert(!is_reference<_Hp>::value,
               "Attempted to default construct a reference element in a tuple");}
 
@@ -255,7 +260,7 @@
     template <class _Tp,
               class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
-        explicit __tuple_leaf(_Tp&& __t)
+        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
             : value(_VSTD::forward<_Tp>(__t))
         {static_assert(!is_reference<_Hp>::value ||
                        (is_lvalue_reference<_Hp>::value &&
@@ -311,7 +316,7 @@
                                 >::value)),
        "Attempted to construct a reference element in a tuple with an rvalue");}
 
-    __tuple_leaf(const __tuple_leaf& __t)
+    __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");}
 
@@ -318,12 +323,13 @@
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
+                           _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value))
             : value(__t.get()) {}
 
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         __tuple_leaf&
-        operator=(_Tp&& __t)
+        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
         {
             value = _VSTD::forward<_Tp>(__t);
             return *this;
@@ -336,8 +342,8 @@
         return 0;
     }
 
-    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       {return value;}
-    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;}
+    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       _NOEXCEPT {return value;}
+    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return value;}
 };
 
 template <size_t _Ip, class _Hp>
@@ -347,7 +353,8 @@
 
     __tuple_leaf& operator=(const __tuple_leaf&);
 public:
-    _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
+             _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
 
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
@@ -366,7 +373,7 @@
     template <class _Tp,
               class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
-        explicit __tuple_leaf(_Tp&& __t)
+        explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
             : _Hp(_VSTD::forward<_Tp>(__t)) {}
 
     template <class _Tp, class _Alloc>
@@ -387,12 +394,13 @@
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
+            _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value))
             : _Hp(__t.get()) {}
 
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         __tuple_leaf&
-        operator=(_Tp&& __t)
+        operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
         {
             _Hp::operator=(_VSTD::forward<_Tp>(__t));
             return *this;
@@ -406,13 +414,13 @@
         return 0;
     }
 
-    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       {return static_cast<_Hp&>(*this);}
-    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);}
+    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       _NOEXCEPT {return static_cast<_Hp&>(*this);}
+    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
 };
 
 template <class ..._Tp>
 _LIBCPP_INLINE_VISIBILITY
-void __swallow(_Tp&&...) {}
+void __swallow(_Tp&&...) _NOEXCEPT {}
 
 template <bool ...> struct __all;
 
@@ -436,6 +444,10 @@
 struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
     : public __tuple_leaf<_Indx, _Tp>...
 {
+    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR __tuple_impl()
+        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
+
     template <size_t ..._Uf, class ..._Tf,
               size_t ..._Ul, class ..._Tl, class ..._Up>
         _LIBCPP_INLINE_VISIBILITY
@@ -442,7 +454,9 @@
         explicit
         __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
                      __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
-                     _Up&&... __u) :
+                     _Up&&... __u)
+                     _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
+                                 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
             __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
             __tuple_leaf<_Ul, _Tl>()...
             {}
@@ -463,11 +477,12 @@
     template <class _Tuple,
               class = typename enable_if
                       <
-                         __tuple_convertible<_Tuple, tuple<_Tp...> >::value
+                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
                       >::type
              >
         _LIBCPP_INLINE_VISIBILITY
-        __tuple_impl(_Tuple&& __t)
+        __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
             : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
                                        typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
             {}
@@ -493,7 +508,8 @@
             __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
             __tuple_impl&
         >::type
-        operator=(_Tuple&& __t)
+        operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
         {
             __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
                                        typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
@@ -502,7 +518,7 @@
 
         _LIBCPP_INLINE_VISIBILITY
         __tuple_impl&
-        operator=(const __tuple_impl& __t)
+        operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
         {
             __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
             return *this;
@@ -517,7 +533,7 @@
 };
 
 template <class ..._Tp>
-class _LIBCPP_VISIBLE tuple
+class _LIBCPP_TYPE_VIS tuple
 {
     typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
 
@@ -532,7 +548,11 @@
 public:
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit tuple(const _Tp& ... __t)
+    _LIBCPP_CONSTEXPR tuple()
+        _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) 
         : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
                 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
                 typename __make_tuple_indices<0>::type(),
@@ -568,6 +588,15 @@
              >
         _LIBCPP_INLINE_VISIBILITY
         tuple(_Up&&... __u)
+            _NOEXCEPT_((
+                is_nothrow_constructible<
+                    typename __make_tuple_indices<sizeof...(_Up)>::type,
+                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
+                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
+                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
+                    _Up...
+                >::value
+            ))
             : 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(),
@@ -600,6 +629,15 @@
         _LIBCPP_INLINE_VISIBILITY
         explicit
         tuple(_Up&&... __u)
+            _NOEXCEPT_((
+                is_nothrow_constructible<
+                    typename __make_tuple_indices<sizeof...(_Up)>::type,
+                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
+                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
+                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
+                    _Up...
+                >::value
+            ))
             : 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(),
@@ -637,7 +675,7 @@
                       >::type = false
              >
         _LIBCPP_INLINE_VISIBILITY
-        tuple(_Tuple&& __t)
+        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
             : base_(_VSTD::forward<_Tuple>(__t)) {}
 
     template <class _Tuple,
@@ -650,7 +688,7 @@
              >
         _LIBCPP_INLINE_VISIBILITY
         explicit
-        tuple(_Tuple&& __t)
+        tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
             : base_(_VSTD::forward<_Tuple>(__t)) {}
 
     template <class _Alloc, class _Tuple,
@@ -671,7 +709,7 @@
              >
         _LIBCPP_INLINE_VISIBILITY
         tuple&
-        operator=(_Tuple&& __t)
+        operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
         {
             base_.operator=(_VSTD::forward<_Tuple>(__t));
             return *this;
@@ -683,23 +721,23 @@
 };
 
 template <>
-class _LIBCPP_VISIBLE tuple<>
+class _LIBCPP_TYPE_VIS tuple<>
 {
 public:
     _LIBCPP_INLINE_VISIBILITY
-    tuple() {}
+    _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
     template <class _Alloc>
     _LIBCPP_INLINE_VISIBILITY
-        tuple(allocator_arg_t, const _Alloc&) {}
+        tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
     template <class _Alloc>
     _LIBCPP_INLINE_VISIBILITY
-        tuple(allocator_arg_t, const _Alloc&, const tuple&) {}
+        tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
     template <class _Up>
     _LIBCPP_INLINE_VISIBILITY
-        tuple(array<_Up, 0>) {}
+        tuple(array<_Up, 0>) _NOEXCEPT {}
     template <class _Alloc, class _Up>
     _LIBCPP_INLINE_VISIBILITY
-        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) {}
+        tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
     _LIBCPP_INLINE_VISIBILITY
     void swap(tuple&) _NOEXCEPT {}
 };
@@ -750,7 +788,7 @@
 template <class ..._Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 tuple<_Tp&...>
-tie(_Tp&... __t)
+tie(_Tp&... __t) _NOEXCEPT
 {
     return tuple<_Tp&...>(__t...);
 }
@@ -765,7 +803,7 @@
 
 namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
 
-template <class _Tp> class reference_wrapper;
+template <class _Tp> class _LIBCPP_TYPE_VIS reference_wrapper;
 
 template <class _Tp>
 struct ___make_tuple_return
@@ -796,7 +834,7 @@
 template <class... _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 tuple<_Tp&&...>
-forward_as_tuple(_Tp&&... __t)
+forward_as_tuple(_Tp&&... __t) _NOEXCEPT
 {
     return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
 }
@@ -1033,7 +1071,7 @@
 }
 
 template <class ..._Tp, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator<tuple<_Tp...>, _Alloc>
+struct _LIBCPP_TYPE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
     : true_type {};
 
 template <class _T1, class _T2>

Modified: trunk/contrib/libc++/include/type_traits
===================================================================
--- trunk/contrib/libc++/include/type_traits	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/type_traits	2016-01-07 17:22:14 UTC (rev 7405)
@@ -129,6 +129,7 @@
     template <class T> struct alignment_of;
     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
         struct aligned_storage;
+    template <size_t Len, class... Types> struct aligned_union;
 
     template <class T> struct decay;
     template <class... T> struct common_type;
@@ -136,6 +137,64 @@
     template <class> class result_of; // undefined
     template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
 
+    // const-volatile modifications:
+    template <class T>
+      using remove_const_t    = typename remove_const<T>::type;  // C++14
+    template <class T>
+      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
+    template <class T>
+      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
+    template <class T>
+      using add_const_t       = typename add_const<T>::type;  // C++14
+    template <class T>
+      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
+    template <class T>
+      using add_cv_t          = typename add_cv<T>::type;  // C++14
+  
+    // reference modifications:
+    template <class T>
+      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
+    template <class T>
+      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
+    template <class T>
+      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
+  
+    // sign modifications:
+    template <class T>
+      using make_signed_t   = typename make_signed<T>::type;  // C++14
+    template <class T>
+      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
+  
+    // array modifications:
+    template <class T>
+      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
+    template <class T>
+      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
+
+    // pointer modifications:
+    template <class T>
+      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
+    template <class T>
+      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
+
+    // other transformations:
+    template <size_t Len, std::size_t Align=default-alignment>
+      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
+    template <std::size_t Len, class... Types>
+      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
+    template <class T>
+      using decay_t           = typename decay<T>::type;  // C++14
+    template <bool b, class T=void>
+      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
+    template <bool b, class T, class F>
+      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
+    template <class... T>
+      using common_type_t     = typename common_type<T...>::type;  // C++14
+    template <class T>
+      using underlying_type_t = typename underlying_type<T>::type;  // C++14
+    template <class F, class... ArgTypes>
+      using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
+
 }  // std
 
 */
@@ -149,19 +208,28 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <bool _Bp, class _If, class _Then>
-    struct _LIBCPP_VISIBLE conditional {typedef _If type;};
+    struct _LIBCPP_TYPE_VIS conditional {typedef _If type;};
 template <class _If, class _Then>
-    struct _LIBCPP_VISIBLE conditional<false, _If, _Then> {typedef _Then type;};
+    struct _LIBCPP_TYPE_VIS conditional<false, _If, _Then> {typedef _Then type;};
 
-template <bool, class _Tp = void> struct _LIBCPP_VISIBLE enable_if {};
-template <class _Tp> struct _LIBCPP_VISIBLE enable_if<true, _Tp> {typedef _Tp type;};
+#if _LIBCPP_STD_VER > 11
+template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
+#endif
 
-struct __two {char _[2];};
+template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS enable_if {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS enable_if<true, _Tp> {typedef _Tp type;};
 
+#if _LIBCPP_STD_VER > 11
+template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
+#endif
+
+
+struct __two {char __lx[2];};
+
 // helper class:
 
 template <class _Tp, _Tp __v>
-struct _LIBCPP_VISIBLE integral_constant
+struct _LIBCPP_TYPE_VIS integral_constant
 {
     static _LIBCPP_CONSTEXPR const _Tp      value = __v;
     typedef _Tp               value_type;
@@ -178,28 +246,37 @@
 
 // is_const
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_const            : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_const<_Tp const> : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_const            : public false_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_const<_Tp const> : public true_type {};
 
 // is_volatile
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_volatile               : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_volatile<_Tp volatile> : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_volatile               : public false_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_volatile<_Tp volatile> : public true_type {};
 
 // remove_const
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_const            {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_const<const _Tp> {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const            {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const<const _Tp> {typedef _Tp type;};
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
+#endif
 
 // remove_volatile
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile               {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_volatile<volatile _Tp> {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile               {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
+#endif
 
 // remove_cv
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_cv
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_cv
 {typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
+#endif
 
 // is_void
 
@@ -206,7 +283,7 @@
 template <class _Tp> struct __is_void       : public false_type {};
 template <>          struct __is_void<void> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_void
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_void
     : public __is_void<typename remove_cv<_Tp>::type> {};
 
 // __is_nullptr_t
@@ -214,7 +291,7 @@
 template <class _Tp> struct ____is_nullptr_t       : public false_type {};
 template <>          struct ____is_nullptr_t<nullptr_t> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE __is_nullptr_t
+template <class _Tp> struct _LIBCPP_TYPE_VIS __is_nullptr_t
     : public ____is_nullptr_t<typename remove_cv<_Tp>::type> {};
 
 // is_integral
@@ -238,7 +315,7 @@
 template <>          struct __is_integral<long long>          : public true_type {};
 template <>          struct __is_integral<unsigned long long> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_integral
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_integral
     : public __is_integral<typename remove_cv<_Tp>::type> {};
 
 // is_floating_point
@@ -248,16 +325,16 @@
 template <>          struct __is_floating_point<double>      : public true_type {};
 template <>          struct __is_floating_point<long double> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_floating_point
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_floating_point
     : public __is_floating_point<typename remove_cv<_Tp>::type> {};
 
 // is_array
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_array
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_array
     : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_array<_Tp[]>
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_array<_Tp[]>
     : public true_type {};
-template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE is_array<_Tp[_Np]>
+template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS is_array<_Tp[_Np]>
     : public true_type {};
 
 // is_pointer
@@ -265,23 +342,23 @@
 template <class _Tp> struct __is_pointer       : public false_type {};
 template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_pointer
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_pointer
     : public __is_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_reference
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference       : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_lvalue_reference<_Tp&> : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_lvalue_reference       : public false_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_lvalue_reference<_Tp&> : public true_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference        : public false_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_rvalue_reference        : public false_type {};
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-template <class _Tp> struct _LIBCPP_VISIBLE is_rvalue_reference<_Tp&&> : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
 #endif
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_reference        : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&>  : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference        : public false_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference<_Tp&>  : public true_type {};
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-template <class _Tp> struct _LIBCPP_VISIBLE is_reference<_Tp&&> : public true_type {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_reference<_Tp&&> : public true_type {};
 #endif
 
 #if defined(__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
@@ -292,13 +369,13 @@
 
 #if __has_feature(is_union) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_union
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_union
     : public integral_constant<bool, __is_union(_Tp)> {};
 
 #else
 
 template <class _Tp> struct __libcpp_union : public false_type {};
-template <class _Tp> struct _LIBCPP_VISIBLE is_union
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_union
     : public __libcpp_union<typename remove_cv<_Tp>::type> {};
 
 #endif
@@ -307,7 +384,7 @@
 
 #if __has_feature(is_class) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_class
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_class
     : public integral_constant<bool, __is_class(_Tp)> {};
 
 #else
@@ -318,7 +395,7 @@
 template <class _Tp> __two __test(...);
 }
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_class
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_class
     : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
 
 #endif
@@ -325,8 +402,8 @@
 
 // is_same
 
-template <class _Tp, class _Up> struct _LIBCPP_VISIBLE is_same           : public false_type {};
-template <class _Tp>            struct _LIBCPP_VISIBLE is_same<_Tp, _Tp> : public true_type {};
+template <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS is_same           : public false_type {};
+template <class _Tp>            struct _LIBCPP_TYPE_VIS is_same<_Tp, _Tp> : public true_type {};
 
 // is_function
 
@@ -347,7 +424,7 @@
     {};
 template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_function
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_function
     : public __is_function<_Tp> {};
 
 // is_member_function_pointer
@@ -355,7 +432,7 @@
 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_VISIBLE is_member_function_pointer
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_function_pointer
     : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_member_pointer
@@ -363,12 +440,12 @@
 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_VISIBLE is_member_pointer
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_pointer
     : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
 
 // is_member_object_pointer
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_member_object_pointer
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_member_object_pointer
     : public integral_constant<bool, is_member_pointer<_Tp>::value &&
                                     !is_member_function_pointer<_Tp>::value> {};
 
@@ -376,12 +453,12 @@
 
 #if __has_feature(is_enum) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_enum
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_enum
     : public integral_constant<bool, __is_enum(_Tp)> {};
 
 #else
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_enum
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_enum
     : public integral_constant<bool, !is_void<_Tp>::value             &&
                                      !is_integral<_Tp>::value         &&
                                      !is_floating_point<_Tp>::value   &&
@@ -397,13 +474,13 @@
 
 // is_arithmetic
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_arithmetic
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_arithmetic
     : public integral_constant<bool, is_integral<_Tp>::value      ||
                                      is_floating_point<_Tp>::value> {};
 
 // is_fundamental
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_fundamental
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_fundamental
     : public integral_constant<bool, is_void<_Tp>::value        ||
                                      __is_nullptr_t<_Tp>::value ||
                                      is_arithmetic<_Tp>::value> {};
@@ -410,7 +487,7 @@
 
 // is_scalar
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_scalar
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_scalar
     : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
                                      is_member_pointer<_Tp>::value ||
                                      is_pointer<_Tp>::value        ||
@@ -417,11 +494,11 @@
                                      __is_nullptr_t<_Tp>::value    ||
                                      is_enum<_Tp>::value           > {};
 
-template <> struct _LIBCPP_VISIBLE is_scalar<nullptr_t> : public true_type {};
+template <> struct _LIBCPP_TYPE_VIS is_scalar<nullptr_t> : public true_type {};
 
 // is_object
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_object
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_object
     : public integral_constant<bool, is_scalar<_Tp>::value ||
                                      is_array<_Tp>::value  ||
                                      is_union<_Tp>::value  ||
@@ -429,7 +506,7 @@
 
 // is_compound
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_compound
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_compound
     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
 
 // add_const
@@ -442,9 +519,13 @@
 template <class _Tp>
 struct __add_const<_Tp, false> {typedef const _Tp type;};
 
-template <class _Tp> struct _LIBCPP_VISIBLE add_const
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_const
     {typedef typename __add_const<_Tp>::type type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
+#endif
+
 // add_volatile
 
 template <class _Tp, bool = is_reference<_Tp>::value ||
@@ -455,39 +536,59 @@
 template <class _Tp>
 struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
 
-template <class _Tp> struct _LIBCPP_VISIBLE add_volatile
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_volatile
     {typedef typename __add_volatile<_Tp>::type type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
+#endif
+
 // add_cv
 
-template <class _Tp> struct _LIBCPP_VISIBLE add_cv
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_cv
     {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
+#endif
+
 // remove_reference
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_reference        {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&>  {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference        {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&>  {typedef _Tp type;};
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-template <class _Tp> struct _LIBCPP_VISIBLE remove_reference<_Tp&&> {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&&> {typedef _Tp type;};
 #endif
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
+#endif
+
 // add_lvalue_reference
 
-template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference                      {typedef _Tp& type;};
-template <class _Tp> struct _LIBCPP_VISIBLE add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
-template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<void>                {typedef void type;};
-template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<const void>          {typedef const void type;};
-template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<volatile void>       {typedef volatile void type;};
-template <>          struct _LIBCPP_VISIBLE add_lvalue_reference<const volatile void> {typedef const volatile void type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_lvalue_reference                      {typedef _Tp& type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
+template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<void>                {typedef void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<const void>          {typedef const void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_lvalue_reference<const volatile void> {typedef const volatile void type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
+#endif
+
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-template <class _Tp> struct _LIBCPP_VISIBLE  add_rvalue_reference                     {typedef _Tp&& type;};
-template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<void>                {typedef void type;};
-template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<const void>          {typedef const void type;};
-template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<volatile void>       {typedef volatile void type;};
-template <>          struct _LIBCPP_VISIBLE add_rvalue_reference<const volatile void> {typedef const volatile void type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS  add_rvalue_reference                     {typedef _Tp&& type;};
+template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<void>                {typedef void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<const void>          {typedef const void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct _LIBCPP_TYPE_VIS add_rvalue_reference<const volatile void> {typedef const volatile void type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
+#endif
+
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -511,17 +612,25 @@
 
 // remove_pointer
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer                      {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp*>                {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const>          {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* volatile>       {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_pointer<_Tp* const volatile> {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer                      {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp*>                {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const>          {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* volatile>       {typedef _Tp type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
+#endif
+
 // add_pointer
 
-template <class _Tp> struct _LIBCPP_VISIBLE add_pointer
+template <class _Tp> struct _LIBCPP_TYPE_VIS add_pointer
     {typedef typename remove_reference<_Tp>::type* type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
+#endif
+
 // is_signed
 
 template <class _Tp, bool = is_integral<_Tp>::value>
@@ -535,7 +644,7 @@
 
 template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_signed : public __is_signed<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_signed : public __is_signed<_Tp> {};
 
 // is_unsigned
 
@@ -550,48 +659,56 @@
 
 template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_unsigned : public __is_unsigned<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_unsigned : public __is_unsigned<_Tp> {};
 
 // rank
 
-template <class _Tp> struct _LIBCPP_VISIBLE rank
+template <class _Tp> struct _LIBCPP_TYPE_VIS rank
     : public integral_constant<size_t, 0> {};
-template <class _Tp> struct _LIBCPP_VISIBLE rank<_Tp[]>
+template <class _Tp> struct _LIBCPP_TYPE_VIS rank<_Tp[]>
     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
-template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE rank<_Tp[_Np]>
+template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS rank<_Tp[_Np]>
     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
 
 // extent
 
-template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_VISIBLE extent
+template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS extent
     : public integral_constant<size_t, 0> {};
-template <class _Tp> struct _LIBCPP_VISIBLE extent<_Tp[], 0>
+template <class _Tp> struct _LIBCPP_TYPE_VIS extent<_Tp[], 0>
     : public integral_constant<size_t, 0> {};
-template <class _Tp, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[], _Ip>
+template <class _Tp, unsigned _Ip> struct _LIBCPP_TYPE_VIS extent<_Tp[], _Ip>
     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
-template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE extent<_Tp[_Np], 0>
+template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS extent<_Tp[_Np], 0>
     : public integral_constant<size_t, _Np> {};
-template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_VISIBLE extent<_Tp[_Np], _Ip>
+template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS extent<_Tp[_Np], _Ip>
     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
 
 // remove_extent
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_extent
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_extent
     {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_extent<_Tp[]>
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[]>
     {typedef _Tp type;};
-template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_extent<_Tp[_Np]>
+template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[_Np]>
     {typedef _Tp type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
+#endif
+
 // remove_all_extents
 
-template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents
     {typedef _Tp type;};
-template <class _Tp> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[]>
+template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[]>
     {typedef typename remove_all_extents<_Tp>::type type;};
-template <class _Tp, size_t _Np> struct _LIBCPP_VISIBLE remove_all_extents<_Tp[_Np]>
+template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[_Np]>
     {typedef typename remove_all_extents<_Tp>::type type;};
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
+#endif
+
 // is_abstract
 
 namespace __is_abstract_imp
@@ -605,24 +722,56 @@
 
 template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_abstract : public __libcpp_abstract<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_abstract : public __libcpp_abstract<_Tp> {};
 
+// is_base_of
+
+#ifdef _LIBCP_HAS_IS_BASE_OF
+
+template <class _Bp, class _Dp>
+struct _LIBCPP_TYPE_VIS is_base_of
+    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
+
+#else  // __has_feature(is_base_of)
+
+namespace __is_base_of_imp
+{
+template <class _Tp>
+struct _Dst
+{
+    _Dst(const volatile _Tp &);
+};
+template <class _Tp>
+struct _Src
+{
+    operator const volatile _Tp &();
+    template <class _Up> operator const _Dst<_Up> &();
+};
+template <size_t> struct __one { typedef char type; };
+template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
+template <class _Bp, class _Dp> __two __test(...);
+}
+
+template <class _Bp, class _Dp>
+struct _LIBCPP_TYPE_VIS 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)
+
 // is_convertible
 
 #if __has_feature(is_convertible_to)
 
-template <class _T1, class _T2> struct _LIBCPP_VISIBLE is_convertible
-    : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
+template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS is_convertible
+    : public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
+                                     !is_abstract<_T2>::value> {};
 
 #else  // __has_feature(is_convertible_to)
 
 namespace __is_convertible_imp
 {
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-template <class _Tp> char  __test(const volatile typename remove_reference<_Tp>::type&&);
-#else
 template <class _Tp> char  __test(_Tp);
-#endif
 template <class _Tp> __two __test(...);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 template <class _Tp> _Tp&& __source();
@@ -657,7 +806,17 @@
     unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
 struct __is_convertible
     : public integral_constant<bool,
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
         sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
+#else
+        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
+         && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
+              && (!is_const<typename remove_reference<_T2>::type>::value
+                  || is_volatile<typename remove_reference<_T2>::type>::value)
+                  && (is_same<typename remove_cv<_T1>::type,
+                              typename remove_cv<typename remove_reference<_T2>::type>::type>::value
+                      || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
+#endif
     >
 {};
 
@@ -687,6 +846,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
 #endif
+template <class _T1>            struct __is_convertible<_T1, _T1&, 2, 0>               : public true_type {};
 template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
 template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
 template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
@@ -709,7 +869,7 @@
 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
 
-template <class _T1, class _T2> struct _LIBCPP_VISIBLE is_convertible
+template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS is_convertible
     : public __is_convertible<_T1, _T2>
 {
     static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
@@ -718,26 +878,12 @@
 
 #endif  // __has_feature(is_convertible_to)
 
-// is_base_of
-
-#ifdef _LIBCP_HAS_IS_BASE_OF
-
-template <class _Bp, class _Dp>
-struct _LIBCPP_VISIBLE is_base_of
-    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
-
-#else  // __has_feature(is_base_of)
-
-#error is_base_of not implemented.
-
-#endif  // __has_feature(is_base_of)
-
 // is_empty
 
 #if __has_feature(is_empty)
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_empty
+struct _LIBCPP_TYPE_VIS is_empty
     : public integral_constant<bool, __is_empty(_Tp)> {};
 
 #else  // __has_feature(is_empty)
@@ -746,12 +892,12 @@
 struct __is_empty1
     : public _Tp
 {
-    double _;
+    double __lx;
 };
 
 struct __is_empty2
 {
-    double _;
+    double __lx;
 };
 
 template <class _Tp, bool = is_class<_Tp>::value>
@@ -759,7 +905,7 @@
 
 template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_empty : public __libcpp_empty<_Tp> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_empty : public __libcpp_empty<_Tp> {};
 
 #endif  // __has_feature(is_empty)
 
@@ -768,23 +914,19 @@
 #if __has_feature(is_polymorphic)
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_polymorphic
+struct _LIBCPP_TYPE_VIS is_polymorphic
     : public integral_constant<bool, __is_polymorphic(_Tp)> {};
 
 #else
 
-template <class _Tp> struct __is_polymorphic1 : public _Tp {};
-template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();};
+template<typename _Tp> char &__is_polymorphic_impl(
+    typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
+                       int>::type);
+template<typename _Tp> __two &__is_polymorphic_impl(...);
 
-template <class _Tp, bool = is_class<_Tp>::value>
-struct __libcpp_polymorphic
-    : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {};
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_polymorphic
+    : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
 
-template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {};
-
-template <class _Tp> struct _LIBCPP_VISIBLE is_polymorphic
-    : public __libcpp_polymorphic<_Tp> {};
-
 #endif // __has_feature(is_polymorphic)
 
 // has_virtual_destructor
@@ -791,12 +933,12 @@
 
 #if __has_feature(has_virtual_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
+template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor
     : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
 
 #else  // _LIBCPP_HAS_TYPE_TRAITS
 
-template <class _Tp> struct _LIBCPP_VISIBLE has_virtual_destructor
+template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor
     : public false_type {};
 
 #endif  // _LIBCPP_HAS_TYPE_TRAITS
@@ -803,11 +945,9 @@
 
 // alignment_of
 
-template <class _Tp> struct __alignment_of {_Tp _;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS alignment_of
+    : public integral_constant<size_t, __alignof__(_Tp)> {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE alignment_of
-    : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};
-
 // aligned_storage
 
 template <class _Hp, class _Tp>
@@ -834,8 +974,8 @@
     typedef _Tp type;
 };
 
-struct __struct_double {long double _;};
-struct __struct_double4 {double _[4];};
+struct __struct_double {long double __lx;};
+struct __struct_double4 {double __lx[4];};
 
 typedef
     __type_list<__align_type<unsigned char>,
@@ -892,8 +1032,8 @@
 struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
     : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
 
-template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value>
-struct _LIBCPP_VISIBLE aligned_storage
+template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
+struct _LIBCPP_TYPE_VIS aligned_storage
 {
     typedef typename __find_pod<__all_types, _Align>::type _Aligner;
     static_assert(!is_void<_Aligner>::value, "");
@@ -904,13 +1044,18 @@
     };
 };
 
+#if _LIBCPP_STD_VER > 11
+template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
+    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
+#endif
+
 #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
 template <size_t _Len>\
-struct _LIBCPP_VISIBLE aligned_storage<_Len, n>\
+struct _LIBCPP_TYPE_VIS aligned_storage<_Len, n>\
 {\
     struct _ALIGNAS(n) type\
     {\
-        unsigned char _[_Len];\
+        unsigned char __lx[_Len];\
     };\
 }
 
@@ -935,6 +1080,42 @@
 
 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
 
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+// aligned_union
+
+template <size_t _I0, size_t ..._In>
+struct __static_max;
+
+template <size_t _I0>
+struct __static_max<_I0>
+{
+    static const size_t value = _I0;
+};
+
+template <size_t _I0, size_t _I1, size_t ..._In>
+struct __static_max<_I0, _I1, _In...>
+{
+    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
+                                             __static_max<_I1, _In...>::value;
+};
+
+template <size_t _Len, class _Type0, class ..._Types>
+struct aligned_union
+{
+    static const size_t alignment_value = __static_max<__alignof__(_Type0),
+                                                       __alignof__(_Types)...>::value;
+    static const size_t __len = __static_max<_Len, sizeof(_Type0),
+                                             sizeof(_Types)...>::value;
+    typedef typename aligned_storage<__len, alignment_value>::type type;
+};
+
+#if _LIBCPP_STD_VER > 11
+template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
+#endif
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
 // __promote
 
 template <class _A1, class _A2 = void, class _A3 = void,
@@ -1089,11 +1270,15 @@
 template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE make_signed
+struct _LIBCPP_TYPE_VIS make_signed
 {
     typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
 };
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
+#endif
+
 template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
 struct __make_unsigned {};
 
@@ -1114,15 +1299,19 @@
 template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE make_unsigned
+struct _LIBCPP_TYPE_VIS make_unsigned
 {
     typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
 };
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
+#endif
+
 #ifdef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp, class _Up = void, class V = void>
-struct _LIBCPP_VISIBLE common_type
+struct _LIBCPP_TYPE_VIS common_type
 {
 public:
     typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
@@ -1129,7 +1318,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE common_type<_Tp, void, void>
+struct _LIBCPP_TYPE_VIS common_type<_Tp, void, void>
 {
 public:
     typedef _Tp type;
@@ -1136,7 +1325,7 @@
 };
 
 template <class _Tp, class _Up>
-struct _LIBCPP_VISIBLE common_type<_Tp, _Up, void>
+struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up, void>
 {
 private:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1155,13 +1344,13 @@
 template <class ..._Tp> struct common_type;
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE common_type<_Tp>
+struct _LIBCPP_TYPE_VIS common_type<_Tp>
 {
     typedef _Tp type;
 };
 
 template <class _Tp, class _Up>
-struct _LIBCPP_VISIBLE common_type<_Tp, _Up>
+struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up>
 {
 private:
     static _Tp&& __t();
@@ -1172,11 +1361,15 @@
 };
 
 template <class _Tp, class _Up, class ..._Vp>
-struct _LIBCPP_VISIBLE common_type<_Tp, _Up, _Vp...>
+struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up, _Vp...>
 {
     typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
 };
 
+#if _LIBCPP_STD_VER > 11
+template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
+#endif
+
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
 // is_assignable
@@ -1216,13 +1409,13 @@
 
 // is_copy_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_copy_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_copy_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
                      const typename add_lvalue_reference<_Tp>::type> {};
 
 // is_move_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_move_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_move_assignable
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
                      const typename add_rvalue_reference<_Tp>::type> {};
@@ -1337,7 +1530,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE decay
+struct _LIBCPP_TYPE_VIS decay
 {
 private:
     typedef typename remove_reference<_Tp>::type _Up;
@@ -1355,6 +1548,10 @@
                      >::type type;
 };
 
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using decay_t = typename decay<_Tp>::type;
+#endif
+
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
@@ -1597,7 +1794,7 @@
 
 template <class _MP>
 struct __member_pointer_traits
-    : public __member_pointer_traits_imp<_MP,
+    : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
                     is_member_function_pointer<_MP>::value,
                     is_member_object_pointer<_MP>::value>
 {
@@ -1609,77 +1806,13 @@
 
 template <class _Callable> class result_of;
 
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
 template <class _Fn, bool, bool>
 class __result_of
 {
 };
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-template <class _Fn, class ..._ArgTypes>
-class __result_of<_Fn(_ArgTypes...), true, false>
-{
-public:
-    typedef decltype(declval<_Fn>()(declval<_ArgTypes>()...)) type;
-};
-
-template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
-struct __result_of_mp;
-
-// member function pointer
-
-template <class _MP, class _Tp>
-struct __result_of_mp<_MP, _Tp, true>
-    : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
-{
-};
-
-// member data pointer
-
-template <class _MP, class _Tp, bool>
-struct __result_of_mdp;
-
-template <class _Rp, class _Class, class _Tp>
-struct __result_of_mdp<_Rp _Class::*, _Tp, false>
-{
-    typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type&& type;
-};
-
-template <class _Rp, class _Class, class _Tp>
-struct __result_of_mdp<_Rp _Class::*, _Tp, true>
-{
-    typedef typename __apply_cv<_Tp, _Rp>::type&& type;
-};
-
-template <class _Rp, class _Class, class _Tp>
-struct __result_of_mp<_Rp _Class::*, _Tp, false>
-    : public __result_of_mdp<_Rp _Class::*, _Tp,
-            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
-{
-};
-
-template <class _Fn, class _Tp, class ..._ArgTypes>
-class __result_of<_Fn(_Tp, _ArgTypes...), false, true>  // _Fn must be member pointer
-    : public __result_of_mp<typename remove_reference<_Fn>::type,
-                            _Tp,
-                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
-{
-};
-
-// result_of
-
-template <class _Fn, class ..._ArgTypes>
-class _LIBCPP_VISIBLE result_of<_Fn(_ArgTypes...)>
-    : public __result_of<_Fn(_ArgTypes...),
-                         is_class<typename remove_reference<_Fn>::type>::value ||
-                         is_function<typename remove_reference<_Fn>::type>::value,
-                         is_member_pointer<typename remove_reference<_Fn>::type>::value
-                        >
-{
-};
-
-#else  // _LIBCPP_HAS_NO_VARIADICS
-
 template <class _Fn>
 class __result_of<_Fn(), true, false>
 {
@@ -1780,7 +1913,7 @@
 // result_of
 
 template <class _Fn>
-class _LIBCPP_VISIBLE result_of<_Fn()>
+class _LIBCPP_TYPE_VIS result_of<_Fn()>
     : public __result_of<_Fn(),
                          is_class<typename remove_reference<_Fn>::type>::value ||
                          is_function<typename remove_reference<_Fn>::type>::value,
@@ -1790,7 +1923,7 @@
 };
 
 template <class _Fn, class _A0>
-class _LIBCPP_VISIBLE result_of<_Fn(_A0)>
+class _LIBCPP_TYPE_VIS result_of<_Fn(_A0)>
     : public __result_of<_Fn(_A0),
                          is_class<typename remove_reference<_Fn>::type>::value ||
                          is_function<typename remove_reference<_Fn>::type>::value,
@@ -1800,7 +1933,7 @@
 };
 
 template <class _Fn, class _A0, class _A1>
-class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1)>
+class _LIBCPP_TYPE_VIS result_of<_Fn(_A0, _A1)>
     : public __result_of<_Fn(_A0, _A1),
                          is_class<typename remove_reference<_Fn>::type>::value ||
                          is_function<typename remove_reference<_Fn>::type>::value,
@@ -1810,7 +1943,7 @@
 };
 
 template <class _Fn, class _A0, class _A1, class _A2>
-class _LIBCPP_VISIBLE result_of<_Fn(_A0, _A1, _A2)>
+class _LIBCPP_TYPE_VIS result_of<_Fn(_A0, _A1, _A2)>
     : public __result_of<_Fn(_A0, _A1, _A2),
                          is_class<typename remove_reference<_Fn>::type>::value ||
                          is_function<typename remove_reference<_Fn>::type>::value,
@@ -1827,8 +1960,10 @@
 
 //      main is_constructible test
 
+template<typename, typename T> struct __select_2nd { typedef T type; };
+
 template <class _Tp, class ..._Args>
-decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...)), true_type())
+typename __select_2nd<decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...))), true_type>::type
 __is_constructible_test(_Tp&&, _Args&& ...);
 
 template <class ..._Args>
@@ -1865,8 +2000,8 @@
 template <class _Tp>
 struct __is_constructible_ref
 {
-    true_type static __(_Tp);
-    false_type static __(...);
+    true_type static __lxx(_Tp);
+    false_type static __lxx(...);
 };
 
 template <class _Tp, class _A0>
@@ -1873,7 +2008,7 @@
 struct __is_constructible<true, _Tp, _A0>
     : public common_type
              <
-                 decltype(__is_constructible_ref<_Tp>::__(declval<_A0>()))
+                 decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>()))
              >::type
     {};
 
@@ -1913,7 +2048,7 @@
 //      is_constructible entry point
 
 template <class _Tp, class... _Args>
-struct _LIBCPP_VISIBLE is_constructible
+struct _LIBCPP_TYPE_VIS is_constructible
     : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
                                         || is_abstract<_Tp>::value,
                                            _Tp, _Args...>
@@ -2061,7 +2196,7 @@
 
 template <class _Tp, class _A0 = __is_construct::__nat,
                      class _A1 = __is_construct::__nat>
-struct _LIBCPP_VISIBLE is_constructible
+struct _LIBCPP_TYPE_VIS is_constructible
     : public __is_constructible2_void_check<is_void<_Tp>::value
                                         || is_abstract<_Tp>::value
                                         || is_function<_Tp>::value
@@ -2071,7 +2206,7 @@
     {};
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
+struct _LIBCPP_TYPE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
     : public __is_constructible0_void_check<is_void<_Tp>::value
                                         || is_abstract<_Tp>::value
                                         || is_function<_Tp>::value,
@@ -2079,7 +2214,7 @@
     {};
 
 template <class _Tp, class _A0>
-struct _LIBCPP_VISIBLE is_constructible<_Tp, _A0, __is_construct::__nat>
+struct _LIBCPP_TYPE_VIS is_constructible<_Tp, _A0, __is_construct::__nat>
     : public __is_constructible1_void_check<is_void<_Tp>::value
                                         || is_abstract<_Tp>::value
                                         || is_function<_Tp>::value
@@ -2127,7 +2262,7 @@
 // is_default_constructible
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_default_constructible
+struct _LIBCPP_TYPE_VIS is_default_constructible
     : public is_constructible<_Tp>
     {};
 
@@ -2134,7 +2269,7 @@
 // is_copy_constructible
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_copy_constructible
+struct _LIBCPP_TYPE_VIS is_copy_constructible
     : public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
     {};
 
@@ -2141,7 +2276,7 @@
 // is_move_constructible
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_move_constructible
+struct _LIBCPP_TYPE_VIS is_move_constructible
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
 #else
@@ -2156,7 +2291,7 @@
 #if __has_feature(is_trivially_constructible)
 
 template <class _Tp, class... _Args>
-struct _LIBCPP_VISIBLE is_trivially_constructible
+struct _LIBCPP_TYPE_VIS is_trivially_constructible
     : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
 {
 };
@@ -2164,13 +2299,13 @@
 #else  // !__has_feature(is_trivially_constructible)
 
 template <class _Tp, class... _Args>
-struct _LIBCPP_VISIBLE is_trivially_constructible
+struct _LIBCPP_TYPE_VIS is_trivially_constructible
     : false_type
 {
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp>
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp>
 #if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_trivial_constructor(_Tp)>
 #else
@@ -2181,9 +2316,9 @@
 
 template <class _Tp>
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&&>
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&&>
 #else
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp>
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp>
 #endif
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
@@ -2190,13 +2325,13 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&>
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&>
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
 };
@@ -2207,7 +2342,7 @@
 
 template <class _Tp, class _A0 = __is_construct::__nat,
                      class _A1 = __is_construct::__nat>
-struct _LIBCPP_VISIBLE is_trivially_constructible
+struct _LIBCPP_TYPE_VIS is_trivially_constructible
     : false_type
 {
 };
@@ -2215,7 +2350,7 @@
 #if __has_feature(is_trivially_constructible)
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
                                                        __is_construct::__nat>
     : integral_constant<bool, __is_trivially_constructible(_Tp)>
 {
@@ -2222,7 +2357,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp,
                                                        __is_construct::__nat>
     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
 {
@@ -2229,7 +2364,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&,
                                                        __is_construct::__nat>
     : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
 {
@@ -2236,7 +2371,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&,
                                                        __is_construct::__nat>
     : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
 {
@@ -2245,7 +2380,7 @@
 #else  // !__has_feature(is_trivially_constructible)
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, __is_construct::__nat,
                                                        __is_construct::__nat>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
@@ -2252,7 +2387,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp,
                                                        __is_construct::__nat>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
@@ -2259,7 +2394,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, const _Tp&,
                                                        __is_construct::__nat>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
@@ -2266,7 +2401,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
+struct _LIBCPP_TYPE_VIS is_trivially_constructible<_Tp, _Tp&,
                                                        __is_construct::__nat>
     : integral_constant<bool, is_scalar<_Tp>::value>
 {
@@ -2278,19 +2413,19 @@
 
 // is_trivially_default_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_default_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_default_constructible
     : public is_trivially_constructible<_Tp>
     {};
 
 // is_trivially_copy_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copy_constructible
     : public is_trivially_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
     {};
 
 // is_trivially_move_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_move_constructible
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
 #else
@@ -2338,7 +2473,7 @@
 
 // is_trivially_copy_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copy_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
                                const typename add_lvalue_reference<_Tp>::type>
     {};
@@ -2345,7 +2480,7 @@
 
 // is_trivially_move_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_move_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
                                      typename add_rvalue_reference<_Tp>::type>
@@ -2358,7 +2493,7 @@
 
 #if __has_feature(has_trivial_destructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_destructible
     : public integral_constant<bool, __has_trivial_destructor(_Tp)> {};
 
 #else  // _LIBCPP_HAS_TYPE_TRAITS
@@ -2367,7 +2502,7 @@
     : public integral_constant<bool, is_scalar<_Tp>::value ||
                                      is_reference<_Tp>::value> {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_destructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_destructible
     : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
 
 #endif  // _LIBCPP_HAS_TYPE_TRAITS
@@ -2393,13 +2528,13 @@
 };
 
 template <class _Tp, class... _Args>
-struct _LIBCPP_VISIBLE is_nothrow_constructible
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible
     : __is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, _Tp, _Args...>
 {
 };
 
 template <class _Tp, size_t _Ns>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp[_Ns]>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp[_Ns]>
     : __is_nothrow_constructible<is_constructible<_Tp>::value, _Tp>
 {
 };
@@ -2407,13 +2542,13 @@
 #else  // __has_feature(cxx_noexcept)
 
 template <class _Tp, class... _Args>
-struct _LIBCPP_VISIBLE is_nothrow_constructible
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible
     : false_type
 {
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp>
 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
 #else
@@ -2424,9 +2559,9 @@
 
 template <class _Tp>
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&&>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&&>
 #else
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp>
 #endif
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
@@ -2437,7 +2572,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, const _Tp&>
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
@@ -2447,7 +2582,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&>
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&>
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
 #else
@@ -2462,13 +2597,13 @@
 
 template <class _Tp, class _A0 = __is_construct::__nat,
                      class _A1 = __is_construct::__nat>
-struct _LIBCPP_VISIBLE is_nothrow_constructible
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible
     : false_type
 {
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, __is_construct::__nat,
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat,
                                                        __is_construct::__nat>
 #if __has_feature(has_nothrow_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_constructor(_Tp)>
@@ -2479,7 +2614,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp,
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp,
                                                        __is_construct::__nat>
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
@@ -2490,7 +2625,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, const _Tp&,
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, const _Tp&,
                                                        __is_construct::__nat>
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
@@ -2501,7 +2636,7 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_constructible<_Tp, _Tp&,
+struct _LIBCPP_TYPE_VIS is_nothrow_constructible<_Tp, _Tp&,
                                                        __is_construct::__nat>
 #if __has_feature(has_nothrow_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_copy(_Tp)>
@@ -2515,19 +2650,19 @@
 
 // is_nothrow_default_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_default_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_default_constructible
     : public is_nothrow_constructible<_Tp>
     {};
 
 // is_nothrow_copy_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_copy_constructible
     : public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type>
     {};
 
 // is_nothrow_move_constructible
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_constructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_move_constructible
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
 #else
@@ -2554,7 +2689,7 @@
 };
 
 template <class _Tp, class _Arg>
-struct _LIBCPP_VISIBLE is_nothrow_assignable
+struct _LIBCPP_TYPE_VIS is_nothrow_assignable
     : public __is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
 {
 };
@@ -2562,11 +2697,11 @@
 #else  // __has_feature(cxx_noexcept)
 
 template <class _Tp, class _Arg>
-struct _LIBCPP_VISIBLE is_nothrow_assignable
+struct _LIBCPP_TYPE_VIS is_nothrow_assignable
     : public false_type {};
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp>
+struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, _Tp>
 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
@@ -2574,7 +2709,7 @@
 #endif
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, _Tp&>
+struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, _Tp&>
 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
@@ -2582,7 +2717,7 @@
 #endif
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_assignable<_Tp&, const _Tp&>
+struct _LIBCPP_TYPE_VIS is_nothrow_assignable<_Tp&, const _Tp&>
 #if __has_feature(has_nothrow_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
     : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
 #else
@@ -2605,7 +2740,7 @@
 
 // is_nothrow_copy_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_copy_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_copy_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
                                const typename add_lvalue_reference<_Tp>::type>
     {};
@@ -2612,7 +2747,7 @@
 
 // is_nothrow_move_assignable
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_move_assignable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_move_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
                                      typename add_rvalue_reference<_Tp>::type>
@@ -2640,19 +2775,19 @@
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_destructible
+struct _LIBCPP_TYPE_VIS is_nothrow_destructible
     : public __is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
 {
 };
 
 template <class _Tp, size_t _Ns>
-struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp[_Ns]>
+struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp[_Ns]>
     : public is_nothrow_destructible<_Tp>
 {
 };
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp&>
+struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp&>
     : public true_type
 {
 };
@@ -2660,7 +2795,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-struct _LIBCPP_VISIBLE is_nothrow_destructible<_Tp&&>
+struct _LIBCPP_TYPE_VIS is_nothrow_destructible<_Tp&&>
     : public true_type
 {
 };
@@ -2673,7 +2808,7 @@
     : public integral_constant<bool, is_scalar<_Tp>::value ||
                                      is_reference<_Tp>::value> {};
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_nothrow_destructible
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_nothrow_destructible
     : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
 
 #endif
@@ -2682,12 +2817,12 @@
 
 #if __has_feature(is_pod) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_pod
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_pod
     : public integral_constant<bool, __is_pod(_Tp)> {};
 
 #else  // _LIBCPP_HAS_TYPE_TRAITS
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_pod
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_pod
     : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
                                      is_trivially_copy_constructible<_Tp>::value      &&
                                      is_trivially_copy_assignable<_Tp>::value    &&
@@ -2697,7 +2832,7 @@
 
 // is_literal_type;
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_literal_type
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_literal_type
 #if __has_feature(is_literal)
     : public integral_constant<bool, __is_literal(_Tp)>
 #else
@@ -2708,7 +2843,7 @@
     
 // is_standard_layout;
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_standard_layout
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_standard_layout
 #if __has_feature(is_standard_layout)
     : public integral_constant<bool, __is_standard_layout(_Tp)>
 #else
@@ -2718,7 +2853,7 @@
     
 // is_trivially_copyable;
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copyable
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivially_copyable
 #if __has_feature(is_trivially_copyable)
     : public integral_constant<bool, __is_trivially_copyable(_Tp)>
 #else
@@ -2728,7 +2863,7 @@
     
 // is_trivial;
 
-template <class _Tp> struct _LIBCPP_VISIBLE is_trivial
+template <class _Tp> struct _LIBCPP_TYPE_VIS is_trivial
 #if __has_feature(is_trivial)
     : public integral_constant<bool, __is_trivial(_Tp)>
 #else
@@ -2781,37 +2916,37 @@
 
 template <class _Rp, class ..._Param>
 struct __check_complete<_Rp (*)(_Param...)>
-    : private __check_complete<_Param...>
+    : private __check_complete<_Rp>
 {
 };
 
 template <class _Rp, class ..._Param>
 struct __check_complete<_Rp (_Param...)>
-    : private __check_complete<_Param...>
+    : private __check_complete<_Rp>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...)>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) volatile>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
@@ -2819,49 +2954,49 @@
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) &>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) &&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const&&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) volatile&&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&>
-    : private __check_complete<_Class, _Param...>
+    : private __check_complete<_Class>
 {
 };
 
@@ -2884,12 +3019,28 @@
 
 // bullets 1 and 2
 
-template <class _Fp, class _A0, class ..._Args>
+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,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
     -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...));
 
-template <class _Fp, class _A0, class ..._Args>
+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,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
     -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
@@ -2896,12 +3047,28 @@
 
 // bullets 3 and 4
 
-template <class _Fp, class _A0>
+template <class _Fp, class _A0,
+            class = typename enable_if
+            <
+                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
+                is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
     -> decltype(_VSTD::forward<_A0>(__a0).*__f);
 
-template <class _Fp, class _A0>
+template <class _Fp, class _A0,
+            class = typename enable_if
+            <
+                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
+                !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
     -> decltype((*_VSTD::forward<_A0>(__a0)).*__f);
@@ -2909,6 +3076,7 @@
 // bullet 5
 
 template <class _Fp, class ..._Args>
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _Args&& ...__args)
     -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...));
@@ -2917,7 +3085,7 @@
 
 template <class _Fp, class ..._Args>
 struct __invokable_imp
-    : private __check_complete<_Fp, _Args...>
+    : private __check_complete<_Fp>
 {
     typedef decltype(
             __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
@@ -2951,6 +3119,16 @@
 {
 };
 
+template <class _Fp, class ..._Args>
+class _LIBCPP_TYPE_VIS result_of<_Fp(_Args...)>
+    : public __invoke_of<_Fp, _Args...>
+{
+};
+
+#if _LIBCPP_STD_VER > 11
+template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
+#endif
+
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp>
@@ -3045,6 +3223,10 @@
     typedef _LIBCXX_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
 
 template <class _Tp, bool _Support = false>

Modified: trunk/contrib/libc++/include/typeindex
===================================================================
--- trunk/contrib/libc++/include/typeindex	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/typeindex	2016-01-07 17:22:14 UTC (rev 7405)
@@ -55,7 +55,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-class _LIBCPP_VISIBLE type_index
+class _LIBCPP_TYPE_VIS type_index
 {
     const type_info* __t_;
 public:
@@ -87,10 +87,10 @@
     const char* name() const _NOEXCEPT {return __t_->name();}
 };
 
-template <class _Tp> struct _LIBCPP_VISIBLE hash;
+template <class _Tp> struct _LIBCPP_TYPE_VIS hash;
 
 template <>
-struct _LIBCPP_VISIBLE hash<type_index>
+struct _LIBCPP_TYPE_VIS hash<type_index>
     : public unary_function<type_index, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY

Modified: trunk/contrib/libc++/include/unordered_map
===================================================================
--- trunk/contrib/libc++/include/unordered_map	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/unordered_map	2016-01-07 17:22:14 UTC (rev 7405)
@@ -325,7 +325,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value
+template <class _Key, class _Cp, class _Hash, bool = is_empty<_Hash>::value
 #if __has_feature(is_final)
                                          && !__is_final(_Hash)
 #endif
@@ -333,8 +333,6 @@
 class __unordered_map_hasher
     : private _Hash
 {
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_hasher()
@@ -347,23 +345,18 @@
     _LIBCPP_INLINE_VISIBILITY
     const _Hash& hash_function() const _NOEXCEPT {return *this;}
     _LIBCPP_INLINE_VISIBILITY
-    size_t operator()(const _Pp& __x) const
-        {return static_cast<const _Hash&>(*this)(__x.first);}
-    _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Cp& __x) const
-        {return static_cast<const _Hash&>(*this)(__x.first);}
+        {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Key& __x) const
         {return static_cast<const _Hash&>(*this)(__x);}
 };
 
-template <class _Key, class _Tp, class _Hash>
-class __unordered_map_hasher<_Key, _Tp, _Hash, false>
+template <class _Key, class _Cp, class _Hash>
+class __unordered_map_hasher<_Key, _Cp, _Hash, false>
 {
     _Hash __hash_;
 
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_hasher()
@@ -376,17 +369,14 @@
     _LIBCPP_INLINE_VISIBILITY
     const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
     _LIBCPP_INLINE_VISIBILITY
-    size_t operator()(const _Pp& __x) const
-        {return __hash_(__x.first);}
-    _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Cp& __x) const
-        {return __hash_(__x.first);}
+        {return __hash_(__x.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(const _Key& __x) const
         {return __hash_(__x);}
 };
 
-template <class _Key, class _Tp, class _Pred, bool = is_empty<_Pred>::value
+template <class _Key, class _Cp, class _Pred, bool = is_empty<_Pred>::value
 #if __has_feature(is_final)
                                          && !__is_final(_Pred)
 #endif
@@ -394,8 +384,6 @@
 class __unordered_map_equal
     : private _Pred
 {
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_equal()
@@ -408,41 +396,21 @@
     _LIBCPP_INLINE_VISIBILITY
     const _Pred& key_eq() const _NOEXCEPT {return *this;}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Cp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Cp& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Cp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
+        {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Key& __y) const
-        {return static_cast<const _Pred&>(*this)(__x.first, __y);}
+        {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _Cp& __y) const
-        {return static_cast<const _Pred&>(*this)(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return static_cast<const _Pred&>(*this)(__x, __y);}
+        {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
 };
 
-template <class _Key, class _Tp, class _Pred>
-class __unordered_map_equal<_Key, _Tp, _Pred, false>
+template <class _Key, class _Cp, class _Pred>
+class __unordered_map_equal<_Key, _Cp, _Pred, false>
 {
     _Pred __pred_;
 
-    typedef pair<typename remove_const<_Key>::type, _Tp> _Pp;
-    typedef pair<const _Key, _Tp> _Cp;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_equal()
@@ -455,32 +423,14 @@
     _LIBCPP_INLINE_VISIBILITY
     const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Pp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Cp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Pp& __x, const _Key& __y) const
-        {return __pred_(__x.first, __y);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Cp& __x, const _Pp& __y) const
-        {return __pred_(__x.first, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Cp& __y) const
-        {return __pred_(__x.first, __y.first);}
+        {return __pred_(__x.__cc.first, __y.__cc.first);}
     _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Cp& __x, const _Key& __y) const
-        {return __pred_(__x.first, __y);}
+        {return __pred_(__x.__cc.first, __y);}
     _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Pp& __y) const
-        {return __pred_(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
     bool operator()(const _Key& __x, const _Cp& __y) const
-        {return __pred_(__x, __y.first);}
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(const _Key& __x, const _Key& __y) const
-        {return __pred_(__x, __y);}
+        {return __pred_(__x, __y.__cc.first);}
 };
 
 template <class _Alloc>
@@ -492,8 +442,8 @@
 public:
     typedef typename __alloc_traits::pointer    pointer;
 private:
-    typedef typename value_type::first_type     first_type;
-    typedef typename value_type::second_type    second_type;
+    typedef typename value_type::value_type::first_type     first_type;
+    typedef typename value_type::value_type::second_type    second_type;
 
     allocator_type& __na_;
 
@@ -535,9 +485,9 @@
     void operator()(pointer __p) _NOEXCEPT
     {
         if (__second_constructed)
-            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
         if (__first_constructed)
-            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
         if (__p)
             __alloc_traits::deallocate(__na_, __p, 1);
     }
@@ -544,13 +494,13 @@
 };
 
 template <class _HashIterator>
-class _LIBCPP_VISIBLE __hash_map_iterator
+class _LIBCPP_TYPE_VIS __hash_map_iterator
 {
     _HashIterator __i_;
 
     typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
-    typedef const typename _HashIterator::value_type::first_type key_type;
-    typedef typename _HashIterator::value_type::second_type      mapped_type;
+    typedef const typename _HashIterator::value_type::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::value_type::second_type      mapped_type;
 public:
     typedef forward_iterator_tag                                 iterator_category;
     typedef pair<key_type, mapped_type>                          value_type;
@@ -571,9 +521,9 @@
     __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return *operator->();}
+    reference operator*() const {return __i_->__cc;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return (pointer)__i_.operator->();}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_map_iterator& operator++() {++__i_; return *this;}
@@ -592,21 +542,21 @@
         bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
 };
 
 template <class _HashIterator>
-class _LIBCPP_VISIBLE __hash_map_const_iterator
+class _LIBCPP_TYPE_VIS __hash_map_const_iterator
 {
     _HashIterator __i_;
 
     typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
-    typedef const typename _HashIterator::value_type::first_type key_type;
-    typedef typename _HashIterator::value_type::second_type      mapped_type;
+    typedef const typename _HashIterator::value_type::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::value_type::second_type      mapped_type;
 public:
     typedef forward_iterator_tag                                 iterator_category;
     typedef pair<key_type, mapped_type>                          value_type;
@@ -632,9 +582,9 @@
                 : __i_(__i.__i_) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return *operator->();}
+    reference operator*() const {return __i_->__cc;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return (pointer)__i_.operator->();}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_map_const_iterator& operator++() {++__i_; return *this;}
@@ -653,15 +603,15 @@
         bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
         {return __x.__i_ != __y.__i_;}
 
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
-    template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
-    template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
 };
 
 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
           class _Alloc = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE unordered_map
+class _LIBCPP_TYPE_VIS unordered_map
 {
 public:
     // types
@@ -671,13 +621,56 @@
     typedef _Pred                                          key_equal;
     typedef _Alloc                                         allocator_type;
     typedef pair<const key_type, mapped_type>              value_type;
+    typedef pair<key_type, mapped_type>                    __nc_value_type;
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
 
 private:
-    typedef pair<key_type, mapped_type>                    __value_type;
-    typedef __unordered_map_hasher<key_type, mapped_type, hasher>   __hasher;
-    typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal;
+#if __cplusplus >= 201103L
+    union __value_type
+    {
+        typedef typename unordered_map::value_type value_type;
+        typedef typename unordered_map::__nc_value_type __nc_value_type;
+        value_type __cc;
+        __nc_value_type __nc;
+
+        template <class ..._Args>
+        __value_type(_Args&& ...__args)
+            : __cc(std::forward<_Args>(__args)...) {}
+
+        __value_type(const __value_type& __v)
+            : __cc(std::move(__v.__cc)) {}
+
+        __value_type(__value_type&& __v)
+            : __nc(std::move(__v.__nc)) {}
+
+        __value_type& operator=(const __value_type& __v)
+            {__nc = __v.__cc; return *this;}
+
+        __value_type& operator=(__value_type&& __v)
+            {__nc = std::move(__v.__nc); return *this;}
+
+        ~__value_type() {__cc.~value_type();}
+    };
+#else
+    struct __value_type
+    {
+        typedef typename unordered_map::value_type value_type;
+        value_type __cc;
+
+        __value_type() {}
+
+        template <class _A0>
+        __value_type(const _A0& __a0)
+            : __cc(__a0) {}
+
+        template <class _A0, class _A1>
+        __value_type(const _A0& __a0, const _A1& __a1)
+            : __cc(__a0, __a1) {}
+    };
+#endif
+    typedef __unordered_map_hasher<key_type, __value_type, hasher>   __hasher;
+    typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
     typedef typename allocator_traits<allocator_type>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind_alloc<__value_type>
@@ -750,7 +743,16 @@
     _LIBCPP_INLINE_VISIBILITY
     unordered_map& operator=(const unordered_map& __u)
     {
+#if __cplusplus >= 201103L
         __table_ = __u.__table_;
+#else
+        __table_.clear();
+        __table_.hash_function() = __u.__table_.hash_function();
+        __table_.key_eq() = __u.__table_.key_eq();
+        __table_.max_load_factor() = __u.__table_.max_load_factor();
+        __table_.__copy_assign_alloc(__u.__table_);
+        insert(__u.begin(), __u.end());
+#endif
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -786,42 +788,15 @@
     const_iterator cend()   const _NOEXCEPT {return __table_.end();}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> emplace()
-        {return __table_.__emplace_unique();}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        pair<iterator, bool> emplace(_A0&& __a0)
-            {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0));}
-
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        pair<iterator, bool> emplace(_A0&& __a0, _Args&&... __args);
+    template <class... _Args>
+        pair<iterator, bool> emplace(_Args&&... __args);
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator)
-        {return __table_.__emplace_unique().first;}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
+    template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
-        iterator emplace_hint(const_iterator, _A0&& __a0)
-            {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0)).first;}
-
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        iterator emplace_hint(const_iterator, _A0&& __a0, _Args&&... __args)
-            {return emplace(_VSTD::forward<_A0>(__a0),
-                            _VSTD::forward<_Args>(__args)...).first;}
+        iterator emplace_hint(const_iterator, _Args&&... __args)
+            {return emplace(_VSTD::forward<_Args>(__args)...).first;}
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
@@ -932,17 +907,17 @@
 
 private:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
+    __node_holder __construct_node_with_key(key_type&& __k);
 #ifndef _LIBCPP_HAS_NO_VARIADICS
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
 #endif  // _LIBCPP_HAS_NO_VARIADICS
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0);
-#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    __node_holder __construct_node(const key_type& __k);
-#endif
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node_with_key(const key_type& __k);
 };
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -1106,33 +1081,21 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0, class... _Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
-unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
-                                                                 _Args&&... __args)
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
 {
     __node_allocator& __na = __table_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first),
-                             _VSTD::forward<_A0>(__a0));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second),
-                             _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0,
-          class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
-         >
+template <class _A0>
 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
 {
@@ -1145,17 +1108,44 @@
     return __h;
 }
 
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return _VSTD::move(__h);
+}
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0, class... _Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
+template <class _A0, class _A1, class ..._Args>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
+                                                                 _A1&& __a1,
+                                                                 _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class... _Args>
 pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
-unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
     if (__r.second)
         __h.release();
@@ -1163,23 +1153,21 @@
 }
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
-#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
-unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
 {
     __node_allocator& __na = __table_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
     __h.get_deleter().__second_constructed = true;
     return _VSTD::move(__h);
 }
 
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1198,7 +1186,7 @@
     iterator __i = find(__k);
     if (__i != end())
         return __i->second;
-    __node_holder __h = __construct_node(__k);
+    __node_holder __h = __construct_node_with_key(__k);
     pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
     __h.release();
     return __r.first->second;
@@ -1213,7 +1201,7 @@
     iterator __i = find(__k);
     if (__i != end())
         return __i->second;
-    __node_holder __h = __construct_node(_VSTD::move(__k));
+    __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
     pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
     __h.release();
     return __r.first->second;
@@ -1285,7 +1273,7 @@
 
 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
           class _Alloc = allocator<pair<const _Key, _Tp> > >
-class _LIBCPP_VISIBLE unordered_multimap
+class _LIBCPP_TYPE_VIS unordered_multimap
 {
 public:
     // types
@@ -1295,13 +1283,56 @@
     typedef _Pred                                          key_equal;
     typedef _Alloc                                         allocator_type;
     typedef pair<const key_type, mapped_type>              value_type;
+    typedef pair<key_type, mapped_type>                    __nc_value_type;
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
 
 private:
-    typedef pair<key_type, mapped_type>                    __value_type;
-    typedef __unordered_map_hasher<key_type, mapped_type, hasher>   __hasher;
-    typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal;
+#if __cplusplus >= 201103L
+    union __value_type
+    {
+        typedef typename unordered_multimap::value_type value_type;
+        typedef typename unordered_multimap::__nc_value_type __nc_value_type;
+        value_type __cc;
+        __nc_value_type __nc;
+
+        template <class ..._Args>
+        __value_type(_Args&& ...__args)
+            : __cc(std::forward<_Args>(__args)...) {}
+
+        __value_type(const __value_type& __v)
+            : __cc(std::move(__v.__cc)) {}
+
+        __value_type(__value_type&& __v)
+            : __nc(std::move(__v.__nc)) {}
+
+        __value_type& operator=(const __value_type& __v)
+            {__nc = __v.__cc; return *this;}
+
+        __value_type& operator=(__value_type&& __v)
+            {__nc = std::move(__v.__nc); return *this;}
+
+        ~__value_type() {__cc.~value_type();}
+    };
+#else
+    struct __value_type
+    {
+        typedef typename unordered_multimap::value_type value_type;
+        value_type __cc;
+
+        __value_type() {}
+
+        template <class _A0>
+        __value_type(const _A0& __a0)
+            : __cc(__a0) {}
+
+        template <class _A0, class _A1>
+        __value_type(const _A0& __a0, const _A1& __a1)
+            : __cc(__a0, __a1) {}
+    };
+#endif
+    typedef __unordered_map_hasher<key_type, __value_type, hasher>   __hasher;
+    typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
     typedef typename allocator_traits<allocator_type>::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
             rebind_alloc<__value_type>
@@ -1373,7 +1404,16 @@
     _LIBCPP_INLINE_VISIBILITY
     unordered_multimap& operator=(const unordered_multimap& __u)
     {
+#if __cplusplus >= 201103L
         __table_ = __u.__table_;
+#else
+        __table_.clear();
+        __table_.hash_function() = __u.__table_.hash_function();
+        __table_.key_eq() = __u.__table_.key_eq();
+        __table_.max_load_factor() = __u.__table_.max_load_factor();
+        __table_.__copy_assign_alloc(__u.__table_);
+        insert(__u.begin(), __u.end());
+#endif
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1409,40 +1449,14 @@
     const_iterator cend()   const _NOEXCEPT {return __table_.end();}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace()
-        {return __table_.__emplace_multi();}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        iterator emplace(_A0&& __a0)
-            {return __table_.__emplace_multi(_VSTD::forward<_A0>(__a0));}
-
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        iterator emplace(_A0&& __a0, _Args&&... __args);
+    template <class... _Args>
+        iterator emplace(_Args&&... __args);
 
+    template <class... _Args>
+        iterator emplace_hint(const_iterator __p, _Args&&... __args);
 #endif  // _LIBCPP_HAS_NO_VARIADICS
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator __p)
-        {return __table_.__emplace_hint_multi(__p.__i_);}
-
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        iterator emplace_hint(const_iterator __p, _A0&& __a0)
-            {return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));}
-
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        iterator emplace_hint(const_iterator __p, _A0&& __a0, _Args&&... __args);
-#endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
@@ -1543,14 +1557,16 @@
     void reserve(size_type __n) {__table_.reserve(__n);}
 
 private:
-#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
-    template <class _A0, class... _Args,
-              class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
-    template <class _A0,
-              class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
-        __node_holder __construct_node(_A0&& __a0);
-#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -1716,33 +1732,21 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0, class... _Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
-unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
-        _A0&& __a0, _Args&&... __args)
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
 {
     __node_allocator& __na = __table_.__node_alloc();
     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first),
-                             _VSTD::forward<_A0>(__a0));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
     __h.get_deleter().__first_constructed = true;
-    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second),
-                             _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__second_constructed = true;
     return __h;
 }
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0,
-          class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
-         >
+template <class _A0>
 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
 {
@@ -1758,14 +1762,27 @@
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0, class... _Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
+template <class _A0, class _A1, class ..._Args>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
+        _A0&& __a0, _A1&& __a1, _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class... _Args>
 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
-unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __table_.__node_insert_multi(__h.get());
     __h.release();
     return __r;
@@ -1772,15 +1789,12 @@
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-template <class _A0, class... _Args,
-          class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
-         >
+template <class... _Args>
 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
-        const_iterator __p, _A0&& __a0, _Args&&... __args)
+        const_iterator __p, _Args&&... __args)
 {
-    __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
-                                         _VSTD::forward<_Args>(__args)...);
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
     __h.release();
     return __r;

Modified: trunk/contrib/libc++/include/unordered_set
===================================================================
--- trunk/contrib/libc++/include/unordered_set	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/unordered_set	2016-01-07 17:22:14 UTC (rev 7405)
@@ -313,7 +313,7 @@
 
 template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
           class _Alloc = allocator<_Value> >
-class _LIBCPP_VISIBLE unordered_set
+class _LIBCPP_TYPE_VIS unordered_set
 {
 public:
     // types
@@ -725,7 +725,7 @@
 
 template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
           class _Alloc = allocator<_Value> >
-class _LIBCPP_VISIBLE unordered_multiset
+class _LIBCPP_TYPE_VIS unordered_multiset
 {
 public:
     // types

Modified: trunk/contrib/libc++/include/utility
===================================================================
--- trunk/contrib/libc++/include/utility	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/utility	2016-01-07 17:22:14 UTC (rev 7405)
@@ -117,6 +117,27 @@
     typename tuple_element<I, std::pair<T1, T2> >::type&&
     get(std::pair<T1, T2>&&) noexcept;
 
+// C++14
+
+template<class T, T... I>
+struct integer_sequence
+{
+    typedef T value_type;
+
+    static constexpr size_t size() noexcept;
+};
+
+template<size_t... I>
+  using index_sequence = integer_sequence<size_t, I...>;
+
+template<class T, T N>
+  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
+template<size_t N>
+  using make_index_sequence = make_integer_sequence<size_t, N>;
+
+template<class... T>
+  using index_sequence_for = make_index_sequence<sizeof...(T)>;
+
 }  // std
 
 */
@@ -205,7 +226,7 @@
     return _VSTD::move(__x);
 }
 
-struct _LIBCPP_VISIBLE piecewise_construct_t { };
+struct _LIBCPP_TYPE_VIS piecewise_construct_t { };
 #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
 extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
 #else
@@ -213,7 +234,7 @@
 #endif
 
 template <class _T1, class _T2>
-struct _LIBCPP_VISIBLE pair
+struct _LIBCPP_TYPE_VIS pair
 {
     typedef _T1 first_type;
     typedef _T2 second_type;
@@ -233,8 +254,8 @@
         _LIBCPP_INLINE_VISIBILITY
         pair(const pair<_U1, _U2>& __p
 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
-                 ,typename enable_if<is_constructible<_T1, _U1>::value &&
-                                    is_constructible<_T2, _U2>::value>::type* = 0
+                 ,typename enable_if<is_convertible<const _U1&, _T1>::value &&
+                                    is_convertible<const _U2&, _T2>::value>::type* = 0
 #endif
                                       )
             : first(__p.first), second(__p.second) {}
@@ -261,8 +282,8 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     template <class _U1, class _U2,
-              class = typename enable_if<is_constructible<first_type, _U1 >::value &&
-                                         is_constructible<second_type, _U2>::value>::type>
+              class = typename enable_if<is_convertible<_U1, first_type>::value &&
+                                         is_convertible<_U2, second_type>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
         pair(_U1&& __u1, _U2&& __u2)
             : first(_VSTD::forward<_U1>(__u1)),
@@ -272,8 +293,8 @@
     template<class _U1, class _U2>
         _LIBCPP_INLINE_VISIBILITY
         pair(pair<_U1, _U2>&& __p,
-                 typename enable_if<is_constructible<_T1, _U1>::value &&
-                                    is_constructible<_T2, _U2>::value>::type* = 0)
+                 typename enable_if<is_convertible<_U1, _T1>::value &&
+                                    is_convertible<_U2, _T2>::value>::type* = 0)
             : first(_VSTD::forward<_U1>(__p.first)),
               second(_VSTD::forward<_U2>(__p.second)) {}
 
@@ -419,7 +440,7 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-template <class _Tp> class reference_wrapper;
+template <class _Tp> class _LIBCPP_TYPE_VIS reference_wrapper;
 
 template <class _Tp>
 struct ___make_pair_return
@@ -460,18 +481,16 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
 template <class _T1, class _T2>
-  class _LIBCPP_VISIBLE tuple_size<pair<_T1, _T2> >
+  class _LIBCPP_TYPE_VIS tuple_size<pair<_T1, _T2> >
     : public integral_constant<size_t, 2> {};
 
 template <class _T1, class _T2>
-  class _LIBCPP_VISIBLE tuple_size<const pair<_T1, _T2> >
+  class _LIBCPP_TYPE_VIS tuple_size<const pair<_T1, _T2> >
     : public integral_constant<size_t, 2> {};
 
 template <class _T1, class _T2>
-class _LIBCPP_VISIBLE tuple_element<0, pair<_T1, _T2> >
+class _LIBCPP_TYPE_VIS tuple_element<0, pair<_T1, _T2> >
 {
 public:
     typedef _T1 type;
@@ -478,7 +497,7 @@
 };
 
 template <class _T1, class _T2>
-class _LIBCPP_VISIBLE tuple_element<1, pair<_T1, _T2> >
+class _LIBCPP_TYPE_VIS tuple_element<1, pair<_T1, _T2> >
 {
 public:
     typedef _T2 type;
@@ -485,7 +504,7 @@
 };
 
 template <class _T1, class _T2>
-class _LIBCPP_VISIBLE tuple_element<0, const pair<_T1, _T2> >
+class _LIBCPP_TYPE_VIS tuple_element<0, const pair<_T1, _T2> >
 {
 public:
     typedef const _T1 type;
@@ -492,7 +511,7 @@
 };
 
 template <class _T1, class _T2>
-class _LIBCPP_VISIBLE tuple_element<1, const pair<_T1, _T2> >
+class _LIBCPP_TYPE_VIS tuple_element<1, const pair<_T1, _T2> >
 {
 public:
     typedef const _T2 type;
@@ -580,8 +599,92 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
+#if _LIBCPP_STD_VER > 11
 
+template<class _Tp, _Tp... _Ip>
+struct _LIBCPP_TYPE_VIS integer_sequence
+{
+    typedef _Tp value_type;
+    static_assert( is_integral<_Tp>::value,
+                  "std::integer_sequence can only be instantiated with an integral type" );
+    static
+    _LIBCPP_INLINE_VISIBILITY
+    constexpr
+    size_t
+    size() noexcept { return sizeof...(_Ip); }
+};
+
+template<size_t... _Ip>
+    using index_sequence = integer_sequence<size_t, _Ip...>;
+
+namespace __detail {
+
+template<typename _Tp, size_t ..._Extra> struct __repeat;
+template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> {
+  typedef integer_sequence<_Tp,
+                           _Np...,
+                           sizeof...(_Np) + _Np...,
+                           2 * sizeof...(_Np) + _Np...,
+                           3 * sizeof...(_Np) + _Np...,
+                           4 * sizeof...(_Np) + _Np...,
+                           5 * sizeof...(_Np) + _Np...,
+                           6 * sizeof...(_Np) + _Np...,
+                           7 * sizeof...(_Np) + _Np...,
+                           _Extra...> type;
+};
+
+template<size_t _Np> struct __parity;
+template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
+
+template<> struct __make<0> { typedef integer_sequence<size_t> type; };
+template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; };
+template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; };
+template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; };
+template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; };
+template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
+template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
+template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
+
+template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
+template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
+template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
+template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
+template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
+template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
+template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
+template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
+
+template<typename _Tp, typename _Up> struct __convert {
+  template<typename> struct __result;
+  template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; };
+};
+template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; };
+
+}
+
+template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
+  typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type;
+
+template <class _Tp, _Tp _Ep>
+struct __make_integer_sequence
+{
+    static_assert(is_integral<_Tp>::value,
+                  "std::make_integer_sequence can only be instantiated with an integral type" );
+    static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
+    typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
+};
+
+template<class _Tp, _Tp _Np>
+    using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
+
+template<size_t _Np>
+    using make_index_sequence = make_integer_sequence<size_t, _Np>;
+
+template<class... _Tp>
+    using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
+  
+#endif  // _LIBCPP_STD_VER > 11
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_UTILITY

Modified: trunk/contrib/libc++/include/valarray
===================================================================
--- trunk/contrib/libc++/include/valarray	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/valarray	2016-01-07 17:22:14 UTC (rev 7405)
@@ -29,7 +29,7 @@
     valarray(const value_type& x, size_t n);
     valarray(const value_type* px, size_t n);
     valarray(const valarray& v);
-    valarray(valarray&& v);
+    valarray(valarray&& v) noexcept;
     valarray(const slice_array<value_type>& sa);
     valarray(const gslice_array<value_type>& ga);
     valarray(const mask_array<value_type>& ma);
@@ -39,7 +39,7 @@
 
     // assignment:
     valarray& operator=(const valarray& v);
-    valarray& operator=(valarray&& v);
+    valarray& operator=(valarray&& v) noexcept;
     valarray& operator=(initializer_list<value_type> il);
     valarray& operator=(const value_type& x);
     valarray& operator=(const slice_array<value_type>& sa);
@@ -91,7 +91,7 @@
     valarray& operator>>=(const valarray& v);
 
     // member functions:
-    void swap(valarray& v);
+    void swap(valarray& v) noexcept;
 
     size_t size() const;
 
@@ -231,7 +231,7 @@
     indirect_array() = delete;
 };
 
-template<class T> void swap(valarray<T>& x, valarray<T>& y);
+template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
 
 template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
 template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
@@ -354,9 +354,9 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template<class _Tp> class valarray;
+template<class _Tp> class _LIBCPP_TYPE_VIS valarray;
 
-class _LIBCPP_VISIBLE slice
+class _LIBCPP_TYPE_VIS slice
 {
     size_t __start_;
     size_t __size_;
@@ -381,25 +381,29 @@
     _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
 };
 
-template <class _Tp> class slice_array;
-class gslice;
-template <class _Tp> class gslice_array;
-template <class _Tp> class mask_array;
-template <class _Tp> class indirect_array;
+template <class _Tp> class _LIBCPP_TYPE_VIS slice_array;
+class _LIBCPP_TYPE_VIS gslice;
+template <class _Tp> class _LIBCPP_TYPE_VIS gslice_array;
+template <class _Tp> class _LIBCPP_TYPE_VIS mask_array;
+template <class _Tp> class _LIBCPP_TYPE_VIS indirect_array;
 
 template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
 _Tp*
 begin(valarray<_Tp>& __v);
 
 template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
 const _Tp*
 begin(const valarray<_Tp>& __v);
 
 template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
 _Tp*
 end(valarray<_Tp>& __v);
 
 template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
 const _Tp*
 end(const valarray<_Tp>& __v);
 
@@ -667,7 +671,7 @@
     _LIBCPP_INLINE_VISIBILITY
     size_t size() const {return __size_;}
 
-    template <class> friend class _LIBCPP_VISIBLE valarray;
+    template <class> friend class _LIBCPP_TYPE_VIS valarray;
 };
 
 template <class _ValExpr>
@@ -782,7 +786,7 @@
 struct __is_val_expr<valarray<_Tp> > : true_type {};
 
 template<class _Tp>
-class _LIBCPP_VISIBLE valarray
+class _LIBCPP_TYPE_VIS valarray
 {
 public:
     typedef _Tp value_type;
@@ -801,7 +805,7 @@
     valarray(const value_type* __p, size_t __n);
     valarray(const valarray& __v);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    valarray(valarray&& __v);
+    valarray(valarray&& __v) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     valarray(initializer_list<value_type> __il);
@@ -815,7 +819,7 @@
     // assignment:
     valarray& operator=(const valarray& __v);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    valarray& operator=(valarray&& __v);
+    valarray& operator=(valarray&& __v) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     valarray& operator=(initializer_list<value_type>);
@@ -956,7 +960,7 @@
     operator>>= (const _Expr& __v);
 
     // member functions:
-    void swap(valarray& __v);
+    void swap(valarray& __v) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
@@ -972,12 +976,12 @@
     void     resize(size_t __n, value_type __x = value_type());
 
 private:
-    template <class> friend class _LIBCPP_VISIBLE valarray;
-    template <class> friend class _LIBCPP_VISIBLE slice_array;
-    template <class> friend class _LIBCPP_VISIBLE gslice_array;
-    template <class> friend class _LIBCPP_VISIBLE mask_array;
+    template <class> friend class _LIBCPP_TYPE_VIS valarray;
+    template <class> friend class _LIBCPP_TYPE_VIS slice_array;
+    template <class> friend class _LIBCPP_TYPE_VIS gslice_array;
+    template <class> friend class _LIBCPP_TYPE_VIS mask_array;
     template <class> friend class __mask_expr;
-    template <class> friend class _LIBCPP_VISIBLE indirect_array;
+    template <class> friend class _LIBCPP_TYPE_VIS indirect_array;
     template <class> friend class __indirect_expr;
     template <class> friend class __val_expr;
 
@@ -1087,7 +1091,7 @@
 // slice_array
 
 template <class _Tp>
-class _LIBCPP_VISIBLE slice_array
+class _LIBCPP_TYPE_VIS slice_array
 {
 public:
     typedef _Tp value_type;
@@ -1390,7 +1394,7 @@
 
 // gslice
 
-class _LIBCPP_VISIBLE gslice
+class _LIBCPP_TYPE_VIS gslice
 {
     valarray<size_t> __size_;
     valarray<size_t> __stride_;
@@ -1457,7 +1461,7 @@
 // gslice_array
 
 template <class _Tp>
-class _LIBCPP_VISIBLE gslice_array
+class _LIBCPP_TYPE_VIS gslice_array
 {
 public:
     typedef _Tp value_type;
@@ -1786,7 +1790,7 @@
 // mask_array
 
 template <class _Tp>
-class _LIBCPP_VISIBLE mask_array
+class _LIBCPP_TYPE_VIS mask_array
 {
 public:
     typedef _Tp value_type;
@@ -2130,7 +2134,7 @@
 // indirect_array
 
 template <class _Tp>
-class _LIBCPP_VISIBLE indirect_array
+class _LIBCPP_TYPE_VIS indirect_array
 {
 public:
     typedef _Tp value_type;
@@ -2481,7 +2485,7 @@
     _LIBCPP_INLINE_VISIBILITY
     size_t size() const {return __1d_.size();}
 
-    template <class> friend class _LIBCPP_VISIBLE valarray;
+    template <class> friend class _LIBCPP_TYPE_VIS valarray;
 };
 
 template<class _ValExpr>
@@ -2709,7 +2713,7 @@
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-valarray<_Tp>::valarray(valarray&& __v)
+valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
     : __begin_(__v.__begin_),
       __end_(__v.__end_)
 {
@@ -2886,7 +2890,7 @@
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
-valarray<_Tp>::operator=(valarray&& __v)
+valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
 {
     resize(0);
     __begin_ = __v.__begin_;
@@ -3446,7 +3450,7 @@
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-valarray<_Tp>::swap(valarray& __v)
+valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
 {
     _VSTD::swap(__begin_, __v.__begin_);
     _VSTD::swap(__end_, __v.__end_);
@@ -3613,7 +3617,7 @@
 template<class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
+swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
 {
     __x.swap(__y);
 }
@@ -4766,9 +4770,9 @@
     return __v.__end_;
 }
 
-extern template valarray<size_t>::valarray(size_t);
-extern template valarray<size_t>::~valarray();
-extern template void valarray<size_t>::resize(size_t, size_t);
+_LIBCPP_EXTERN_TEMPLATE(valarray<size_t>::valarray(size_t))
+_LIBCPP_EXTERN_TEMPLATE(valarray<size_t>::~valarray())
+_LIBCPP_EXTERN_TEMPLATE(void valarray<size_t>::resize(size_t, size_t))
 
 _LIBCPP_END_NAMESPACE_STD
 

Modified: trunk/contrib/libc++/include/vector
===================================================================
--- trunk/contrib/libc++/include/vector	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/include/vector	2016-01-07 17:22:14 UTC (rev 7405)
@@ -313,7 +313,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _MSC_VER
-extern template class __vector_base_common<true>;
+_LIBCPP_EXTERN_TEMPLATE(class __vector_base_common<true>)
 #ifdef _MSC_VER
 #pragma warning( pop )
 #endif // _MSC_VER
@@ -365,12 +365,7 @@
         {return static_cast<size_type>(__end_cap() - __begin_);}
 
     _LIBCPP_INLINE_VISIBILITY
-    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
-        {__destruct_at_end(__new_last, false_type());}
-    _LIBCPP_INLINE_VISIBILITY
-    void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
-    void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
+    void __destruct_at_end(pointer __new_last) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     void __copy_assign_alloc(const __vector_base& __c)
@@ -437,27 +432,19 @@
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 void
-__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
+__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
 {
     while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
 }
 
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
-void
-__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
-{
-    __end_ = const_cast<pointer>(__new_last);
-}
-
-template <class _Tp, class _Allocator>
-_LIBCPP_INLINE_VISIBILITY inline
 __vector_base<_Tp, _Allocator>::__vector_base()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-    : __begin_(0),
-      __end_(0),
-      __end_cap_(0)
+    : __begin_(nullptr),
+      __end_(nullptr),
+      __end_cap_(nullptr)
 {
 }
 
@@ -464,9 +451,9 @@
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
-    : __begin_(0),
-      __end_(0),
-      __end_cap_(0, __a)
+    : __begin_(nullptr),
+      __end_(nullptr),
+      __end_cap_(nullptr, __a)
 {
 }
 
@@ -473,7 +460,7 @@
 template <class _Tp, class _Allocator>
 __vector_base<_Tp, _Allocator>::~__vector_base()
 {
-    if (__begin_ != 0)
+    if (__begin_ != nullptr)
     {
         clear();
         __alloc_traits::deallocate(__alloc(), __begin_, capacity());
@@ -481,7 +468,7 @@
 }
 
 template <class _Tp, class _Allocator = allocator<_Tp> >
-class _LIBCPP_VISIBLE vector
+class _LIBCPP_TYPE_VIS vector
     : private __vector_base<_Tp, _Allocator>
 {
 private:
@@ -502,6 +489,9 @@
     typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
     typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
 
+    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
+                  "Allocator::value_type must be same type as value_type");
+
     _LIBCPP_INLINE_VISIBILITY
     vector()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
@@ -523,17 +513,29 @@
     template <class _InputIterator>
         vector(_InputIterator __first, _InputIterator __last,
                typename enable_if<__is_input_iterator  <_InputIterator>::value &&
-                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+                                 !__is_forward_iterator<_InputIterator>::value &&
+                                 is_constructible<
+                                    value_type,
+                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
     template <class _InputIterator>
         vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
                typename enable_if<__is_input_iterator  <_InputIterator>::value &&
-                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+                                 !__is_forward_iterator<_InputIterator>::value &&
+                                 is_constructible<
+                                    value_type,
+                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
     template <class _ForwardIterator>
         vector(_ForwardIterator __first, _ForwardIterator __last,
-               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
+                                 is_constructible<
+                                    value_type,
+                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
     template <class _ForwardIterator>
         vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
-               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
+                                 is_constructible<
+                                    value_type,
+                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
     vector(initializer_list<value_type> __il);
@@ -574,7 +576,10 @@
         typename enable_if
         <
              __is_input_iterator  <_InputIterator>::value &&
-            !__is_forward_iterator<_InputIterator>::value,
+            !__is_forward_iterator<_InputIterator>::value &&
+            is_constructible<
+                 value_type,
+                 typename iterator_traits<_InputIterator>::reference>::value,
             void
         >::type
         assign(_InputIterator __first, _InputIterator __last);
@@ -581,7 +586,10 @@
     template <class _ForwardIterator>
         typename enable_if
         <
-            __is_forward_iterator<_ForwardIterator>::value,
+            __is_forward_iterator<_ForwardIterator>::value &&
+            is_constructible<
+                 value_type,
+                 typename iterator_traits<_ForwardIterator>::reference>::value,
             void
         >::type
         assign(_ForwardIterator __first, _ForwardIterator __last);
@@ -697,7 +705,10 @@
         typename enable_if
         <
              __is_input_iterator  <_InputIterator>::value &&
-            !__is_forward_iterator<_InputIterator>::value,
+            !__is_forward_iterator<_InputIterator>::value &&
+            is_constructible<
+                 value_type,
+                 typename iterator_traits<_InputIterator>::reference>::value,
             iterator
         >::type
         insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
@@ -704,7 +715,10 @@
     template <class _ForwardIterator>
         typename enable_if
         <
-            __is_forward_iterator<_ForwardIterator>::value,
+            __is_forward_iterator<_ForwardIterator>::value &&
+            is_constructible<
+                 value_type,
+                 typename iterator_traits<_ForwardIterator>::reference>::value,
             iterator
         >::type
         insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
@@ -770,7 +784,7 @@
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
     void __move_assign(vector& __c, false_type);
     _LIBCPP_INLINE_VISIBILITY
-    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
+    void __destruct_at_end(pointer __new_last) _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __c_node* __c = __get_db()->__find_c_and_lock(this);
@@ -851,11 +865,11 @@
 void
 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
 {
-    if (this->__begin_ != 0)
+    if (this->__begin_ != nullptr)
     {
         clear();
         __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
-        this->__begin_ = this->__end_ = this->__end_cap() = 0;
+        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
     }
 }
 
@@ -1031,7 +1045,10 @@
 template <class _InputIterator>
 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
        typename enable_if<__is_input_iterator  <_InputIterator>::value &&
-                         !__is_forward_iterator<_InputIterator>::value>::type*)
+                         !__is_forward_iterator<_InputIterator>::value &&
+                         is_constructible<
+                            value_type,
+                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->__insert_c(this);
@@ -1044,7 +1061,10 @@
 template <class _InputIterator>
 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
        typename enable_if<__is_input_iterator  <_InputIterator>::value &&
-                         !__is_forward_iterator<_InputIterator>::value>::type*)
+                         !__is_forward_iterator<_InputIterator>::value &&
+                         is_constructible<
+                            value_type,
+                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
     : __base(__a)
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1057,7 +1077,10 @@
 template <class _Tp, class _Allocator>
 template <class _ForwardIterator>
 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
-                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
+                                is_constructible<
+                                   value_type,
+                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->__insert_c(this);
@@ -1073,7 +1096,10 @@
 template <class _Tp, class _Allocator>
 template <class _ForwardIterator>
 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
-                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
+                                is_constructible<
+                                   value_type,
+                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
     : __base(__a)
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1132,7 +1158,7 @@
     this->__begin_ = __x.__begin_;
     this->__end_ = __x.__end_;
     this->__end_cap() = __x.__end_cap();
-    __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
+    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
 }
 
 template <class _Tp, class _Allocator>
@@ -1255,7 +1281,10 @@
 typename enable_if
 <
      __is_input_iterator  <_InputIterator>::value &&
-    !__is_forward_iterator<_InputIterator>::value,
+    !__is_forward_iterator<_InputIterator>::value &&
+    is_constructible<
+       _Tp,
+       typename iterator_traits<_InputIterator>::reference>::value,
     void
 >::type
 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
@@ -1269,7 +1298,10 @@
 template <class _ForwardIterator>
 typename enable_if
 <
-    __is_forward_iterator<_ForwardIterator>::value,
+    __is_forward_iterator<_ForwardIterator>::value &&
+    is_constructible<
+       _Tp,
+       typename iterator_traits<_ForwardIterator>::reference>::value,
     void
 >::type
 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
@@ -1458,7 +1490,8 @@
     allocator_type& __a = this->__alloc();
     __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
     // __v.push_back(_VSTD::forward<_Up>(__x));
-    __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_++), _VSTD::forward<_Up>(__x));
+    __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
+    __v.__end_++;
     __swap_out_circular_buffer(__v);
 }
 
@@ -1505,7 +1538,8 @@
     allocator_type& __a = this->__alloc();
     __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
 //    __v.emplace_back(_VSTD::forward<_Args>(__args)...);
-    __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_++), _VSTD::forward<_Args>(__args)...);
+    __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
+    __v.__end_++;
     __swap_out_circular_buffer(__v);
 }
 
@@ -1548,7 +1582,10 @@
         "vector::erase(iterator) called with an iterator not"
         " referring to this vector");
 #endif
-    pointer __p = const_cast<pointer>(&*__position);
+    _LIBCPP_ASSERT(__position != end(),
+        "vector::erase(iterator) called with a non-dereferenceable iterator");
+    difference_type __ps = __position - cbegin();
+    pointer __p = this->__begin_ + __ps;
     iterator __r = __make_iter(__p);
     this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
     return __r;
@@ -1566,7 +1603,8 @@
     _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
     pointer __p = this->__begin_ + (__first - begin());
     iterator __r = __make_iter(__p);
-    this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
+    if (__first != __last)
+        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
     return __r;
 }
 
@@ -1681,8 +1719,9 @@
         }
         else
         {
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);
             __move_range(__p, this->__end_, __p + 1);
-            *__p = value_type(_VSTD::forward<_Args>(__args)...);
+            *__p = _VSTD::move(__tmp);
         }
     }
     else
@@ -1745,7 +1784,10 @@
 typename enable_if
 <
      __is_input_iterator  <_InputIterator>::value &&
-    !__is_forward_iterator<_InputIterator>::value,
+    !__is_forward_iterator<_InputIterator>::value &&
+    is_constructible<
+       _Tp,
+       typename iterator_traits<_InputIterator>::reference>::value,
     typename vector<_Tp, _Allocator>::iterator
 >::type
 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
@@ -1797,7 +1839,10 @@
 template <class _ForwardIterator>
 typename enable_if
 <
-    __is_forward_iterator<_ForwardIterator>::value,
+    __is_forward_iterator<_ForwardIterator>::value &&
+    is_constructible<
+       _Tp,
+       typename iterator_traits<_ForwardIterator>::reference>::value,
     typename vector<_Tp, _Allocator>::iterator
 >::type
 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
@@ -1886,9 +1931,9 @@
 bool
 vector<_Tp, _Allocator>::__invariants() const
 {
-    if (this->__begin_ == 0)
+    if (this->__begin_ == nullptr)
     {
-        if (this->__end_ != 0 || this->__end_cap() != 0)
+        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
             return false;
     }
     else
@@ -1960,7 +2005,7 @@
 };
 
 template <class _Allocator>
-class _LIBCPP_VISIBLE vector<bool, _Allocator>
+class _LIBCPP_TYPE_VIS vector<bool, _Allocator>
     : private __vector_base_common<true>
 {
 public:
@@ -1970,6 +2015,7 @@
     typedef allocator_traits<allocator_type>         __alloc_traits;
     typedef typename __alloc_traits::size_type       size_type;
     typedef typename __alloc_traits::difference_type difference_type;
+    typedef size_type __storage_type;
     typedef __bit_iterator<vector, false>            pointer;
     typedef __bit_iterator<vector, true>             const_pointer;
 #ifdef _LIBCPP_DEBUG
@@ -1991,7 +2037,6 @@
     typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
 
 private:
-    typedef size_type __storage_type;
     typedef typename __alloc_traits::template
 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
                 rebind_alloc<__storage_type>
@@ -2250,7 +2295,7 @@
         {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
     _LIBCPP_INLINE_VISIBILITY
     iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
-        {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
+        {return begin() + (__p - cbegin());}
 #endif  // _LIBCPP_DEBUG
 
     _LIBCPP_INLINE_VISIBILITY
@@ -2317,8 +2362,8 @@
     friend class __bit_const_reference<vector>;
     friend class __bit_iterator<vector, false>;
     friend class __bit_iterator<vector, true>;
-    friend class __bit_array<vector>;
-    friend struct _LIBCPP_VISIBLE hash<vector>;
+    friend struct __bit_array<vector>;
+    friend struct _LIBCPP_TYPE_VIS hash<vector>;
 };
 
 template <class _Allocator>
@@ -2357,11 +2402,11 @@
 void
 vector<bool, _Allocator>::deallocate() _NOEXCEPT
 {
-    if (this->__begin_ != 0)
+    if (this->__begin_ != nullptr)
     {
         __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
         __invalidate_all_iterators();
-        this->__begin_ = 0;
+        this->__begin_ = nullptr;
         this->__size_ = this->__cap() = 0;
     }
 }
@@ -2424,7 +2469,7 @@
 _LIBCPP_INLINE_VISIBILITY inline
 vector<bool, _Allocator>::vector()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2433,7 +2478,7 @@
 template <class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 vector<bool, _Allocator>::vector(const allocator_type& __a)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
@@ -2441,7 +2486,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(size_type __n)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2454,7 +2499,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2467,7 +2512,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
@@ -2483,7 +2528,7 @@
 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
        typename enable_if<__is_input_iterator  <_InputIterator>::value &&
                          !__is_forward_iterator<_InputIterator>::value>::type*)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2497,7 +2542,7 @@
     }
     catch (...)
     {
-        if (__begin_ != 0)
+        if (__begin_ != nullptr)
             __storage_traits::deallocate(__alloc(), __begin_, __cap());
         __invalidate_all_iterators();
         throw;
@@ -2510,7 +2555,7 @@
 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
        typename enable_if<__is_input_iterator  <_InputIterator>::value &&
                          !__is_forward_iterator<_InputIterator>::value>::type*)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
@@ -2524,7 +2569,7 @@
     }
     catch (...)
     {
-        if (__begin_ != 0)
+        if (__begin_ != nullptr)
             __storage_traits::deallocate(__alloc(), __begin_, __cap());
         __invalidate_all_iterators();
         throw;
@@ -2536,7 +2581,7 @@
 template <class _ForwardIterator>
 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
                                 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2552,7 +2597,7 @@
 template <class _ForwardIterator>
 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
                                 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
@@ -2568,7 +2613,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0)
 {
@@ -2582,7 +2627,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, static_cast<__storage_allocator>(__a))
 {
@@ -2599,7 +2644,7 @@
 template <class _Allocator>
 vector<bool, _Allocator>::~vector()
 {
-    if (__begin_ != 0)
+    if (__begin_ != nullptr)
         __storage_traits::deallocate(__alloc(), __begin_, __cap());
 #ifdef _LIBCPP_DEBUG
     __invalidate_all_iterators();
@@ -2608,7 +2653,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(const vector& __v)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
 {
@@ -2621,7 +2666,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __a)
 {
@@ -2663,7 +2708,7 @@
       __size_(__v.__size_),
       __cap_alloc_(__v.__cap_alloc_)
 {
-    __v.__begin_ = 0;
+    __v.__begin_ = nullptr;
     __v.__size_ = 0;
     __v.__cap() = 0;
 }
@@ -2670,7 +2715,7 @@
 
 template <class _Allocator>
 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
-    : __begin_(0),
+    : __begin_(nullptr),
       __size_(0),
       __cap_alloc_(0, __a)
 {
@@ -2699,6 +2744,7 @@
 {
     __move_assign(__v, integral_constant<bool,
           __storage_traits::propagate_on_container_move_assignment::value>());
+    return *this;
 }
 
 template <class _Allocator>
@@ -3065,7 +3111,7 @@
 bool
 vector<bool, _Allocator>::__invariants() const
 {
-    if (this->__begin_ == 0)
+    if (this->__begin_ == nullptr)
     {
         if (this->__size_ != 0 || this->__cap() != 0)
             return false;
@@ -3100,7 +3146,7 @@
 }
 
 template <class _Allocator>
-struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
+struct _LIBCPP_TYPE_VIS hash<vector<bool, _Allocator> >
     : public unary_function<vector<bool, _Allocator>, size_t>
 {
     _LIBCPP_INLINE_VISIBILITY

Modified: trunk/contrib/libc++/src/chrono.cpp
===================================================================
--- trunk/contrib/libc++/src/chrono.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/chrono.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -9,7 +9,7 @@
 
 #include "chrono"
 #include <sys/time.h>        //for gettimeofday and timeval
-#if __APPLE__
+#ifdef __APPLE__
 #include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
 #else  /* !__APPLE__ */
 #include <cerrno>  // errno
@@ -24,6 +24,8 @@
 
 // system_clock
 
+const bool system_clock::is_steady;
+
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
@@ -46,7 +48,9 @@
 
 // steady_clock
 
-#if __APPLE__
+const bool steady_clock::is_steady;
+
+#ifdef __APPLE__
 //   mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
 //   nanoseconds since the computer booted up.  MachInfo.numer and MachInfo.denom
 //   are run time constants supplied by the OS.  This clock has no relationship

Modified: trunk/contrib/libc++/src/condition_variable.cpp
===================================================================
--- trunk/contrib/libc++/src/condition_variable.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/condition_variable.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -20,13 +20,13 @@
 }
 
 void
-condition_variable::notify_one()
+condition_variable::notify_one() _NOEXCEPT
 {
     pthread_cond_signal(&__cv_);
 }
 
 void
-condition_variable::notify_all()
+condition_variable::notify_all() _NOEXCEPT
 {
     pthread_cond_broadcast(&__cv_);
 }
@@ -51,10 +51,22 @@
         __throw_system_error(EPERM,
                             "condition_variable::timed wait: mutex not locked");
     nanoseconds d = tp.time_since_epoch();
+    if (d > nanoseconds(0x59682F000000E941))
+        d = nanoseconds(0x59682F000000E941);
     timespec ts;
     seconds s = duration_cast<seconds>(d);
-    ts.tv_sec = static_cast<decltype(ts.tv_sec)>(s.count());
-    ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+    typedef decltype(ts.tv_sec) ts_sec;
+    _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
+    if (s.count() < ts_sec_max)
+    {
+        ts.tv_sec = static_cast<ts_sec>(s.count());
+        ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+    }
+    else
+    {
+        ts.tv_sec = ts_sec_max;
+        ts.tv_nsec = giga::num - 1;
+    }
     int ec = pthread_cond_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
     if (ec != 0 && ec != ETIMEDOUT)
         __throw_system_error(ec, "condition_variable timed_wait failed");

Modified: trunk/contrib/libc++/src/debug.cpp
===================================================================
--- trunk/contrib/libc++/src/debug.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/debug.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -17,15 +17,15 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
 __libcpp_db*
 __get_db()
 {
     static __libcpp_db db;
     return &db;
-};
+}
 
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
 const __libcpp_db*
 __get_const_db()
 {
@@ -110,8 +110,7 @@
 {
     RLock _(mut());
     __i_node* i = __find_iterator(__i);
-    _LIBCPP_ASSERT(i != nullptr, "iterator constructed in translation unit with debug mode not enabled."
-                   "  #define _LIBCPP_DEBUG2 1 for that translation unit.");
+    _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
     return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
 }
 
@@ -144,9 +143,13 @@
     if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
     {
         size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
-        __c_node** cbeg = (__c_node**)calloc(nc, sizeof(void*));
+        __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*)));
         if (cbeg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
             throw bad_alloc();
+#else
+            abort();
+#endif
         for (__c_node** p = __cbeg_; p != __cend_; ++p)
         {
             __c_node* q = *p;
@@ -165,9 +168,14 @@
     }
     size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
     __c_node* p = __cbeg_[hc];
-    __c_node* r = __cbeg_[hc] = (__c_node*)malloc(sizeof(__c_node));
+    __c_node* r = __cbeg_[hc] =
+      static_cast<__c_node*>(malloc(sizeof(__c_node)));
     if (__cbeg_[hc] == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
         throw bad_alloc();
+#else
+        abort();
+#endif
     r->__c_ = __c;
     r->__next_ = p;
     ++__csz_;
@@ -294,7 +302,7 @@
     __i_node* i = __find_iterator(__i);
     __i_node* i0 = __find_iterator(__i0);
     __c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
-    if (i == nullptr && c0 != nullptr)
+    if (i == nullptr && i0 != nullptr)
         i = __insert_iterator(__i);
     __c_node* c = i != nullptr ? i->__c_ : nullptr;
     if (c != c0)
@@ -400,9 +408,14 @@
         size_t nc = 2*static_cast<size_t>(cap_ - beg_);
         if (nc == 0)
             nc = 1;
-        __i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
+        __i_node** beg =
+           static_cast<__i_node**>(malloc(nc * sizeof(__i_node*)));
         if (beg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
             throw bad_alloc();
+#else
+            abort();
+#endif
         if (nc > 1)
             memcpy(beg, beg_, nc/2*sizeof(__i_node*));
         free(beg_);
@@ -422,9 +435,13 @@
     if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_))
     {
         size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
-        __i_node** ibeg = (__i_node**)calloc(nc, sizeof(void*));
+        __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*)));
         if (ibeg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
             throw bad_alloc();
+#else
+            abort();
+#endif
         for (__i_node** p = __ibeg_; p != __iend_; ++p)
         {
             __i_node* q = *p;
@@ -443,9 +460,14 @@
     }
     size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
     __i_node* p = __ibeg_[hi];
-    __i_node* r = __ibeg_[hi] = (__i_node*)malloc(sizeof(__i_node));
+    __i_node* r = __ibeg_[hi] =
+      static_cast<__i_node*>(malloc(sizeof(__i_node)));
     if (r == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
         throw bad_alloc();
+#else
+        abort();
+#endif
     ::new(r) __i_node(__i, p, nullptr);
     ++__isz_;
     return r;

Modified: trunk/contrib/libc++/src/exception.cpp
===================================================================
--- trunk/contrib/libc++/src/exception.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/exception.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -10,7 +10,11 @@
 
 #include "exception"
 
-#if __APPLE__
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
+#ifdef __APPLE__
   #include <cxxabi.h>
 
   using namespace __cxxabiv1;
@@ -23,19 +27,21 @@
     #define __terminate_handler  __cxxabiapple::__cxa_terminate_handler
     #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
   #endif  // _LIBCPPABI_VERSION
-#elif defined(LIBCXXRT)
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
   #include <cxxabi.h>
   using namespace __cxxabiv1;
-  #define HAVE_DEPENDENT_EH_ABI 1
-#else  // __APPLE__
+  #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION)
+    #define HAVE_DEPENDENT_EH_ABI 1
+  #endif
+#elif !defined(__GLIBCXX__) // __has_include(<cxxabi.h>)
   static std::terminate_handler  __terminate_handler;
   static std::unexpected_handler __unexpected_handler;
-#endif  // __APPLE__
+#endif // __has_include(<cxxabi.h>)
 
 namespace std
 {
 
-#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
+#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__)
 
 // libcxxrt provides implementations of these functions itself.
 unexpected_handler
@@ -50,7 +56,7 @@
     return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
 }
 
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
 void
 unexpected()
 {
@@ -71,7 +77,8 @@
     return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
 }
 
-_ATTRIBUTE(noreturn)
+#ifndef EMSCRIPTEN // We provide this in JS
+_LIBCPP_NORETURN
 void
 terminate() _NOEXCEPT
 {
@@ -91,17 +98,15 @@
     }
 #endif  // _LIBCPP_NO_EXCEPTIONS
 }
+#endif // !EMSCRIPTEN
 #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
 
-#ifndef LIBCXXRT
+#if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(EMSCRIPTEN)
 bool uncaught_exception() _NOEXCEPT
 {
-#if __APPLE__
+#if defined(__APPLE__) || defined(_LIBCPPABI_VERSION)
     // on Darwin, there is a helper function so __cxa_get_globals is private
     return __cxa_uncaught_exception();
-#elif LIBCXXRT
-    __cxa_eh_globals * globals = __cxa_get_globals();
-    return (globals->uncaughtExceptions != 0);
 #else  // __APPLE__
     #warning uncaught_exception not yet implemented
     ::abort();
@@ -121,7 +126,7 @@
 
 #endif  // _LIBCPPABI_VERSION
 #endif //LIBCXXRT
-#ifndef _LIBCPPABI_VERSION
+#if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__)
 
 bad_exception::~bad_exception() _NOEXCEPT
 {
@@ -181,7 +186,7 @@
 {
 }
 
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
 void
 nested_exception::rethrow_nested() const
 {
@@ -206,7 +211,7 @@
 #endif  // __APPLE__
 }
 
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
 void rethrow_exception(exception_ptr p)
 {
 #if HAVE_DEPENDENT_EH_ABI

Modified: trunk/contrib/libc++/src/future.cpp
===================================================================
--- trunk/contrib/libc++/src/future.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/future.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -47,7 +47,7 @@
 }
 
 const error_category&
-future_category()
+future_category() _NOEXCEPT
 {
     static __future_error_category __f;
     return __f;
@@ -78,8 +78,8 @@
         throw future_error(make_error_code(future_errc::promise_already_satisfied));
 #endif
     __state_ |= __constructed | ready;
+    __cv_.notify_all();
     __lk.unlock();
-    __cv_.notify_all();
 }
 
 void

Modified: trunk/contrib/libc++/src/hash.cpp
===================================================================
--- trunk/contrib/libc++/src/hash.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/hash.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -10,7 +10,12 @@
 #include "__hash_table"
 #include "algorithm"
 #include "stdexcept"
+#include "type_traits"
 
+#ifdef __clang__
+#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace {
@@ -144,23 +149,29 @@
 // are fewer potential primes to search, and fewer potential primes to divide
 // against.
 
+template <size_t _Sz = sizeof(size_t)>
 inline _LIBCPP_INLINE_VISIBILITY
-void
-__check_for_overflow(size_t N, integral_constant<size_t, 32>)
+typename enable_if<_Sz == 4, void>::type
+__check_for_overflow(size_t N)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS 
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (N > 0xFFFFFFFB)
         throw overflow_error("__next_prime overflow");
+#else
+    (void)N;
 #endif
 }
 
+template <size_t _Sz = sizeof(size_t)>
 inline _LIBCPP_INLINE_VISIBILITY
-void
-__check_for_overflow(size_t N, integral_constant<size_t, 64>)
+typename enable_if<_Sz == 8, void>::type
+__check_for_overflow(size_t N)
 {
-#ifndef _LIBCPP_NO_EXCEPTIONS 
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (N > 0xFFFFFFFFFFFFFFC5ull)
         throw overflow_error("__next_prime overflow");
+#else
+    (void)N;
 #endif
 }
 
@@ -174,8 +185,7 @@
         return *std::lower_bound(small_primes, small_primes + N, n);
     // Else n > largest small_primes
     // Check for overflow
-    __check_for_overflow(n, integral_constant<size_t, 
-                                                   sizeof(n) * __CHAR_BIT__>());
+    __check_for_overflow(n);
     // Start searching list of potential primes: L * k0 + indices[in]
     const size_t M = sizeof(indices) / sizeof(indices[0]);
     // Select first potential prime >= n

Modified: trunk/contrib/libc++/src/ios.cpp
===================================================================
--- trunk/contrib/libc++/src/ios.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/ios.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -401,7 +401,7 @@
 }
 
 void
-ios_base::swap(ios_base& rhs)
+ios_base::swap(ios_base& rhs) _NOEXCEPT
 {
     _VSTD::swap(__fmtflags_, rhs.__fmtflags_);
     _VSTD::swap(__precision_, rhs.__precision_);

Modified: trunk/contrib/libc++/src/iostream.cpp
===================================================================
--- trunk/contrib/libc++/src/iostream.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/iostream.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -13,37 +13,39 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-alignas (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)];
-alignas (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
-alignas (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
-alignas (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)];
-alignas (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
-alignas (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
+static mbstate_t state_types[6] = {};
 
-alignas (istream) char cin [sizeof(istream)];
-alignas (ostream) char cout[sizeof(ostream)];
-alignas (ostream) char cerr[sizeof(ostream)];
-alignas (ostream) char clog[sizeof(ostream)];
-alignas (wistream) char wcin [sizeof(wistream)];
-alignas (wostream) char wcout[sizeof(wostream)];
-alignas (wostream) char wcerr[sizeof(wostream)];
-alignas (wostream) char wclog[sizeof(wostream)];
+_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)];
+_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
+_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
+_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)];
+_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
+_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
 
+_ALIGNAS_TYPE (istream) char cin [sizeof(istream)];
+_ALIGNAS_TYPE (ostream) char cout[sizeof(ostream)];
+_ALIGNAS_TYPE (ostream) char cerr[sizeof(ostream)];
+_ALIGNAS_TYPE (ostream) char clog[sizeof(ostream)];
+_ALIGNAS_TYPE (wistream) char wcin [sizeof(wistream)];
+_ALIGNAS_TYPE (wostream) char wcout[sizeof(wostream)];
+_ALIGNAS_TYPE (wostream) char wcerr[sizeof(wostream)];
+_ALIGNAS_TYPE (wostream) char wclog[sizeof(wostream)];
+
 ios_base::Init __start_std_streams;
 
 ios_base::Init::Init()
 {
-    istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin) );
-    ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout));
-    ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr));
+    istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin, state_types+0) );
+    ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1));
+    ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2));
                         ::new(clog) ostream(cerr_ptr->rdbuf());
     cin_ptr->tie(cout_ptr);
     _VSTD::unitbuf(*cerr_ptr);
     cerr_ptr->tie(cout_ptr);
 
-    wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin) );
-    wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout));
-    wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr));
+    wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin, state_types+3) );
+    wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4));
+    wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5));
                           ::new(wclog) wostream(wcerr_ptr->rdbuf());
     wcin_ptr->tie(wcout_ptr);
     _VSTD::unitbuf(*wcerr_ptr);
@@ -52,13 +54,13 @@
 
 ios_base::Init::~Init()
 {
-    ostream* cout_ptr = (ostream*)cout;
-    ostream* clog_ptr = (ostream*)clog;
+    ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
+    ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
     cout_ptr->flush();
     clog_ptr->flush();
 
-    wostream* wcout_ptr = (wostream*)wcout;
-    wostream* wclog_ptr = (wostream*)wclog;
+    wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
+    wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
     wcout_ptr->flush();
     wclog_ptr->flush();
 }

Modified: trunk/contrib/libc++/src/locale.cpp
===================================================================
--- trunk/contrib/libc++/src/locale.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/locale.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -25,7 +25,7 @@
 #include "cstring"
 #include "cwctype"
 #include "__sso_allocator"
-#if _WIN32
+#ifdef _WIN32
 #include <support/win32/locale_win32.h>
 #else // _WIN32
 #include <langinfo.h>
@@ -32,6 +32,10 @@
 #endif // _!WIN32
 #include <stdlib.h>
 
+// On Linux, wint_t and wchar_t have different signed-ness, and this causes
+// lots of noise in the build log, but no bugs that I know of. 
+#pragma clang diagnostic ignored "-Wsign-conversion"
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifdef __cloc_defined
@@ -81,8 +85,35 @@
     return *(T*)&buf;
 }
 
+template <typename T, size_t N>
+inline
+_LIBCPP_CONSTEXPR
+size_t
+countof(const T (&)[N])
+{
+    return N;
 }
 
+template <typename T>
+inline
+_LIBCPP_CONSTEXPR
+size_t
+countof(const T * const begin, const T * const end)
+{
+    return static_cast<size_t>(end - begin);
+}
+
+}
+
+const locale::category locale::none;
+const locale::category locale::collate;
+const locale::category locale::ctype;
+const locale::category locale::monetary;
+const locale::category locale::numeric;
+const locale::category locale::time;
+const locale::category locale::messages;
+const locale::category locale::all;
+
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wpadded"
 
@@ -197,6 +228,13 @@
 #endif  // _LIBCPP_NO_EXCEPTIONS
 }
 
+// NOTE avoid the `base class should be explicitly initialized in the
+// copy constructor` warning emitted by GCC
+#if defined(__clang__) || _GNUC_VER >= 406
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wextra"
+#endif
+
 locale::__imp::__imp(const __imp& other)
     : facets_(max<size_t>(N, other.facets_.size())),
       name_(other.name_)
@@ -207,6 +245,10 @@
             facets_[i]->__add_shared();
 }
 
+#if defined(__clang__) || _GNUC_VER >= 406
+#pragma GCC diagnostic pop
+#endif
+
 locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
     : facets_(N),
       name_("*")
@@ -691,6 +733,19 @@
 
 // template <> class ctype<wchar_t>;
 
+const ctype_base::mask ctype_base::space;
+const ctype_base::mask ctype_base::print;
+const ctype_base::mask ctype_base::cntrl;
+const ctype_base::mask ctype_base::upper;
+const ctype_base::mask ctype_base::lower;
+const ctype_base::mask ctype_base::alpha;
+const ctype_base::mask ctype_base::digit;
+const ctype_base::mask ctype_base::punct;
+const ctype_base::mask ctype_base::xdigit;
+const ctype_base::mask ctype_base::blank;
+const ctype_base::mask ctype_base::alnum;
+const ctype_base::mask ctype_base::graph;
+    
 locale::id ctype<wchar_t>::id;
 
 ctype<wchar_t>::~ctype()
@@ -735,7 +790,7 @@
 {
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
     return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
 #else
     return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
@@ -748,7 +803,7 @@
     for (; low != high; ++low)
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
         *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
                              : *low;
 #else
@@ -762,7 +817,7 @@
 {
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
     return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
 #else
     return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
@@ -775,7 +830,7 @@
     for (; low != high; ++low)
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
         *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
                              : *low;
 #else
@@ -842,8 +897,11 @@
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ?
       static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
-#elif defined(__GLIBC__)
-    return isascii(c) ? __classic_upper_table()[c] : c;
+#elif defined(__NetBSD__)
+    return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+    return isascii(c) ? 
+      static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
 #else
     return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
 #endif
@@ -856,8 +914,11 @@
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ?
           static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
-#elif defined(__GLIBC__)
-        *low = isascii(*low) ? __classic_upper_table()[*low] : *low;
+#elif defined(__NetBSD__)
+        *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+        *low = isascii(*low) ?
+          static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
 #else
         *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
 #endif
@@ -870,8 +931,11 @@
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
     return isascii(c) ?
       static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
-#elif defined(__GLIBC__)
-    return isascii(c) ? __classic_lower_table()[c] : c;
+#elif defined(__NetBSD__)
+    return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
+    return isascii(c) ?
+      static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
 #else
     return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
 #endif
@@ -883,8 +947,10 @@
     for (; low != high; ++low)
 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
         *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
-#elif defined(__GLIBC__)
-        *low = isascii(*low) ? __classic_lower_table()[*low] : *low;
+#elif defined(__NetBSD__)
+        *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+        *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
 #else
         *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
 #endif
@@ -924,19 +990,29 @@
     return low;
 }
 
+#ifdef EMSCRIPTEN
+extern "C" const unsigned short ** __ctype_b_loc();
+extern "C" const int ** __ctype_tolower_loc();
+extern "C" const int ** __ctype_toupper_loc();
+#endif
+
 const ctype<char>::mask*
 ctype<char>::classic_table()  _NOEXCEPT
 {
 #if defined(__APPLE__) || defined(__FreeBSD__)
     return _DefaultRuneLocale.__runetype;
+#elif defined(__NetBSD__)
+    return _C_ctype_tab_ + 1;
 #elif defined(__GLIBC__)
     return __cloc()->__ctype_b;
 #elif __sun__
     return __ctype_mask;
-#elif _WIN32
+#elif defined(_WIN32)
     return _ctype+1; // internal ctype mask table defined in msvcrt.dll
 // This is assumed to be safe, which is a nonsense assumption because we're
 // going to end up dereferencing it later...
+#elif defined(EMSCRIPTEN)
+    return *__ctype_b_loc();
 #else
     // Platform not supported: abort so the person doing the port knows what to
     // fix
@@ -958,8 +1034,33 @@
 {
     return __cloc()->__ctype_toupper;
 }
-#endif // __GLIBC__
+#elif __NetBSD__
+const short*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+    return _C_tolower_tab_ + 1;
+}
 
+const short*
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+    return _C_toupper_tab_ + 1;
+}
+
+#elif defined(EMSCRIPTEN)
+const int*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+    return *__ctype_tolower_loc();
+}
+
+const int*
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+    return *__ctype_toupper_loc();
+}
+#endif // __GLIBC__ || EMSCRIPTEN || __NETBSD__
+
 // template <> class ctype_byname<char>
 
 ctype_byname<char>::ctype_byname(const char* name, size_t refs)
@@ -992,7 +1093,7 @@
 char
 ctype_byname<char>::do_toupper(char_type c) const
 {
-    return static_cast<char>(toupper_l(c, __l));
+    return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
 }
 
 const char*
@@ -999,7 +1100,7 @@
 ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
 {
     for (; low != high; ++low)
-        *low = static_cast<char>(toupper_l(*low, __l));
+        *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
     return low;
 }
 
@@ -1006,7 +1107,7 @@
 char
 ctype_byname<char>::do_tolower(char_type c) const
 {
-    return static_cast<char>(tolower_l(c, __l));
+    return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
 }
 
 const char*
@@ -1013,7 +1114,7 @@
 ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
 {
     for (; low != high; ++low)
-        *low = static_cast<char>(tolower_l(*low, __l));
+        *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
     return low;
 }
 
@@ -1052,17 +1153,18 @@
 #ifdef _LIBCPP_WCTYPE_IS_MASK
     return static_cast<bool>(iswctype_l(c, m, __l));
 #else
-    bool result = true;
-    if (m & space && !iswspace_l(c, __l)) result = false;
-    if (m & print && !iswprint_l(c, __l)) result = false;
-    if (m & cntrl && !iswcntrl_l(c, __l)) result = false;
-    if (m & upper && !iswupper_l(c, __l)) result = false;
-    if (m & lower && !iswlower_l(c, __l)) result = false;
-    if (m & alpha && !iswalpha_l(c, __l)) result = false;
-    if (m & digit && !iswdigit_l(c, __l)) result = false;
-    if (m & punct && !iswpunct_l(c, __l)) result = false;
-    if (m & xdigit && !iswxdigit_l(c, __l)) result = false;
-    if (m & blank && !iswblank_l(c, __l)) result = false;
+    bool result = false;
+    wint_t ch = static_cast<wint_t>(c);
+    if (m & space) result |= (iswspace_l(ch, __l) != 0);
+    if (m & print) result |= (iswprint_l(ch, __l) != 0);
+    if (m & cntrl) result |= (iswcntrl_l(ch, __l) != 0);
+    if (m & upper) result |= (iswupper_l(ch, __l) != 0);
+    if (m & lower) result |= (iswlower_l(ch, __l) != 0);
+    if (m & alpha) result |= (iswalpha_l(ch, __l) != 0);
+    if (m & digit) result |= (iswdigit_l(ch, __l) != 0);
+    if (m & punct) result |= (iswpunct_l(ch, __l) != 0);
+    if (m & xdigit) result |= (iswxdigit_l(ch, __l) != 0);
+    if (m & blank) result |= (iswblank_l(ch, __l) != 0);
     return result;
 #endif
 }
@@ -1077,23 +1179,24 @@
         else
         {
             *vec = 0;
-            if (iswspace_l(*low, __l))
+            wint_t ch = static_cast<wint_t>(*low);
+            if (iswspace_l(ch, __l))
                 *vec |= space;
-            if (iswprint_l(*low, __l))
+            if (iswprint_l(ch, __l))
                 *vec |= print;
-            if (iswcntrl_l(*low, __l))
+            if (iswcntrl_l(ch, __l))
                 *vec |= cntrl;
-            if (iswupper_l(*low, __l))
+            if (iswupper_l(ch, __l))
                 *vec |= upper;
-            if (iswlower_l(*low, __l))
+            if (iswlower_l(ch, __l))
                 *vec |= lower;
-            if (iswalpha_l(*low, __l))
+            if (iswalpha_l(ch, __l))
                 *vec |= alpha;
-            if (iswdigit_l(*low, __l))
+            if (iswdigit_l(ch, __l))
                 *vec |= digit;
-            if (iswpunct_l(*low, __l))
+            if (iswpunct_l(ch, __l))
                 *vec |= punct;
-            if (iswxdigit_l(*low, __l))
+            if (iswxdigit_l(ch, __l))
                 *vec |= xdigit;
         }
     }
@@ -1109,17 +1212,17 @@
         if (iswctype_l(*low, m, __l))
             break;
 #else
-        if (m & space && !iswspace_l(*low, __l)) continue;
-        if (m & print && !iswprint_l(*low, __l)) continue;
-        if (m & cntrl && !iswcntrl_l(*low, __l)) continue;
-        if (m & upper && !iswupper_l(*low, __l)) continue;
-        if (m & lower && !iswlower_l(*low, __l)) continue;
-        if (m & alpha && !iswalpha_l(*low, __l)) continue;
-        if (m & digit && !iswdigit_l(*low, __l)) continue;
-        if (m & punct && !iswpunct_l(*low, __l)) continue;
-        if (m & xdigit && !iswxdigit_l(*low, __l)) continue;
-        if (m & blank && !iswblank_l(*low, __l)) continue;
-        break;
+        wint_t ch = static_cast<wint_t>(*low);
+        if (m & space && iswspace_l(ch, __l)) break;
+        if (m & print && iswprint_l(ch, __l)) break;
+        if (m & cntrl && iswcntrl_l(ch, __l)) break;
+        if (m & upper && iswupper_l(ch, __l)) break;
+        if (m & lower && iswlower_l(ch, __l)) break;
+        if (m & alpha && iswalpha_l(ch, __l)) break;
+        if (m & digit && iswdigit_l(ch, __l)) break;
+        if (m & punct && iswpunct_l(ch, __l)) break;
+        if (m & xdigit && iswxdigit_l(ch, __l)) break;
+        if (m & blank && iswblank_l(ch, __l)) break;
 #endif
     }
     return low;
@@ -1134,16 +1237,17 @@
         if (!iswctype_l(*low, m, __l))
             break;
 #else
-        if (m & space && iswspace_l(*low, __l)) continue;
-        if (m & print && iswprint_l(*low, __l)) continue;
-        if (m & cntrl && iswcntrl_l(*low, __l)) continue;
-        if (m & upper && iswupper_l(*low, __l)) continue;
-        if (m & lower && iswlower_l(*low, __l)) continue;
-        if (m & alpha && iswalpha_l(*low, __l)) continue;
-        if (m & digit && iswdigit_l(*low, __l)) continue;
-        if (m & punct && iswpunct_l(*low, __l)) continue;
-        if (m & xdigit && iswxdigit_l(*low, __l)) continue;
-        if (m & blank && iswblank_l(*low, __l)) continue;
+        wint_t ch = static_cast<wint_t>(*low);
+        if (m & space && iswspace_l(ch, __l)) continue;
+        if (m & print && iswprint_l(ch, __l)) continue;
+        if (m & cntrl && iswcntrl_l(ch, __l)) continue;
+        if (m & upper && iswupper_l(ch, __l)) continue;
+        if (m & lower && iswlower_l(ch, __l)) continue;
+        if (m & alpha && iswalpha_l(ch, __l)) continue;
+        if (m & digit && iswdigit_l(ch, __l)) continue;
+        if (m & punct && iswpunct_l(ch, __l)) continue;
+        if (m & xdigit && iswxdigit_l(ch, __l)) continue;
+        if (m & blank && iswblank_l(ch, __l)) continue;
         break;
 #endif
     }
@@ -1208,7 +1312,7 @@
 #else
     int r = __wctob_l(c, __l);
 #endif
-    return r != WEOF ? static_cast<char>(r) : dfault;
+    return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
 }
 
 const wchar_t*
@@ -1221,7 +1325,7 @@
 #else
         int r = __wctob_l(*low, __l);
 #endif
-        *dest = r != WEOF ? static_cast<char>(r) : dfault;
+        *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
     }
     return low;
 }
@@ -1293,7 +1397,7 @@
 
 codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
     : locale::facet(refs),
-      __l(0)
+      __l(_LIBCPP_GET_C_LOCALE)
 {
 }
 
@@ -1310,7 +1414,7 @@
 
 codecvt<wchar_t, char, mbstate_t>::~codecvt()
 {
-    if (__l != 0)
+    if (__l != _LIBCPP_GET_C_LOCALE)
         freelocale(__l);
 }
 
@@ -1328,7 +1432,7 @@
     to_nxt = to;
     for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
     {
-        // save state in case needed to reover to_nxt on error
+        // save state in case it is needed to recover to_nxt on error
         mbstate_t save_state = st;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
         size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
@@ -1397,7 +1501,7 @@
     to_nxt = to;
     for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
     {
-        // save state in case needed to reover to_nxt on error
+        // save state in case it is needed to recover to_nxt on error
         mbstate_t save_state = st;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
         size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
@@ -1543,9 +1647,9 @@
 codecvt<wchar_t, char, mbstate_t>::do_max_length() const  _NOEXCEPT
 {
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
+    return __l == 0 ? 1 : static_cast<int>(  MB_CUR_MAX_L(__l));
 #else
-    return __l == 0 ? 1 : __mb_cur_max_l(__l);
+    return __l == 0 ? 1 : static_cast<int>(__mb_cur_max_l(__l));
 #endif
 }
 
@@ -2620,7 +2724,6 @@
                        codecvt_mode mode = codecvt_mode(0))
 {
     const uint8_t* frm_nxt = frm;
-    frm_nxt = frm;
     if (mode & consume_header)
     {
         if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
@@ -2753,7 +2856,6 @@
                        codecvt_mode mode = codecvt_mode(0))
 {
     const uint8_t* frm_nxt = frm;
-    frm_nxt = frm;
     if (mode & consume_header)
     {
         if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
@@ -2848,7 +2950,6 @@
                        codecvt_mode mode = codecvt_mode(0))
 {
     const uint8_t* frm_nxt = frm;
-    frm_nxt = frm;
     if (mode & consume_header)
     {
         if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
@@ -4560,6 +4661,7 @@
 }
 
 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
+#pragma GCC   diagnostic ignored "-Wmissing-field-initializers"
 
 template <>
 string
@@ -4579,7 +4681,7 @@
     char f[3] = {0};
     f[0] = '%';
     f[1] = fmt;
-    size_t n = strftime_l(buf, 100, f, &t, __loc_);
+    size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
     char* bb = buf;
     char* be = buf + n;
     string result;
@@ -4725,15 +4827,15 @@
     char f[3] = {0};
     f[0] = '%';
     f[1] = fmt;
-    strftime_l(buf, 100, f, &t, __loc_);
+    strftime_l(buf, countof(buf), f, &t, __loc_);
     wchar_t wbuf[100];
     wchar_t* wbb = wbuf;
     mbstate_t mb = {0};
     const char* bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    size_t j = mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
 #else
-    size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    size_t j = __mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -4865,15 +4967,15 @@
 void
 __time_get_storage<char>::init(const ctype<char>& ct)
 {
-    tm t;
+    tm t = {0};
     char buf[100];
     // __weeks_
     for (int i = 0; i < 7; ++i)
     {
         t.tm_wday = i;
-        strftime_l(buf, 100, "%A", &t, __loc_);
+        strftime_l(buf, countof(buf), "%A", &t, __loc_);
         __weeks_[i] = buf;
-        strftime_l(buf, 100, "%a", &t, __loc_);
+        strftime_l(buf, countof(buf), "%a", &t, __loc_);
         __weeks_[i+7] = buf;
     }
     // __months_
@@ -4880,17 +4982,17 @@
     for (int i = 0; i < 12; ++i)
     {
         t.tm_mon = i;
-        strftime_l(buf, 100, "%B", &t, __loc_);
+        strftime_l(buf, countof(buf), "%B", &t, __loc_);
         __months_[i] = buf;
-        strftime_l(buf, 100, "%b", &t, __loc_);
+        strftime_l(buf, countof(buf), "%b", &t, __loc_);
         __months_[i+12] = buf;
     }
     // __am_pm_
     t.tm_hour = 1;
-    strftime_l(buf, 100, "%p", &t, __loc_);
+    strftime_l(buf, countof(buf), "%p", &t, __loc_);
     __am_pm_[0] = buf;
     t.tm_hour = 13;
-    strftime_l(buf, 100, "%p", &t, __loc_);
+    strftime_l(buf, countof(buf), "%p", &t, __loc_);
     __am_pm_[1] = buf;
     __c_ = __analyze('c', ct);
     __r_ = __analyze('r', ct);
@@ -4904,7 +5006,6 @@
 {
     tm t = {0};
     char buf[100];
-    size_t be;
     wchar_t wbuf[100];
     wchar_t* wbe;
     mbstate_t mb = {0};
@@ -4912,25 +5013,25 @@
     for (int i = 0; i < 7; ++i)
     {
         t.tm_wday = i;
-        be = strftime_l(buf, 100, "%A", &t, __loc_);
+        strftime_l(buf, countof(buf), "%A", &t, __loc_);
         mb = mbstate_t();
         const char* bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __weeks_[i].assign(wbuf, wbe);
-        be = strftime_l(buf, 100, "%a", &t, __loc_);
+        strftime_l(buf, countof(buf), "%a", &t, __loc_);
         mb = mbstate_t();
         bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -4941,25 +5042,25 @@
     for (int i = 0; i < 12; ++i)
     {
         t.tm_mon = i;
-        be = strftime_l(buf, 100, "%B", &t, __loc_);
+        strftime_l(buf, countof(buf), "%B", &t, __loc_);
         mb = mbstate_t();
         const char* bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __months_[i].assign(wbuf, wbe);
-        be = strftime_l(buf, 100, "%b", &t, __loc_);
+        strftime_l(buf, countof(buf), "%b", &t, __loc_);
         mb = mbstate_t();
         bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -4968,13 +5069,13 @@
     }
     // __am_pm_
     t.tm_hour = 1;
-    be = strftime_l(buf, 100, "%p", &t, __loc_);
+    strftime_l(buf, countof(buf), "%p", &t, __loc_);
     mb = mbstate_t();
     const char* bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -4981,13 +5082,13 @@
     wbe = wbuf + j;
     __am_pm_[0].assign(wbuf, wbe);
     t.tm_hour = 13;
-    be = strftime_l(buf, 100, "%p", &t, __loc_);
+    strftime_l(buf, countof(buf), "%p", &t, __loc_);
     mb = mbstate_t();
     bb = buf;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #else
-    j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+    j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -5239,7 +5340,7 @@
 
 __time_put::~__time_put()
 {
-    if (__loc_)
+    if (__loc_ != _LIBCPP_GET_C_LOCALE)
         freelocale(__loc_);
 }
 
@@ -5250,7 +5351,7 @@
     char fmt[] = {'%', __fmt, __mod, 0};
     if (__mod != 0)
         swap(fmt[1], fmt[2]);
-    size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_);
+    size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
     __ne = __nb + n;
 }
 
@@ -5264,9 +5365,9 @@
     mbstate_t mb = {0};
     const char* __nb = __nar;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+    size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
 #else
-    size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+    size_t j = __mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -5725,7 +5826,7 @@
         __frac_digits_ = lc->int_frac_digits;
     else
         __frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
     if (lc->p_sign_posn == 0)
 #else // _WIN32
     if (lc->int_p_sign_posn == 0)
@@ -5733,7 +5834,7 @@
         __positive_sign_ = "()";
     else
         __positive_sign_ = lc->positive_sign;
-#if _WIN32
+#ifdef _WIN32
     if(lc->n_sign_posn == 0)
 #else // _WIN32
     if (lc->int_n_sign_posn == 0)
@@ -5745,7 +5846,7 @@
     // the same places in curr_symbol since there's no way to
     // represent anything else.
     string_type __dummy_curr_symbol = __curr_symbol_;
-#if _WIN32
+#ifdef _WIN32
     __init_pat(__pos_format_, __dummy_curr_symbol, true,
                lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
     __init_pat(__neg_format_, __curr_symbol_, true,
@@ -5789,9 +5890,9 @@
     mbstate_t mb = {0};
     const char* bb = lc->currency_symbol;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -5808,9 +5909,9 @@
         mb = mbstate_t();
         bb = lc->positive_sign;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -5824,9 +5925,9 @@
         mb = mbstate_t();
         bb = lc->negative_sign;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -5872,9 +5973,9 @@
     mbstate_t mb = {0};
     const char* bb = lc->int_curr_symbol;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
     if (j == size_t(-1))
         __throw_runtime_error("locale not supported");
@@ -5884,7 +5985,7 @@
         __frac_digits_ = lc->int_frac_digits;
     else
         __frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
     if (lc->p_sign_posn == 0)
 #else // _WIN32
     if (lc->int_p_sign_posn == 0)
@@ -5895,9 +5996,9 @@
         mb = mbstate_t();
         bb = lc->positive_sign;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -5904,7 +6005,7 @@
         wbe = wbuf + j;
         __positive_sign_.assign(wbuf, wbe);
     }
-#if _WIN32
+#ifdef _WIN32
     if (lc->n_sign_posn == 0)
 #else // _WIN32
     if (lc->int_n_sign_posn == 0)
@@ -5915,9 +6016,9 @@
         mb = mbstate_t();
         bb = lc->negative_sign;
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #else
-        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
 #endif
         if (j == size_t(-1))
             __throw_runtime_error("locale not supported");
@@ -5928,7 +6029,7 @@
     // the same places in curr_symbol since there's no way to
     // represent anything else.
     string_type __dummy_curr_symbol = __curr_symbol_;
-#if _WIN32
+#ifdef _WIN32
     __init_pat(__pos_format_, __dummy_curr_symbol, true,
                lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
     __init_pat(__neg_format_, __curr_symbol_, true,
@@ -5949,6 +6050,8 @@
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
     throw runtime_error(msg);
+#else
+    (void)msg;
 #endif
 }
 

Modified: trunk/contrib/libc++/src/memory.cpp
===================================================================
--- trunk/contrib/libc++/src/memory.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/memory.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -7,7 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define _LIBCPP_BUILDING_MEMORY
 #include "memory"
+#include "mutex"
+#include "thread"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -116,7 +119,62 @@
 
 #endif  // _LIBCPP_NO_RTTI
 
+#if __has_feature(cxx_atomic)
+
+static const std::size_t __sp_mut_count = 16;
+static pthread_mutex_t mut_back_imp[__sp_mut_count] =
+{
+    PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+    PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+    PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+    PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER
+};
+
+static mutex* mut_back = reinterpret_cast<std::mutex*>(mut_back_imp);
+
+_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
+   : __lx(p)
+{
+}
+
 void
+__sp_mut::lock() _NOEXCEPT
+{
+    mutex& m = *static_cast<mutex*>(__lx);
+    unsigned count = 0;
+    while (!m.try_lock())
+    {
+        if (++count > 16)
+        {
+            m.lock();
+            break;
+        }
+        this_thread::yield();
+    }
+}
+
+void
+__sp_mut::unlock() _NOEXCEPT
+{
+    static_cast<mutex*>(__lx)->unlock();
+}
+
+__sp_mut&
+__get_sp_mut(const void* p)
+{
+    static __sp_mut muts[__sp_mut_count] 
+    {
+        &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
+        &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
+        &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
+        &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15]
+    };
+    return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
+}
+
+#endif // __has_feature(cxx_atomic)
+
+void
 declare_reachable(void*)
 {
 }

Modified: trunk/contrib/libc++/src/mutex.cpp
===================================================================
--- trunk/contrib/libc++/src/mutex.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/mutex.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define _LIBCPP_BUILDING_MUTEX
 #include "mutex"
 #include "limits"
 #include "system_error"
@@ -32,13 +33,13 @@
 }
 
 bool
-mutex::try_lock()
+mutex::try_lock() _NOEXCEPT
 {
     return pthread_mutex_trylock(&__m_) == 0;
 }
 
 void
-mutex::unlock()
+mutex::unlock() _NOEXCEPT
 {
     int ec = pthread_mutex_unlock(&__m_);
     assert(ec == 0);
@@ -90,7 +91,7 @@
 }
 
 void
-recursive_mutex::unlock()
+recursive_mutex::unlock() _NOEXCEPT
 {
     int e = pthread_mutex_unlock(&__m_);
     assert(e == 0);
@@ -97,7 +98,7 @@
 }
 
 bool
-recursive_mutex::try_lock()
+recursive_mutex::try_lock() _NOEXCEPT
 {
     return pthread_mutex_trylock(&__m_) == 0;
 }
@@ -124,7 +125,7 @@
 }
 
 bool
-timed_mutex::try_lock()
+timed_mutex::try_lock() _NOEXCEPT
 {
     unique_lock<mutex> lk(__m_, try_to_lock);
     if (lk.owns_lock() && !__locked_)
@@ -136,7 +137,7 @@
 }
 
 void
-timed_mutex::unlock()
+timed_mutex::unlock() _NOEXCEPT
 {
     lock_guard<mutex> _(__m_);
     __locked_ = false;
@@ -175,7 +176,7 @@
 }
 
 bool
-recursive_timed_mutex::try_lock()
+recursive_timed_mutex::try_lock() _NOEXCEPT
 {
     pthread_t id = pthread_self();
     unique_lock<mutex> lk(__m_, try_to_lock);
@@ -191,7 +192,7 @@
 }
 
 void
-recursive_timed_mutex::unlock()
+recursive_timed_mutex::unlock() _NOEXCEPT
 {
     unique_lock<mutex> lk(__m_);
     if (--__count_ == 0)

Modified: trunk/contrib/libc++/src/new.cpp
===================================================================
--- trunk/contrib/libc++/src/new.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/new.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -11,7 +11,11 @@
 
 #include "new"
 
-#if __APPLE__
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
+#ifdef __APPLE__
     #include <cxxabi.h>
 
     #ifndef _LIBCPPABI_VERSION
@@ -21,7 +25,12 @@
         #define __new_handler __cxxabiapple::__cxa_new_handler
     #endif
 #else  // __APPLE__
-    static std::new_handler __new_handler;
+    #if defined(LIBCXXRT) || __has_include(<cxxabi.h>)
+        #include <cxxabi.h>
+    #endif  // __has_include(<cxxabi.h>)
+    #ifndef _LIBCPPABI_VERSION
+        static std::new_handler __new_handler;
+    #endif  // _LIBCPPABI_VERSION
 #endif
 
 // Implement all new and delete operators as weak definitions

Modified: trunk/contrib/libc++/src/random.cpp
===================================================================
--- trunk/contrib/libc++/src/random.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/random.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -40,7 +40,7 @@
 }
 
 double
-random_device::entropy() const
+random_device::entropy() const _NOEXCEPT
 {
     return 0;
 }

Modified: trunk/contrib/libc++/src/stdexcept.cpp
===================================================================
--- trunk/contrib/libc++/src/stdexcept.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/stdexcept.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -16,9 +16,14 @@
 #include <cstddef>
 #include "system_error"
 
-// Use <cxxabi.h> to determine whether we're linking against libc++abi.
-#if __has_include(<cxxabi.h>)
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
+#ifdef __APPLE__
 #include <cxxabi.h>
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
+#include <cxxabi.h>
 #endif
 
 // Note:  optimize for size
@@ -34,7 +39,7 @@
     const char* str_;
 
     typedef std::size_t unused_t;
-    typedef std::int32_t count_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));
@@ -56,7 +61,7 @@
     c[0] = c[1] = len;
     str_ += offset;
     count() = 0;
-    std::strcpy(const_cast<char*>(c_str()), msg);
+    std::memcpy(const_cast<char*>(c_str()), msg, len + 1);
 }
 
 inline
@@ -72,7 +77,7 @@
     const char* p = str_;
     str_ = s.str_;
     __sync_add_and_fetch(&count(), 1);
-    if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), -1) < 0)
+    if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), count_t(-1)) < 0)
         delete [] (p-offset);
     return *this;
 }
@@ -80,7 +85,7 @@
 inline
 __libcpp_nmstr::~__libcpp_nmstr()
 {
-    if (__sync_add_and_fetch(&count(), -1) < 0)
+    if (__sync_add_and_fetch(&count(), count_t(-1)) < 0)
         delete [] (str_ - offset);
 }
 

Modified: trunk/contrib/libc++/src/string.cpp
===================================================================
--- trunk/contrib/libc++/src/string.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/string.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -11,7 +11,9 @@
 #include "cstdlib"
 #include "cwchar"
 #include "cerrno"
-#if _WIN32
+#include "limits"
+#include "stdexcept"
+#ifdef _WIN32
 #include "support/win32/support.h"
 #endif // _WIN32
 
@@ -26,654 +28,499 @@
     string
     operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
 
-int
-stoi(const string& str, size_t* idx, int base)
+namespace
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    long r = strtol(p, &ptr, base);
-    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
-        ptr = const_cast<char*>(p);
+
+template<typename T>
+inline
+void throw_helper( const string& msg )
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw T( msg );
+#else
+    abort();
+#endif
+}
+
+inline
+void throw_from_string_out_of_range( const string& func )
+{
+    throw_helper<out_of_range>(func + ": out of range");
+}
+
+inline
+void throw_from_string_invalid_arg( const string& func )
+{
+    throw_helper<invalid_argument>(func + ": no conversion");
+}
+
+// as_integer
+
+template<typename V, typename S, typename F>
+inline
+V
+as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
+{
+    typename S::value_type* ptr;
+    const typename S::value_type* const p = str.c_str();
+    typename remove_reference<decltype(errno)>::type errno_save = errno;
+    errno = 0;
+    V r = f(p, &ptr, base);
+    swap(errno, errno_save);
+    if (errno_save == ERANGE)
+        throw_from_string_out_of_range(func);
     if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoi: no conversion");
-        throw out_of_range("stoi: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
+        throw_from_string_invalid_arg(func);
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
+    return r;
+}
+
+template<typename V, typename S>
+inline
+V
+as_integer(const string& func, const S& s, size_t* idx, int base);
+
+// string
+template<>
+inline
+int
+as_integer(const string& func, const string& s, size_t* idx, int base )
+{
+    // Use long as no Stantard string to integer exists.
+    long r = as_integer_helper<long>( func, s, idx, base, strtol );
+    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+        throw_from_string_out_of_range(func);
     return static_cast<int>(r);
 }
 
+template<>
+inline
+long
+as_integer(const string& func, const string& s, size_t* idx, int base )
+{
+    return as_integer_helper<long>( func, s, idx, base, strtol );
+}
+
+template<>
+inline
+unsigned long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+    return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
+}
+
+template<>
+inline
+long long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+    return as_integer_helper<long long>( func, s, idx, base, strtoll );
+}
+
+template<>
+inline
+unsigned long long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+    return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
+}
+
+// wstring
+template<>
+inline
 int
-stoi(const wstring& str, size_t* idx, int base)
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    long r = wcstol(p, &ptr, base);
+    // Use long as no Stantard string to integer exists.
+    long r = as_integer_helper<long>( func, s, idx, base, wcstol );
     if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
-        ptr = const_cast<wchar_t*>(p);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoi: no conversion");
-        throw out_of_range("stoi: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
+        throw_from_string_out_of_range(func);
     return static_cast<int>(r);
 }
 
+template<>
+inline
 long
-stol(const string& str, size_t* idx, int base)
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    long r = strtol(p, &ptr, base);
+    return as_integer_helper<long>( func, s, idx, base, wcstol );
+}
+
+template<>
+inline
+unsigned long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+    return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
+}
+
+template<>
+inline
+long long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+    return as_integer_helper<long long>( func, s, idx, base, wcstoll );
+}
+
+template<>
+inline
+unsigned long long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+    return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
+}
+
+// as_float
+
+template<typename V, typename S, typename F> 
+inline
+V
+as_float_helper(const string& func, const S& str, size_t* idx, F f )
+{
+    typename S::value_type* ptr;
+    const typename S::value_type* const p = str.c_str();
+    typename remove_reference<decltype(errno)>::type errno_save = errno;
+    errno = 0;
+    V r = f(p, &ptr);
+    swap(errno, errno_save);
+    if (errno_save == ERANGE)
+        throw_from_string_out_of_range(func);
     if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stol: no conversion");
-        throw out_of_range("stol: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
+        throw_from_string_invalid_arg(func);
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return r;
 }
 
+template<typename V, typename S>
+inline
+V as_float( const string& func, const S& s, size_t* idx = nullptr );
+
+template<>
+inline
+float
+as_float( const string& func, const string& s, size_t* idx )
+{
+    return as_float_helper<float>( func, s, idx, strtof );
+}
+
+template<>
+inline
+double
+as_float(const string& func, const string& s, size_t* idx )
+{
+    return as_float_helper<double>( func, s, idx, strtod );
+}
+
+template<>
+inline
+long double
+as_float( const string& func, const string& s, size_t* idx )
+{
+    return as_float_helper<long double>( func, s, idx, strtold );
+}
+
+template<>
+inline
+float
+as_float( const string& func, const wstring& s, size_t* idx )
+{
+    return as_float_helper<float>( func, s, idx, wcstof );
+}
+
+template<>
+inline
+double
+as_float( const string& func, const wstring& s, size_t* idx )
+{
+    return as_float_helper<double>( func, s, idx, wcstod );
+}
+
+template<>
+inline
+long double
+as_float( const string& func, const wstring& s, size_t* idx )
+{
+    return as_float_helper<long double>( func, s, idx, wcstold );
+}
+
+}  // unnamed namespace
+
+int
+stoi(const string& str, size_t* idx, int base)
+{
+    return as_integer<int>( "stoi", str, idx, base );
+}
+
+int
+stoi(const wstring& str, size_t* idx, int base)
+{
+    return as_integer<int>( "stoi", str, idx, base );
+}
+
 long
+stol(const string& str, size_t* idx, int base)
+{
+    return as_integer<long>( "stol", str, idx, base );
+}
+
+long
 stol(const wstring& str, size_t* idx, int base)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    long r = wcstol(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stol: no conversion");
-        throw out_of_range("stol: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<long>( "stol", str, idx, base );
 }
 
 unsigned long
 stoul(const string& str, size_t* idx, int base)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    unsigned long r = strtoul(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoul: no conversion");
-        throw out_of_range("stoul: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<unsigned long>( "stoul", str, idx, base );
 }
 
 unsigned long
 stoul(const wstring& str, size_t* idx, int base)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    unsigned long r = wcstoul(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoul: no conversion");
-        throw out_of_range("stoul: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<unsigned long>( "stoul", str, idx, base );
 }
 
 long long
 stoll(const string& str, size_t* idx, int base)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    long long r = strtoll(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoll: no conversion");
-        throw out_of_range("stoll: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<long long>( "stoll", str, idx, base );
 }
 
 long long
 stoll(const wstring& str, size_t* idx, int base)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    long long r = wcstoll(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoll: no conversion");
-        throw out_of_range("stoll: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<long long>( "stoll", str, idx, base );
 }
 
 unsigned long long
 stoull(const string& str, size_t* idx, int base)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    unsigned long long r = strtoull(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoull: no conversion");
-        throw out_of_range("stoull: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<unsigned long long>( "stoull", str, idx, base );
 }
 
 unsigned long long
 stoull(const wstring& str, size_t* idx, int base)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    unsigned long long r = wcstoull(p, &ptr, base);
-    if (ptr == p)
-    {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-        if (r == 0)
-            throw invalid_argument("stoull: no conversion");
-        throw out_of_range("stoull: out of range");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    }
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_integer<unsigned long long>( "stoull", str, idx, base );
 }
 
 float
 stof(const string& str, size_t* idx)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    double r = strtod(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stof: out of range");
-    if (ptr == p)
-        throw invalid_argument("stof: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return static_cast<float>(r);
+    return as_float<float>( "stof", str, idx );
 }
 
 float
 stof(const wstring& str, size_t* idx)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    double r = wcstod(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stof: out of range");
-    if (ptr == p)
-        throw invalid_argument("stof: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return static_cast<float>(r);
+    return as_float<float>( "stof", str, idx );
 }
 
 double
 stod(const string& str, size_t* idx)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    double r = strtod(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stod: out of range");
-    if (ptr == p)
-        throw invalid_argument("stod: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_float<double>( "stod", str, idx );
 }
 
 double
 stod(const wstring& str, size_t* idx)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    double r = wcstod(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stod: out of range");
-    if (ptr == p)
-        throw invalid_argument("stod: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_float<double>( "stod", str, idx );
 }
 
 long double
 stold(const string& str, size_t* idx)
 {
-    char* ptr;
-    const char* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    long double r = strtold(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stold: out of range");
-    if (ptr == p)
-        throw invalid_argument("stold: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_float<long double>( "stold", str, idx );
 }
 
 long double
 stold(const wstring& str, size_t* idx)
 {
-    wchar_t* ptr;
-    const wchar_t* const p = str.c_str();
-    int errno_save = errno;
-    errno = 0;
-    long double r = wcstold(p, &ptr);
-    swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    if (errno_save == ERANGE)
-        throw out_of_range("stold: out of range");
-    if (ptr == p)
-        throw invalid_argument("stold: no conversion");
-#endif  // _LIBCPP_NO_EXCEPTIONS
-    if (idx)
-        *idx = static_cast<size_t>(ptr - p);
-    return r;
+    return as_float<long double>( "stold", str, idx );
 }
 
-string to_string(int val)
+// to_string
+
+namespace
 {
-    string s;
-    s.resize(s.capacity());
+
+// as_string
+
+template<typename S, typename P, typename V >
+inline
+S
+as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
+{
+    typedef typename S::size_type size_type;
+    size_type available = s.size();
     while (true)
     {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%d", val));
-        if (n2 <= s.size())
+        int status = sprintf_like(&s[0], available + 1, fmt, a);
+        if ( status >= 0 )
         {
-            s.resize(n2);
-            break;
+            size_type used = static_cast<size_type>(status);
+            if ( used <= available )
+            {
+                s.resize( used );
+                break;
+            }
+            available = used; // Assume this is advice of how much space we need.
         }
-        s.resize(n2);
+        else
+            available = available * 2 + 1;
+        s.resize(available);
     }
     return s;
 }
 
-string to_string(unsigned val)
+template <class S, class V, bool = is_floating_point<V>::value>
+struct initial_string;
+
+template <class V, bool b>
+struct initial_string<string, V, b>
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
+    string
+    operator()() const
     {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%u", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
+        string s;
+        s.resize(s.capacity());
+        return s;
     }
-    return s;
-}
+};
 
-string to_string(long val)
+template <class V>
+struct initial_string<wstring, V, false>
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
+    wstring
+    operator()() const
     {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%ld", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
+        const size_t n = (numeric_limits<unsigned long long>::digits / 3)
+          + ((numeric_limits<unsigned long long>::digits % 3) != 0)
+          + 1;
+        wstring s(n, wchar_t());
+        s.resize(s.capacity());
+        return s;
     }
-    return s;
-}
+};
 
-string to_string(unsigned long val)
+template <class V>
+struct initial_string<wstring, V, true>
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
+    wstring
+    operator()() const
     {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lu", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
+        wstring s(20, wchar_t());
+        s.resize(s.capacity());
+        return s;
     }
-    return s;
+};
+
+typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
+
+inline
+wide_printf
+get_swprintf()
+{
+#ifndef _WIN32
+    return swprintf;
+#else
+    return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(swprintf);
+#endif
 }
 
+}  // unnamed namespace
+
+string to_string(int val)
+{
+    return as_string(snprintf, initial_string<string, int>()(), "%d", val);
+}
+
+string to_string(unsigned val)
+{
+    return as_string(snprintf, initial_string<string, unsigned>()(), "%u", val);
+}
+
+string to_string(long val)
+{
+    return as_string(snprintf, initial_string<string, long>()(), "%ld", val);
+}
+
+string to_string(unsigned long val)
+{
+    return as_string(snprintf, initial_string<string, unsigned long>()(), "%lu", val);
+}
+
 string to_string(long long val)
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
-    {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lld", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
-    }
-    return s;
+    return as_string(snprintf, initial_string<string, long long>()(), "%lld", val);
 }
 
 string to_string(unsigned long long val)
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
-    {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%llu", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
-    }
-    return s;
+    return as_string(snprintf, initial_string<string, unsigned long long>()(), "%llu", val);
 }
 
 string to_string(float val)
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
-    {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
-    }
-    return s;
+    return as_string(snprintf, initial_string<string, float>()(), "%f", val);
 }
 
 string to_string(double val)
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
-    {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
-    }
-    return s;
+    return as_string(snprintf, initial_string<string, double>()(), "%f", val);
 }
 
 string to_string(long double val)
 {
-    string s;
-    s.resize(s.capacity());
-    while (true)
-    {
-        size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%Lf", val));
-        if (n2 <= s.size())
-        {
-            s.resize(n2);
-            break;
-        }
-        s.resize(n2);
-    }
-    return s;
+    return as_string(snprintf, initial_string<string, long double>()(), "%Lf", val);
 }
 
 wstring to_wstring(int val)
 {
-    const size_t n = (numeric_limits<int>::digits / 3)
-          + ((numeric_limits<int>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%d", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, int>()(), L"%d", val);
 }
 
 wstring to_wstring(unsigned val)
 {
-    const size_t n = (numeric_limits<unsigned>::digits / 3)
-          + ((numeric_limits<unsigned>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%u", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, unsigned>()(), L"%u", val);
 }
 
 wstring to_wstring(long val)
 {
-    const size_t n = (numeric_limits<long>::digits / 3)
-          + ((numeric_limits<long>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%ld", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, long>()(), L"%ld", val);
 }
 
 wstring to_wstring(unsigned long val)
 {
-    const size_t n = (numeric_limits<unsigned long>::digits / 3)
-          + ((numeric_limits<unsigned long>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%lu", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, unsigned long>()(), L"%lu", val);
 }
 
 wstring to_wstring(long long val)
 {
-    const size_t n = (numeric_limits<long long>::digits / 3)
-          + ((numeric_limits<long long>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%lld", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, long long>()(), L"%lld", val);
 }
 
 wstring to_wstring(unsigned long long val)
 {
-    const size_t n = (numeric_limits<unsigned long long>::digits / 3)
-          + ((numeric_limits<unsigned long long>::digits % 3) != 0)
-          + 1;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%llu", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, unsigned long long>()(), L"%llu", val);
 }
 
 wstring to_wstring(float val)
 {
-    const size_t n = 20;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%f", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, float>()(), L"%f", val);
 }
 
 wstring to_wstring(double val)
 {
-    const size_t n = 20;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%f", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, double>()(), L"%f", val);
 }
 
 wstring to_wstring(long double val)
 {
-    const size_t n = 20;
-    wstring s(n, wchar_t());
-    s.resize(s.capacity());
-    while (true)
-    {
-        int n2 = swprintf(&s[0], s.size()+1, L"%Lf", val);
-        if (n2 > 0)
-        {
-            s.resize(static_cast<size_t>(n2));
-            break;
-        }
-        s.resize(2*s.size());
-        s.resize(s.capacity());
-    }
-    return s;
+    return as_string(get_swprintf(), initial_string<wstring, long double>()(), L"%Lf", val);
 }
-
 _LIBCPP_END_NAMESPACE_STD

Modified: trunk/contrib/libc++/src/strstream.cpp
===================================================================
--- trunk/contrib/libc++/src/strstream.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/strstream.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -158,6 +158,8 @@
             return int_type(EOF);
         streamsize old_size = (epptr() ? epptr() : egptr()) - eback();
         streamsize new_size = max<streamsize>(__alsize_, 2*old_size);
+        if (new_size == 0)
+            new_size = __default_alsize;
         char* buf = nullptr;
         if (__palloc_)
             buf = static_cast<char*>(__palloc_(static_cast<size_t>(new_size)));

Modified: trunk/contrib/libc++/src/system_error.cpp
===================================================================
--- trunk/contrib/libc++/src/system_error.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/system_error.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -195,6 +195,9 @@
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
     throw system_error(error_code(ev, system_category()), what_arg);
+#else
+    (void)ev;
+    (void)what_arg;
 #endif
 }
 

Modified: trunk/contrib/libc++/src/thread.cpp
===================================================================
--- trunk/contrib/libc++/src/thread.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/thread.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -11,11 +11,22 @@
 #include "exception"
 #include "vector"
 #include "future"
+#include "limits"
 #include <sys/types.h>
-#if !_WIN32 && !__sun__
+#if !defined(_WIN32)
+#if !defined(__sun__) && !defined(__linux__)
 #include <sys/sysctl.h>
-#endif // _WIN32
+#endif // !__sun__ && !__linux__
+#include <unistd.h>
+#endif // !_WIN32
 
+#if defined(__NetBSD__)
+#pragma weak pthread_create // Do not create libpthread dependency
+#endif
+#if defined(_WIN32)
+#include <windows.h>
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 thread::~thread()
@@ -31,6 +42,8 @@
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (ec)
         throw system_error(error_code(ec, system_category()), "thread::join failed");
+#else
+    (void)ec;
 #endif  // _LIBCPP_NO_EXCEPTIONS
     __t_ = 0;
 }
@@ -52,7 +65,7 @@
 }
 
 unsigned
-thread::hardware_concurrency()
+thread::hardware_concurrency() _NOEXCEPT
 {
 #if defined(CTL_HW) && defined(HW_NCPU)
     unsigned n;
@@ -60,9 +73,23 @@
     std::size_t s = sizeof(n);
     sysctl(mib, 2, &n, &s, 0, 0);
     return n;
+#elif defined(_SC_NPROCESSORS_ONLN)
+    long result = sysconf(_SC_NPROCESSORS_ONLN);
+    // sysconf returns -1 if the name is invalid, the option does not exist or
+    // does not have a definite limit.
+    // if sysconf returns some other negative number, we have no idea
+    // what is going on. Default to something safe.
+    if (result < 0)
+        return 0;
+    return static_cast<unsigned>(result);
+#elif defined(_WIN32)
+    SYSTEM_INFO info;
+    GetSystemInfo(&info);
+    return info.dwNumberOfProcessors;
 #else  // defined(CTL_HW) && defined(HW_NCPU)
     // TODO: grovel through /proc or check cpuid on x86 and similar
     // instructions on other architectures.
+#warning hardware_concurrency not yet implemented
     return 0;  // Means not computable [thread.thread.static]
 #endif  // defined(CTL_HW) && defined(HW_NCPU)
 }
@@ -74,11 +101,22 @@
 sleep_for(const chrono::nanoseconds& ns)
 {
     using namespace chrono;
-    if (ns >= nanoseconds::zero())
+    if (ns > nanoseconds::zero())
     {
+        seconds s = duration_cast<seconds>(ns);
         timespec ts;
-        ts.tv_sec = static_cast<decltype(ts.tv_sec)>(duration_cast<seconds>(ns).count());
-        ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((ns - seconds(ts.tv_sec)).count());
+        typedef decltype(ts.tv_sec) ts_sec;
+        _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
+        if (s.count() < ts_sec_max)
+        {
+            ts.tv_sec = static_cast<ts_sec>(s.count());
+            ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((ns-s).count());
+        }
+        else
+        {
+            ts.tv_sec = ts_sec_max;
+            ts.tv_nsec = giga::num - 1;
+        }
         nanosleep(&ts, 0);
     }
 }

Modified: trunk/contrib/libc++/src/typeinfo.cpp
===================================================================
--- trunk/contrib/libc++/src/typeinfo.cpp	2016-01-06 20:10:37 UTC (rev 7404)
+++ trunk/contrib/libc++/src/typeinfo.cpp	2016-01-07 17:22:14 UTC (rev 7405)
@@ -7,8 +7,15 @@
 //
 //===----------------------------------------------------------------------===//
 #include <stdlib.h>
-#if __APPLE__
+
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
+#ifdef __APPLE__
 #include <cxxabi.h>
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
+#include <cxxabi.h>
 #endif
 
 #include "typeinfo"
@@ -43,11 +50,21 @@
   return "std::bad_typeid";
 }
 
-#if __APPLE__
+#ifdef __APPLE__
   // On Darwin, the cxa_bad_* functions cannot be in the lower level library
   // because bad_cast and bad_typeid are defined in his higher level library
-  void __cxxabiv1::__cxa_bad_typeid() { throw std::bad_typeid(); }
-  void __cxxabiv1::__cxa_bad_cast() { throw std::bad_cast(); }
+  void __cxxabiv1::__cxa_bad_typeid()
+  {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+     throw std::bad_typeid();
 #endif
+  }
+  void __cxxabiv1::__cxa_bad_cast()
+  {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+      throw std::bad_cast();
+#endif
+  }
+#endif
 
 #endif  // _LIBCPPABI_VERSION



More information about the Midnightbsd-cvs mailing list