Need clarification on how to capture by reference in C++ recursive lambda
While writing a library that will be shared between programs compiled under GCC 14.2.0 for X86 and ARM 6.22 for Cortex-M, I came upon a discrepancy between how the two compilers handle the recursive lambda capture when using the new 'this auto &&' deduced 'this' feature. Here is the code: /* Compiled with --std=c++23 option */ struct Foo { int s = 1 ; void zook (void) { auto f_ok = [ & s = s ] (this auto && f , int x) -> void // ok { if (x < 10) f (x + s) ; } ; auto f_bad = [ & ] (this auto && f , int x) -> void // error: invalid use of non-static data member 'Foo::s' { if (x < 10) f (x + s) ;
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.