struct is_bind_expression<_Bind_result<_Result, _Signature> >
: public true_type { };
- template<typename _Functor, typename... _ArgTypes>
+ // Trait type used to remove std::bind() from overload set via SFINAE
+ // when first argument has integer type, so that std::bind() will
+ // not be a better match than ::bind() from the BSD Sockets API.
+ template<typename _Tp>
+ class __is_socketlike
+ {
+ typedef typename decay<_Tp>::type _Tp2;
+ public:
+ static const bool value =
+ is_integral<_Tp2>::value || is_enum<_Tp2>::value;
+ };
+
+ template<bool _SocketLike, typename _Func, typename... _BoundArgs>
struct _Bind_helper
{
- typedef _Maybe_wrap_member_pointer<typename decay<_Functor>::type>
+ typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
__maybe_type;
- typedef typename __maybe_type::type __functor_type;
- typedef _Bind<__functor_type(typename decay<_ArgTypes>::type...)> type;
+ typedef typename __maybe_type::type __func_type;
+ typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
};
+ // Partial specialization for is_socketlike == true, does not define
+ // nested type so std::bind() will not participate in overload resolution
+ // when the first argument might be a socket file descriptor.
+ template<typename _Func, typename... _BoundArgs>
+ struct _Bind_helper<true, _Func, _BoundArgs...>
+ { };
+
/**
* @brief Function template for std::bind.
* @ingroup binders
*/
- template<typename _Functor, typename... _ArgTypes>
- inline
- typename _Bind_helper<_Functor, _ArgTypes...>::type
- bind(_Functor&& __f, _ArgTypes&&... __args)
+ template<typename _Func, typename... _BoundArgs>
+ inline typename
+ _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
+ bind(_Func&& __f, _BoundArgs&&... __args)
{
- typedef _Bind_helper<_Functor, _ArgTypes...> __helper_type;
+ typedef _Bind_helper<false, _Func, _BoundArgs...> __helper_type;
typedef typename __helper_type::__maybe_type __maybe_type;
typedef typename __helper_type::type __result_type;
- return __result_type(__maybe_type::__do_wrap(std::forward<_Functor>(__f)),
- std::forward<_ArgTypes>(__args)...);
+ return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
+ std::forward<_BoundArgs>(__args)...);
}
- template<typename _Result, typename _Functor, typename... _ArgTypes>
+ template<typename _Result, typename _Func, typename... _BoundArgs>
struct _Bindres_helper
{
- typedef _Maybe_wrap_member_pointer<typename decay<_Functor>::type>
+ typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
__maybe_type;
typedef typename __maybe_type::type __functor_type;
typedef _Bind_result<_Result,
- __functor_type(typename decay<_ArgTypes>::type...)>
+ __functor_type(typename decay<_BoundArgs>::type...)>
type;
};
* @brief Function template for std::bind<R>.
* @ingroup binders
*/
- template<typename _Result, typename _Functor, typename... _ArgTypes>
+ template<typename _Result, typename _Func, typename... _BoundArgs>
inline
- typename _Bindres_helper<_Result, _Functor, _ArgTypes...>::type
- bind(_Functor&& __f, _ArgTypes&&... __args)
+ typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
+ bind(_Func&& __f, _BoundArgs&&... __args)
{
- typedef _Bindres_helper<_Result, _Functor, _ArgTypes...> __helper_type;
+ typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
typedef typename __helper_type::__maybe_type __maybe_type;
typedef typename __helper_type::type __result_type;
- return __result_type(__maybe_type::__do_wrap(std::forward<_Functor>(__f)),
- std::forward<_ArgTypes>(__args)...);
+ return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
+ std::forward<_BoundArgs>(__args)...);
}
/**
--- /dev/null
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 20.8.9 Function template bind
+
+// Verify that calls to bind() in BSD sockets API do not match std::bind()
+// (this is a GNU extension)
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <functional>
+
+struct my_sockaddr { };
+typedef long my_socklen_t;
+int bind(int, const my_sockaddr*, my_socklen_t);
+
+using namespace std;
+
+int test01()
+{
+ int fd = 1;
+ my_sockaddr sa; // N.B. non-const
+ size_t len = sizeof(sa); // N.B. size_t not socklen_t
+ return bind(fd, &sa, sizeof(sa));
+}
+