https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96184
Bug ID: 96184 Summary: GCC treats "use of local variable with automatic storage from containing function" differently in versions Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: haoxintu at gmail dot com Target Milestone: --- Hi, all. This code, GCC-trunk and other versions (etc., GCC-10) treat it differently. $cat test.cc int main(){ int a = 10; int const b = 10; auto p = [ ] () noexcept ( b ? 0 : a = b) { return 0;}; return 0; } $g++-trunk -std=c++14 test.cc //nothing $g++-10 -std=c++14 test.cc test.cc: In function ‘int main()’: test.cc:4:40: error: use of local variable with automatic storage from containing function 4 | auto p = [ ] () noexcept ( b ? 0 : a = b) { return 0;}; | ^ test.cc:2:9: note: ‘int a’ declared here 2 | int a = 10; | ^ I am wondering is this a enhancement of GCC-trunk? I also test this in other GCC versions. Weirdly, only GCC-9 or GCC-10 rejects it while other versions from 6.1 to 8.3 (also trunk) accepts it. I don't know how GCC deals with this case and this also makes me confused. Thanks, Haoxin