Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#4566 closed Bugs (fixed)

Binding to a class member with lambda::bind() can cause const qualifier mismatch.

Reported by: David Larsson <david.larsson@…> Owned by: No-Maintainer
Milestone: To Be Determined Component: lambda
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

The following code (omitting namespaces) would compile correctly in Boost 1.43.0, but now fails with error boost/lambda/detail/function_adaptors.hpp(264) : error C2440 : 'return' : cannot convert from 'const int' to 'int &:

bind( &pair<int,int>::first, _1 )( make_pair( 1, 0 ) );

The boost::lambda::bind() expression creates a function that returns the first element of a pair, and then applies this to a const pair<int,int>. The following will work, because the argument is not constant:

pair<int,int> x(1,0);
bind( &pair<int,int>::first, _1 )( x );

A workaround for this issue is to specify the return value of bind() explicitly, but it shouldn't be necessary for this simple case:

bind<int>( &pair<int,int>::first, _1 )( make_pair( 1, 0 ) );

I have tested this on VC8 and VC10 with identical results.

Thanks for a great library,

/David

Attachments (1)

lambda.cpp (180 bytes ) - added by David Larsson <david.larsson@…> 12 years ago.
Repro case

Download all attachments as: .zip

Change History (4)

by David Larsson <david.larsson@…>, 12 years ago

Attachment: lambda.cpp added

Repro case

comment:1 by Steven Watanabe, 12 years ago

Resolution: fixed
Status: newclosed

(In [67640]) Fix return type deduction for pointers to data members. Fixes #4962. Fixes #4566.

comment:2 by anonymous, 8 years ago

+1

comment:3 by anonymous, 8 years ago

thanks? I correct my boost 1.44

Note: See TracTickets for help on using tickets.