Search

Nested std::bind functions give bad error (with no reference to the file being compiled) by Rubenvb89

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 616827
Opened: 10/26/2010 10:51:06 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
There seems to be a problem with the MSVC 2010 c++ <functional> implementation with regard to std::bind. See example below. The functionally equivalent using lambda functions compiles and runs as expected. Both versions of the code work in GCC 4.5+ (with -std=c++0x -pedantic -Wall -Wextra, which is why I strongly believe this is a bug in MSVC.

Forum link:
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/42cf1d81-1799-438e-bfa6-ccde2a56e56a/
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

Compile this program:

#include <functional>
using std::bind;
using std::divides;
using std::function;
using std::minus;
using namespace std::placeholders; // _1, _2 etc.
#include <iostream>
using std::cout;
using std::endl;

typedef std::function<double (double)> Func1D;

double func( const double x )
{
return x*x + x*x*x;
}

int main()
{
const double pole = 2.;

/* std::bind version, which fails on MSVC 10.0, but not on GCC 4.4+ */
Func1D fullFunc =
    bind( divides<double>(),     // division of
     bind(func, _1),         // f(x), with _1 = x
     bind(minus<double>(), _1, pole) ); // by x-a, with _1 = x
/* Lambda version, which works in both cases (GCC 4.5+ nd MSVC 10.0):
auto fullFunc = [=](const double x) -> double
{
    return func(x)/(x-pole);
};*/

cout << "(x*x+x*x*x)/(x-2) evaluated in x=3 gives: " << fullFunc(3) << endl;

return 0.;
}

Product Language

English

Operating System

Windows 7

Operating System Language

Dutch (Belgian)

Actual results

Errors without any reference to the file being compiled at all. (too long to be posted here)

Expected results

That the source file compiles fine, as it does with GCC 4.4+.

The lambda version is commented out, but works in both GCC 4.5+ and MSVC 10.0.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 6/28/2011 at 5:51 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 10/26/2010 at 7:15 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by Microsoft on 10/26/2010 at 11:22 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.