(_Mem_fn): Inherit from _Mem_fn_base.
* testsuite/20_util/function_objects/mem_fn/refqual.cc: New.
+ * include/std/functional (_Mem_fn_traits_base::__arity): New typedef.
+ (_Mem_fn_base::_Arity): New typedef.
+ (_Bind_check_arity): New class template.
+ (_Bind_helper, _Bindres_helper, _Bind_simple_helper): Check arity.
+ * testsuite/20_util/bind/ref_neg.cc: Adjust dg-error.
+
2014-10-31 Jonathan Wakely <jwakely@redhat.com>
* include/bits/stl_bvector.h (_Bvector_base): Use allocator_traits.
using __arg_types = _Pack<_ArgTypes...>;
using __maybe_type
= _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>;
+ using __arity = integral_constant<size_t, sizeof...(_ArgTypes)>;
};
template<typename _Res, typename _Class, typename... _ArgTypes>
public:
using result_type = typename _Traits::__result_type;
+ using _Arity = typename _Traits::__arity;
private:
using _Class = typename _Traits::__class_type;
{ return (*__ptr).*_M_pm; }
public:
+ using _Arity = integral_constant<size_t, 0>;
+
explicit
_Mem_fn_base(_Res _Class::*__pm) noexcept : _M_pm(__pm) { }
struct is_bind_expression<const volatile _Bind_result<_Result, _Signature>>
: public true_type { };
+ template<typename _Func, typename... _BoundArgs>
+ struct _Bind_check_arity { };
+
+ template<typename _Ret, typename... _Args, typename... _BoundArgs>
+ struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
+ {
+ static_assert(sizeof...(_BoundArgs) == sizeof...(_Args),
+ "Wrong number of arguments for function");
+ };
+
+ template<typename _Tp, typename _Class, typename... _BoundArgs>
+ struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
+ {
+ using _Arity = typename _Mem_fn<_Tp _Class::*>::_Arity;
+ static_assert(sizeof...(_BoundArgs) == _Arity::value + 1,
+ "Wrong number of arguments for pointer-to-member");
+ };
+
// 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<bool _SocketLike, typename _Func, typename... _BoundArgs>
struct _Bind_helper
+ : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
{
typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
__maybe_type;
template<typename _Result, typename _Func, typename... _BoundArgs>
struct _Bindres_helper
+ : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
{
typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
__maybe_type;
template<typename _Func, typename... _BoundArgs>
struct _Bind_simple_helper
+ : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
{
typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
__maybe_type;
{
const int dummy = 0;
std::bind(&inc, _1)(0); // { dg-error "no match" }
- // { dg-error "rvalue|const" "" { target *-*-* } 1315 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1329 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1343 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1357 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1213 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1227 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1241 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1255 }
std::bind(&inc, std::ref(dummy))(); // { dg-error "no match" }
}