Fixes for LWG 2598, 2686, 2739, 2742, 2747, and 2759, which were adopted last week in Issaquah

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@286858 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/algorithm b/include/algorithm
index 3bafd3d..c5a5d0a 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -877,7 +877,7 @@
 {
     for (; __first != __last; ++__first)
         __f(*__first);
-    return _LIBCPP_EXPLICIT_MOVE(__f);  // explicitly moved for (emulated) C++03
+    return __f;
 }
 
 // find
diff --git a/include/chrono b/include/chrono
index 68484e9..3cef9ed 100644
--- a/include/chrono
+++ b/include/chrono
@@ -1026,7 +1026,8 @@
 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
 {
-    return __lhs + (-__rhs);
+    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
+    return _Ret(__lhs.time_since_epoch() -__rhs);
 }
 
 // duration operator-(time_point x, time_point y);
diff --git a/include/memory b/include/memory
index 69068f3..daa1740 100644
--- a/include/memory
+++ b/include/memory
@@ -164,6 +164,7 @@
 template <class T> void               return_temporary_buffer(T* p) noexcept;
 
 template <class T> T* addressof(T& r) noexcept;
+template <class T> T* addressof(const T&& r) noexcept = delete;
 
 template <class InputIterator, class ForwardIterator>
 ForwardIterator
@@ -675,7 +676,7 @@
 #endif
 }
 
-// addressof moved to <__functional_base>
+// addressof moved to <type_traits>
 
 template <class _Tp> class allocator;
 
diff --git a/include/numeric b/include/numeric
index 1643d64..e005808 100644
--- a/include/numeric
+++ b/include/numeric
@@ -230,6 +230,8 @@
 gcd(_Tp __m, _Up __n)
 {
     static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
+    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
+    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
     using _Rp = common_type_t<_Tp,_Up>;
     using _Wp = make_unsigned_t<_Rp>;
     return static_cast<_Rp>(__gcd(static_cast<_Wp>(__abs<_Tp>()(__m)),
@@ -242,6 +244,8 @@
 lcm(_Tp __m, _Up __n)
 {
     static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
+    static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
+    static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
     if (__m == 0 || __n == 0)
         return 0;
 
diff --git a/include/string b/include/string
index 347cb68..840fd00 100644
--- a/include/string
+++ b/include/string
@@ -102,6 +102,8 @@
                  const allocator_type& a = allocator_type());
     basic_string(const basic_string& str, size_type pos, size_type n,
                  const Allocator& a = Allocator());
+    template<class T>
+        basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
     explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
     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());
@@ -789,6 +791,10 @@
     _LIBCPP_INLINE_VISIBILITY
     basic_string(const basic_string& __str, size_type __pos,
                  const allocator_type& __a = allocator_type());
+    template<class _Tp>
+        basic_string(const _Tp& __t, size_type __pos, size_type __n, 
+                     const allocator_type& __a = allocator_type(),
+                     typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
     _LIBCPP_INLINE_VISIBILITY explicit
     basic_string(__self_view __sv);
     _LIBCPP_INLINE_VISIBILITY
@@ -1717,6 +1723,20 @@
 }
 
 template <class _CharT, class _Traits, class _Allocator>
+template <class _Tp>
+basic_string<_CharT, _Traits, _Allocator>::basic_string(
+             const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
+			 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
+    : __r_(__a)
+{
+	__self_view __sv = __self_view(__t).substr(__pos, __n);
+    __init(__sv.data(), __sv.size());
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __get_db()->__insert_c(this);
+#endif	
+}
+
+template <class _CharT, class _Traits, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
 {
diff --git a/include/string_view b/include/string_view
index baba464..60c0ad0 100644
--- a/include/string_view
+++ b/include/string_view
@@ -164,7 +164,6 @@
 #include <__config>
 
 #include <__string>
-#include <algorithm>
 #include <iterator>
 #include <__debug>
 
@@ -320,8 +319,8 @@
 	{
 		if (__pos > size())
 			__throw_out_of_range("string_view::copy");
-		size_type __rlen = _VSTD::min( __n, size() - __pos );
-		copy_n(begin() + __pos, __rlen, __s );
+		size_type __rlen = _VSTD::min(__n, size() - __pos);
+		_Traits::copy(__s, data() + __pos, __rlen);
 		return __rlen;
 	}
 
diff --git a/include/system_error b/include/system_error
index faaeaa0..c7e73d4 100644
--- a/include/system_error
+++ b/include/system_error
@@ -219,6 +219,7 @@
 bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
 
 template <> struct hash<std::error_code>;
+template <> struct hash<std::error_condition>;
 
 }  // std
 
@@ -629,6 +630,17 @@
     }
 };
 
+template <>
+struct _LIBCPP_TYPE_VIS_ONLY hash<error_condition>
+    : public unary_function<error_condition, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(const error_condition& __ec) const _NOEXCEPT
+    {
+        return static_cast<size_t>(__ec.value());
+    }
+};
+
 // system_error
 
 class _LIBCPP_TYPE_VIS system_error
diff --git a/include/type_traits b/include/type_traits
index 4d24886..fbfc9d3 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -488,6 +488,10 @@
 }
 #endif
 
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_DELETED_FUNCTIONS)
+template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
+#endif
+
 struct __two {char __lx[2];};
 
 // helper class: