From b752e2c926065820a0086c7a482edf199d79dfc2 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 2 May 2019 22:23:35 +0100 Subject: [PATCH] Remove redundant __constexpr_addressof function The std::__addressof function is always constexpr, even in C++14, so we can just use that. * include/experimental/bits/lfts_config.h: Improve doc markup. * include/experimental/optional: Improve docs. (_Has_addressof_mem, _Has_addressof_free, _Has_addressof) (__constexpr_addressof): Remove. (optional::operator->()): Use std::__addressof(). * include/std/optional (optional::operator->()): Adjust whitespace. * testsuite/experimental/optional/constexpr/observers/2.cc: Check that operator-> is still constexpr with overloaded operator&. Change to compile-only test. * testsuite/experimental/optional/constexpr/observers/3.cc: Change to compile-only test. From-SVN: r270826 --- libstdc++-v3/ChangeLog | 12 +++ .../include/experimental/bits/lfts_config.h | 5 +- libstdc++-v3/include/experimental/optional | 73 +++---------------- libstdc++-v3/include/std/optional | 3 +- .../optional/constexpr/observers/2.cc | 4 +- .../optional/constexpr/observers/3.cc | 2 +- 6 files changed, 28 insertions(+), 71 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3fe61147d07..cd1508ee789 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2019-05-02 Jonathan Wakely + * include/experimental/bits/lfts_config.h: Improve doc markup. + * include/experimental/optional: Improve docs. + (_Has_addressof_mem, _Has_addressof_free, _Has_addressof) + (__constexpr_addressof): Remove. + (optional::operator->()): Use std::__addressof(). + * include/std/optional (optional::operator->()): Adjust whitespace. + * testsuite/experimental/optional/constexpr/observers/2.cc: Check + that operator-> is still constexpr with overloaded operator&. Change + to compile-only test. + * testsuite/experimental/optional/constexpr/observers/3.cc: Change to + compile-only test. + * include/bits/shared_ptr.h: Improve docs. * include/bits/shared_ptr_atomic.h: Likewise. * include/bits/unique_ptr.h: Likewise. Adjust whitespace. diff --git a/libstdc++-v3/include/experimental/bits/lfts_config.h b/libstdc++-v3/include/experimental/bits/lfts_config.h index 8fc67054c55..851b8b4d43a 100644 --- a/libstdc++-v3/include/experimental/bits/lfts_config.h +++ b/libstdc++-v3/include/experimental/bits/lfts_config.h @@ -36,9 +36,8 @@ * Components defined by the _C++ Extensions for Library Fundamentals_ * Technical Specification, versions 1 and 2. * - * ISO/IEC TS 19568:2015 C++ Extensions for Library Fundamentals - * - * ISO/IEC TS 19568:2017 C++ Extensions for Library Fundamentals, Version 2 + * - ISO/IEC TS 19568:2015 C++ Extensions for Library Fundamentals + * - ISO/IEC TS 19568:2017 C++ Extensions for Library Fundamentals, Version 2 */ #if _GLIBCXX_INLINE_VERSION diff --git a/libstdc++-v3/include/experimental/optional b/libstdc++-v3/include/experimental/optional index 9a0112de854..ee06b63efd1 100644 --- a/libstdc++-v3/include/experimental/optional +++ b/libstdc++-v3/include/experimental/optional @@ -112,6 +112,8 @@ inline namespace fundamentals_v1 virtual ~bad_optional_access() noexcept = default; }; + /// @cond undocumented + void __throw_bad_optional_access(const char*) __attribute__((__noreturn__)); @@ -121,59 +123,6 @@ inline namespace fundamentals_v1 __throw_bad_optional_access(const char* __s) { _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); } -#ifndef __cpp_lib_addressof_constexpr - template - struct _Has_addressof_mem : std::false_type { }; - - template - struct _Has_addressof_mem<_Tp, - __void_t().operator&() )> - > - : std::true_type { }; - - template - struct _Has_addressof_free : std::false_type { }; - - template - struct _Has_addressof_free<_Tp, - __void_t()) )> - > - : std::true_type { }; - - /** - * @brief Trait that detects the presence of an overloaded unary operator&. - * - * Practically speaking this detects the presence of such an operator when - * called on a const-qualified lvalue (e.g. - * declval().operator&()). - */ - template - struct _Has_addressof - : std::__or_<_Has_addressof_mem<_Tp>, _Has_addressof_free<_Tp>>::type - { }; - - /** - * @brief An overload that attempts to take the address of an lvalue as a - * constant expression. Falls back to __addressof in the presence of an - * overloaded addressof operator (unary operator&), in which case the call - * will not be a constant expression. - */ - template - constexpr - enable_if_t::value, _Tp*> - __constexpr_addressof(_Tp& __t) - { return &__t; } - - /** - * @brief Fallback overload that defers to __addressof. - */ - template - 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 * and that has the responsibility for construction and the special members. @@ -452,9 +401,6 @@ inline namespace fundamentals_v1 bool _M_engaged = false; }; - template - class optional; - template using __converts_from_optional = __or_&>, @@ -473,6 +419,8 @@ inline namespace fundamentals_v1 is_assignable<_Tp&, const optional<_Up>&&>, is_assignable<_Tp&, optional<_Up>&&>>; + /// @endcond + /** * @brief Class template for optional values. */ @@ -698,13 +646,7 @@ inline namespace fundamentals_v1 // [X.Y.4.5] Observers. constexpr const _Tp* operator->() const - { -#ifndef __cpp_lib_addressof_constexpr - return __constexpr_addressof(this->_M_get()); -#else - return std::__addressof(this->_M_get()); -#endif - } + { return std::__addressof(this->_M_get()); } _Tp* operator->() @@ -796,6 +738,8 @@ inline namespace fundamentals_v1 } }; + /// @relates experimental::optional @{ + // [X.Y.8] Comparisons between optional values. template constexpr bool @@ -966,11 +910,14 @@ inline namespace fundamentals_v1 make_optional(_Tp&& __t) { return optional> { std::forward<_Tp>(__t) }; } + // @} relates experimental::optional // @} group optional } // namespace fundamentals_v1 } // namespace experimental // [X.Y.12] + /// std::hash partial specialization for experimental::optional + /// @relates experimental::optional template struct hash> { diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index 503d859bee6..ae825d3e327 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -888,8 +888,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator->() const { return std::__addressof(this->_M_get()); } - constexpr - _Tp* + constexpr _Tp* operator->() { return std::__addressof(this->_M_get()); } diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc index 5653df66833..01fa9e8278c 100644 --- a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc +++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc @@ -1,4 +1,4 @@ -// { dg-do run { target c++14 } } +// { dg-do compile { target c++14 } } // Copyright (C) 2013-2019 Free Software Foundation, Inc. // @@ -23,7 +23,7 @@ struct value_type { int i; - void* operator&() { return nullptr; } // N.B. non-const + void* operator&() const { return nullptr; } }; int main() diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc index 7cdbf7aee76..242eb8c83c6 100644 --- a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc +++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc @@ -1,4 +1,4 @@ -// { dg-do run { target c++14 } } +// { dg-do compile { target c++14 } } // Copyright (C) 2013-2019 Free Software Foundation, Inc. // -- 2.30.2