What are search rules when calling a function from lambda?

The following example demonstrates the problem that I encountered in VC ++ 2010:

class Foo { template<class T> static T foo(T t) { return t; } public: void test() { auto lambda = []() { return foo(1); }; // call to Foo::foo<int> lambda(); } }; 

VC ++ produces: error C3861: 'foo' : identifier not found

If I answer the call to foo: Foo::foo(1); , then this example compiles with a warning: warning C4573: using 'Foo::foo' requires the compiler to capture 'this' , but the current capture mode does not allow it by default

What does the standard say about this case? Should an unqualified name be found? Is a qualified name required to capture this ?

+6
source share
2 answers

Microsoft has discovered this problem in a number of cases. Cm:

Domain resolution with lambdas interferes with namespace and type resolution

Template resolution in lambdas

As you can see, explicit permission allows you to find a name. There is an additional warning about this, which is also a compiler error (name resolution does not require access to this, although I can see how the compiler implementation may be required) - this is a separate error. Microsoft acknowledged this as an error and apparently prepared a fix for the next version.

+4
source

The following compiles in order. It seems to me that this is just a VS error with templates.

 struct Foo { static void foo() {} void bar() { auto f = []() { foo(); }; f(); } }; 
+2
source

Source: https://habr.com/ru/post/896465/


All Articles