This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR libstdc++/83427 detect weak result type from noexcept functions


Richard Smith pointed out that our "weak result type" implementation
(used by std::reference_wrapper and std::bind) doesn't work for
noexcept functions.

The simple fix is to adjust every partial specialization to include
noexcept deduction (which I'll do for gcc-7-branch), but I took the
opportunity to clean things up a bit on trunk. We already have the
required logic in _Mem_fn_traits, so I replaced all the partial
specializations for member function pointers with new helpers that use
_Mem_fn_traits. That adds support for ref-qualifiers as well, which
was missing.

I've also removed a number of useless partial specializations that can
never match anything. We don't need to support cv-qualified functions
types (so-called abominable function types) in std::bind, because you
can never call it with an argument of such a type, so I removed all
the _Weak_result_type_impl<R(Args...) cv> partial specializations. We
do need to support those types in std::reference_wrapper, but that
seems to be an obvious defect, so I've reported an issue to fix the
standard.  In the meanwhile I'm not adding noexcept deduction to those
specializations, because I want them to go away, not get fixed.
Finally, we also don't need _Weak_result_type_impl<R(&)(Args)> because
std::bind decays its functor, and reference_wrapper doesn't need a
weak result type for references to functions (and my defect report
might make them undefined anyway).

	PR libstdc++/83427
	* include/bits/refwrap.h (_Maybe_unary_or_binary_function): Move here
	from <bits/std_function.h>.
	(_Mem_fn_traits_base, _Mem_fn_traits): Move here, from <functional>.
	(_Weak_result_type_impl, _Reference_wrapper_base): Deduce noexcept
	for function types. Remove partial specializations for member
	functions.
	(_Weak_result_type_impl): Remove unused partial specializations for
	non-referenceable function types and for references to functions.
	(_Weak_result_type_memfun, _Reference_wrapper_base_memfun): New
	helpers to handle member functions via _Mem_fn_traits.
	(_Weak_result_type, reference_wrapper): Derive from new helpers.
	* include/bits/std_function.h (_Maybe_unary_or_binary_function): Move
	to <bits/refwrap.h>.
	* include/std/functional (_Pack, _AllConvertible, _NotSame): Remove.
	(_Mem_fn_traits_base, _Mem_fn_traits): Move to <bits/refwrap.h>.
	* testsuite/20_util/bind/83427.cc: New test.
	* testsuite/20_util/bind/refqual.cc: Add noexcept to functions and
	check for weak result types.
	* testsuite/20_util/reference_wrapper/83427.cc: New test.
Tested powerpc64le-linux, committed to trunk.

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]