https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84471
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Instruction reordering |Debugger jumps back to |happens in lambdas even |lambda capture location |with -O0 |every time a captured | |variable is odr-used --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- Every time a captured variable is odr-used in the lambda body, the debugger jumps back to the location of the capture list: $ cat lambda.cc int main(int argc, char**) { int x = 1; auto f = [&x, &argc](const char* i) { i += x; i -= argc; i += argc - x; return i; }; f(" "); } $ g++ -g lambda.cc -o lambda $ gdb -q -ex start -ex 'py [gdb.execute("step") for n in range(14)]' ./lambda Reading symbols from ./lambda... Temporary breakpoint 1 at 0x40117a: file lambda.cc, line 3. Starting program: /tmp/lambda [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Temporary breakpoint 1, main (argc=1) at lambda.cc:3 3 int x = 1; 9 }; 10 f(" "); operator() (__closure=0x7fffffffda60, i=0x402004 " ") at lambda.cc:5 5 i += x; 4 auto f = [&x, &argc](const char* i) { 5 i += x; 6 i -= argc; 4 auto f = [&x, &argc](const char* i) { 6 i -= argc; 7 i += argc - x; 4 auto f = [&x, &argc](const char* i) { 7 i += argc - x; 4 auto f = [&x, &argc](const char* i) { 7 i += argc - x; 8 return i; We keep returning to line 4 (the capture) every time the captured variiable is odr-used. I've updated the summary. There is no instruction reordering, the debuginfo just contains line info that causes the debugger to jump around. That has nothing to do with the actual instructions being executed.