From: Jesse Perla on
Are there supposed to be some strange interactions with C++0X lambdas
and ADL? The following code, works in Intel 11.1 and GCC4.5 but fails
in VisualStudio 2010. Is this a Microsoft bug? If so, I posted it on
https://connect.microsoft.com/VisualStudio/feedback/details/585643/bug-in-adl-lookup-with-c-0x-lambdas#details
if anyone wants to vote for it. Thanks

namespace X
{
struct Y{};

template<typename F>
void myfunc(F f, Y y) {}
}

double identity(double x){return x;}

int main()
{
myfunc(identity, X::Y()); //ADL Works as expected
myfunc([](double x){return x;}, X::Y()); //THIS FAILS! Doesn't seem
to like rvalue lambdas

auto f = [](double x){return x;};
myfunc(f, X::Y()); //Strangely, this works fine
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 12 Aug., 07:27, Jesse Perla <jessepe...(a)gmail.com> wrote:
> Are there supposed to be some strange interactions with C++0X lambdas
> and ADL? The following code, works in Intel 11.1 and GCC4.5 but fails
> in VisualStudio 2010. Is this a Microsoft bug? If so, I posted it onhttps://connect.microsoft.com/VisualStudio/feedback/details/585643/bu...
> if anyone wants to vote for it. Thanks

This link seems truncated and I could not successfully resolve it (not
even from your OP).

> namespace X
> {
> struct Y{};
>
> template<typename F>
> void myfunc(F f, Y y) {}
> }

[..]

> int main()
> {

[..]

> myfunc([](double x){return x;}, X::Y()); //THIS FAILS! Doesn't seem
> to like rvalue lambdas
>
> auto f = [](double x){return x;};
> myfunc(f, X::Y()); //Strangely, this works fine
> }

The difference between these two invocations of myfunc looks
like a compiler bug to me. The compiler should accept both
versions. In fact the lambda closure case is not essentially
different from

struct { double operator()(double x) const { return x; } } obj;
myfunc(decltype(obj)(), X::Y());

within the function body of main. The conditions for
ADL require a function call (this is satisfied) and an
/unqualified-id/ as /postfix-expression/. This seems
to be satisfied as well. Comparing the mechanism of
ADL with the specification of a lambda-expression I
don't see a special interaction here, especially not
one related to the value category of the argument.

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]