https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081
Bug ID: 104081 Summary: Variable optimized out despite -Og Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: matthias at urlichs dot de Target Milestone: --- I expect the optimizer, when confronted with "-Og", to keep my variables debuggable. (I also expect (of me) to not make terminally stupid mistakes like the one exhibited here, but that's a different problem …) // "data" is a std::string_view (gdb) l 19 if(data.length() == 0) 20 throw_invalid("empty",data); 21 } 22 for (const auto& c : data) { 23 if ('0' < c || '9' > c) 24 throw_invalid("not a number",data); 25 val = val*10 + c-'0'; 26 } 27 if(neg) 28 val = -val; (gdb) p data $1 = <optimized out> (gdb) p c $2 = <optimized out> (gdb) q Options: g++-12 -march=native -Og -g -xc++ -std=c++17 …