mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
847e9cf81e
commit
72e58f18ae
|
|
@ -1,3 +1,10 @@
|
||||||
|
2014-11-12 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* 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 <jwakely@redhat.com>
|
2014-11-11 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
* include/std/type_traits (__void_t): Define new alias template.
|
* include/std/type_traits (__void_t): Define new alias template.
|
||||||
|
|
|
||||||
|
|
@ -127,12 +127,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
__throw_bad_optional_access(const char* __s)
|
__throw_bad_optional_access(const char* __s)
|
||||||
{ _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); }
|
{ _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Sfinae = void>
|
template<typename _Tp, typename = void>
|
||||||
struct _Has_addressof_impl : std::false_type { };
|
struct _Has_addressof_mem : std::false_type { };
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
struct _Has_addressof_impl<_Tp,
|
struct _Has_addressof_mem<_Tp,
|
||||||
decltype( std::declval<const _Tp&>().operator&(), void() )>
|
__void_t<decltype( std::declval<const _Tp&>().operator&() )>
|
||||||
|
>
|
||||||
|
: std::true_type { };
|
||||||
|
|
||||||
|
template<typename _Tp, typename = void>
|
||||||
|
struct _Has_addressof_free : std::false_type { };
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
struct _Has_addressof_free<_Tp,
|
||||||
|
__void_t<decltype( operator&(std::declval<const _Tp&>()) )>
|
||||||
|
>
|
||||||
: std::true_type { };
|
: std::true_type { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -143,7 +153,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
* declval<_Tp * const&>().operator&()).
|
* declval<_Tp * const&>().operator&()).
|
||||||
*/
|
*/
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
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
|
* @brief An overload that attempts to take the address of an lvalue as a
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
struct value_type
|
struct value_type
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
void* operator&() { return nullptr; } // N.B. non-const
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ struct value_type
|
||||||
int i;
|
int i;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void* operator&(const value_type&) = delete;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::experimental::optional<value_type> o { value_type { 51 } };
|
std::experimental::optional<value_type> o { value_type { 51 } };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue