Problem with non-const operator() and bind - by Leigh Johnston

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 540098 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 3/8/2010 9:25:07 AM
Access Restriction Public


The following does not compile in VS2008 and (apparently) VS2010

#include <functional>

struct foo
  void operator()() { }

int main() 
  foo o;
Sign in to post a comment.
Posted by Stephan [MSFT] on 6/22/2010 at 2:19 PM

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

As always, if you have any further questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Stephan [MSFT] on 3/9/2010 at 8:12 PM

Thanks for reporting this bug. We believed that we had fixed this in VC9 SP1, but we missed the zero-argument case. Although it's too late to fix this in VC10, we're keeping this bug active so that it can be fixed in a future release.

Some additional explanation: We simulate variadic templates with macros. This works well for things like make_shared<T>(), but multiplies <functional>'s inherent complexity, and bind() is the most severely affected. That's one of the reasons why apparently simple bind() bugs can require very complicated fixes.

We have a regression test to ensure that the one-argument case works, although more complicated uses of bind() may trigger other bugs. (Fortunately, while VC10's bind() implementation is still fragile, lambdas supersede 99% of bind() uses, and the remaining 1% are better dealt with using named functors.) Here's an example:

C:\Temp>type meow.cpp
#include <functional>
#include <iostream>
#include <ostream>
using namespace std;
using namespace std::tr1;

struct Functor {
    typedef int result_type;

    int operator()(int x) { // NON-const
        return x * 2;

int main() {
    Functor f; // NON-const

    int r = bind(f, 123)();

    cout << "This should be 246: " << r << endl;

C:\Temp>cl /EHsc /nologo /W4 meow.cpp

This should be 246: 246

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

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 3/8/2010 at 9:51 PM

Thanks for your feedback.

We are routing 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 3/8/2010 at 7:04 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(