Bug 79798 - [7 Regression] std::bind loses cv-qualifiers in result_of type
Summary: [7 Regression] std::bind loses cv-qualifiers in result_of type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: 7.0
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2017-03-01 23:48 UTC by Jonathan Wakely
Modified: 2017-03-02 07:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.3.0
Known to fail: 7.0
Last reconfirmed: 2017-03-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2017-03-01 23:48:45 UTC
Another case like PR 79486, this fails to compile with trunk:

#include <functional>

struct X { };
const X f(int);

struct Y {
  void operator()(X&&) = delete;
  int operator()(const X&&);
};

auto b = std::bind(Y(), std::bind(f, std::placeholders::_1));
auto i = b(1);


x.cc:12:13: error: no match for call to ‘(std::_Bind<Y(std::_Bind<const X (*(std::_Placeholder<1>))(int)>)>) (int)’
 auto i = b(1);
             ^
Comment 1 Jonathan Wakely 2017-03-01 23:55:42 UTC
We need to add && to the arg types in the result_of argument, so that top-level cv qualifiers aren't lost in the function type that result_of requires us to use:

--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -502,7 +502,7 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
 
       template<typename _Fn, typename _CallArgs, typename... _BArgs>
        using _Res_type_impl
-         = typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>...) >::type;
+         = typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
 
       template<typename _CallArgs>
        using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;

This would be fixed by adopting the proposed invoke_result and using that instead of result_of, which we've agreed to deprecate.
Comment 2 Jonathan Wakely 2017-03-02 03:44:12 UTC
Author: redi
Date: Thu Mar  2 03:43:36 2017
New Revision: 245827

URL: https://gcc.gnu.org/viewcvs?rev=245827&root=gcc&view=rev
Log:
PR 79798 Fix incorrect use of std::result_of in std::bind

	PR libstdc++/79798
	* include/std/functional (bind::_Res_type_impl): Fix incorrect use of
	result_of that loses top-level cv-qualifiers.
	* testsuite/20_util/bind/79798.cc: New test.

Added:
    trunk/libstdc++-v3/testsuite/20_util/bind/79798.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/functional
Comment 3 Jonathan Wakely 2017-03-02 07:53:39 UTC
Fixed