]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: Constrain optional's __constexpr_addressof in its return type and use a...
authorVille Voutilainen <ville.voutilainen@gmail.com>
Wed, 7 Dec 2016 15:22:34 +0000 (17:22 +0200)
committerVille Voutilainen <ville@gcc.gnu.org>
Wed, 7 Dec 2016 15:22:34 +0000 (17:22 +0200)
Backport from mainline
2016-12-06  Ville Voutilainen  <ville.voutilainen@gmail.com>

Constrain optional's __constexpr_addressof in its return type
and use a constexpr addressof for optional, if available.
* include/experimental/optional (__constexpr_addressof):
Constrain in the return type instead of in a template parameter.
(_Has_addressof_mem)
(_Has_addressof_free, _Has_addressof, __constexpr_addressof):
Guard with #ifndef __cpp_lib_addressof_constexpr.
(operator->()): Use std::__addressof if it's constexpr.

From-SVN: r243350

libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/optional

index 4c58b9fbf4643162d3b2ef5a6a555ed16f3844d7..7a0782825c421ae064100f521ebfaf0ca7f9f893 100644 (file)
@@ -1,3 +1,17 @@
+2016-12-07  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Backport from mainline
+       2016-12-06  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Constrain optional's __constexpr_addressof in its return type
+       and use a constexpr addressof for optional, if available.
+       * include/experimental/optional (__constexpr_addressof):
+       Constrain in the return type instead of in a template parameter.
+       (_Has_addressof_mem)
+       (_Has_addressof_free, _Has_addressof, __constexpr_addressof):
+       Guard with #ifndef __cpp_lib_addressof_constexpr.
+       (operator->()): Use std::__addressof if it's constexpr.
+
 2016-12-06  Aditya Kumar  <hiraditya@msn.com>
 
        * src/c++11/shared_ptr.cc (_Sp_locker::_Sp_locker(const void* p)): Add
index b85b4bff92381f773027ede3f8c0596b856cf92b..e9c5412c349875ab766dc9434882044feeb11e83 100644 (file)
@@ -134,6 +134,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __throw_bad_optional_access(const char* __s)
   { _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); }
 
+#ifndef __cpp_lib_addressof_constexpr
   template<typename _Tp, typename = void>
     struct _Has_addressof_mem : std::false_type { };
 
@@ -170,16 +171,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     * overloaded addressof operator (unary operator&), in which case the call
     * will not be a constant expression.
     */
-  template<typename _Tp, enable_if_t<!_Has_addressof<_Tp>::value, int>...>
-    constexpr _Tp* __constexpr_addressof(_Tp& __t)
+  template<typename _Tp>
+    constexpr
+    enable_if_t<!_Has_addressof<_Tp>::value, _Tp*>
+    __constexpr_addressof(_Tp& __t)
     { return &__t; }
 
   /**
     * @brief Fallback overload that defers to __addressof.
     */
-  template<typename _Tp, enable_if_t<_Has_addressof<_Tp>::value, int>...>
-    inline _Tp* __constexpr_addressof(_Tp& __t)
+  template<typename _Tp>
+    inline
+    enable_if_t<_Has_addressof<_Tp>::value, _Tp*>
+    __constexpr_addressof(_Tp& __t)
     { return std::__addressof(__t); }
+#endif // __cpp_lib_addressof_constexpr
 
   /**
     * @brief Class template that holds the necessary state for @ref optional
@@ -574,7 +580,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // [X.Y.4.5] Observers.
       constexpr const _Tp*
       operator->() const
-      { return __constexpr_addressof(this->_M_get()); }
+      {
+#ifndef __cpp_lib_addressof_constexpr
+       return __constexpr_addressof(this->_M_get());
+#else
+       return std::__addressof(this->_M_get());
+#endif
+      }
 
       _Tp*
       operator->()