lambda to pointer to function conversion
От: Nikita.Trophimov  
Дата: 01.03.13 04:15
Оценка:
int main()
{
   void (*fp)() = [&]{}; // Ok
}


int main()
{
   int foo;
   void (*fp)() = [&]{ foo = 0; }; // error: cannot convert 'main()::<lambda()>' to 'void (*)()' in initialization
}


int main()
{
   int foo;
   void (*fp)() = [&foo]{}; // error: cannot convert 'main()::<lambda()>' to 'void (*)()' in initialization
}


gcc 4.7.2.

По-моему, первый кусок кода также не должен был скомпилироваться.

ISO/IEC 14882:2011

5.1.2 Lambda expressions [expr.prim.lambda]

6 The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const
conversion function to pointer to function having the same parameter and return types as the closure type’s
function call operator.


Баг gcc?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.