Bug 52612 - std::tr1::bind doesn't work with placeholders
Summary: std::tr1::bind doesn't work with placeholders
Status: RESOLVED DUPLICATE of bug 35569
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-19 09:45 UTC by Anthony Williams
Modified: 2012-03-19 11:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Example code that fails (122 bytes, text/x-c++src)
2012-03-19 09:45 UTC, Anthony Williams
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Williams 2012-03-19 09:45:02 UTC
Created attachment 26913 [details]
Example code that fails

The following simple code doesn't compile:

#include <tr1/functional>

int return_int2(int,int)
{
    return 42;
}

int main(){
    std::tr1::bind(return_int2,32,std::tr1::placeholders::_1)(5);
}

Compiler output:

$g++ t2.cpp 
t2.cpp: In function ‘int main()’:
t2.cpp:9:64: error: no match for call to ‘(std::tr1::_Bind<int (*(int, std::tr1::_Placeholder<1>))(int, int)>) (int)’
/usr/include/c++/4.6/tr1/functional:1134:11: note: candidates are:
/usr/include/c++/4.6/tr1/functional:1205:9: note: typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int]
/usr/include/c++/4.6/tr1/functional:1205:9: note:   no known conversion for argument 1 from ‘int’ to ‘int&’
/usr/include/c++/4.6/tr1/functional:1216:9: note: typename std::tr1::result_of<const _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) const [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<const _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int]
/usr/include/c++/4.6/tr1/functional:1216:9: note:   no known conversion for argument 1 from ‘int’ to ‘int&’
/usr/include/c++/4.6/tr1/functional:1228:9: note: typename std::tr1::result_of<volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) volatile [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int]
/usr/include/c++/4.6/tr1/functional:1228:9: note:   no known conversion for argument 1 from ‘int’ to ‘int&’
/usr/include/c++/4.6/tr1/functional:1241:9: note: typename std::tr1::result_of<const volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) const volatile [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<const volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int]
/usr/include/c++/4.6/tr1/functional:1241:9: note:   no known conversion for argument 1 from ‘int’ to ‘int&’


$ g++ --version
g++ (Ubuntu 4.6.0-3~ppa1) 4.6.1 20110409 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Paolo Carlini 2012-03-19 10:39:10 UTC
I seem to remember that this is a known problem of the tr1 version of this facility, per the specs. Changing the snippet like the following works:

  ...

  int main()
  {
    int n = 5;
    std::tr1::bind(return_int2,32,std::tr1::placeholders::_1)(n);
  }
Comment 2 Jonathan Wakely 2012-03-19 10:57:38 UTC
See my comments on PR 50320

C++11 std::bind works with rvalues, as of GCC 4.5

*** This bug has been marked as a duplicate of bug 35569 ***
Comment 3 Anthony Williams 2012-03-19 11:15:45 UTC
It's frustrating that the TR1 spec specifies lvalues (I assumed it was the same as std::bind). This came up in supposedly-portable code that works with MSVC's TR1 bind.

Good thing it's fixed for std::bind.
Comment 4 Jonathan Wakely 2012-03-19 11:24:15 UTC
Yeah, it's not ideal, but I have very little motivation (and even less time!) to improve tr1::bind now. For C++03 code there's boost::bind and for C++11 code there's std::bind.