From 72e58f18aed02cadf0c19f11b8d524fab9613cac Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 12 Nov 2014 00:16:19 +0000 Subject: [PATCH] optional (_Has_addressof): Check for non-member operator&. * include/experimental/optional (_Has_addressof): Check for non-member operator&. * testsuite/experimental/optional/observers/2.cc: Add operator&. * testsuite/experimental/optional/constexpr/observers/2.cc: Likewise. From-SVN: r217397 --- libstdc++-v3/ChangeLog | 7 ++++++ libstdc++-v3/include/experimental/optional | 24 ++++++++++++++----- .../optional/constexpr/observers/2.cc | 2 ++ .../experimental/optional/observers/2.cc | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4a17fd0b9b3..0c9d430c70c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2014-11-12 Jonathan Wakely + + * include/experimental/optional (_Has_addressof): Check for non-member + operator&. + * testsuite/experimental/optional/observers/2.cc: Add operator&. + * testsuite/experimental/optional/constexpr/observers/2.cc: Likewise. + 2014-11-11 Jonathan Wakely * include/std/type_traits (__void_t): Define new alias template. diff --git a/libstdc++-v3/include/experimental/optional b/libstdc++-v3/include/experimental/optional index 7e01abedb76..2d3127a7b1d 100644 --- a/libstdc++-v3/include/experimental/optional +++ b/libstdc++-v3/include/experimental/optional @@ -127,13 +127,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __throw_bad_optional_access(const char* __s) { _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); } - template - struct _Has_addressof_impl : std::false_type { }; + template + struct _Has_addressof_mem : std::false_type { }; template - struct _Has_addressof_impl<_Tp, - decltype( std::declval().operator&(), void() )> - : std::true_type { }; + 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&. @@ -143,7 +153,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * declval<_Tp * const&>().operator&()). */ template - struct _Has_addressof : _Has_addressof_impl<_Tp>::type { }; + 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 diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc index 14b5e3b1f52..2c9215c6924 100644 --- a/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc +++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc @@ -26,6 +26,8 @@ struct value_type { int i; + + void* operator&() { return nullptr; } // N.B. non-const }; int main() diff --git a/libstdc++-v3/testsuite/experimental/optional/observers/2.cc b/libstdc++-v3/testsuite/experimental/optional/observers/2.cc index 8499b4779d2..9fb2edbd89a 100644 --- a/libstdc++-v3/testsuite/experimental/optional/observers/2.cc +++ b/libstdc++-v3/testsuite/experimental/optional/observers/2.cc @@ -26,6 +26,8 @@ struct value_type int i; }; +void* operator&(const value_type&) = delete; + int main() { std::experimental::optional o { value_type { 51 } }; -- 2.30.2