[PATCH] PR66284 remove std::function special case for reference_wrapper

Jonathan Wakely jwakely@redhat.com
Thu Jan 12 14:30:00 GMT 2017


As the PR says, we follow the Boost.Function semantics w.r.t.
construction of std::function from a std::reference_wrapper, but other
std::lib implementations do something different. I reported a defect
(LWG 2781) and the consensus is to clarify the standard to bless the
other implementations. This modifies our std::function to have the
correct semantics.

Previously passing a std::reference_wrapper<F> to a std::function
constructor would unwrap it and store an F*, but target_type() would
return typeid(F). With the change it stores std::reference_wrapper<F>
and target_type() returns typeid(std::reference_wrapper<F>). This is
more straightforward, as there's no cleverness being done behind the
scenes.

The previous semantics required a special case in the non-const
overload of std::function::target() to ensure it couldn't be used to
drop const-qualification when the std::function was constructed from a
std::reference_wrapper<const F>. Now that there's no unwrapping of
reference_wrappers that isn't needed, and the non-const overload of
target() can simply call the const overload and then const_cast the
result.

These are user-visible changes, but I doubt much code will be affected.

	PR libstdc++/66284
	* doc/xml/manual/intro.xml: Document LWG 2781 change.
	* doc/html/*: Regenerate.
	* include/std/functional (_Function_base::_Ref_manager): Remove.
	(_Function_handler): Remove partial specializations for
	reference_wrapper.
	(function::target): Remove special case for const qualification.
	* testsuite/20_util/function/6.cc: Adjust tests for target type.
	* testsuite/20_util/function/7.cc: Likewise.
	* testsuite/20_util/function/8.cc: Likewise.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 16342 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170112/3d83a8c7/attachment.bin>


More information about the Gcc-patches mailing list