http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46056
Summary: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: alser...@inbox.ru Target: i686-pc-linux-gnu The following test crashes once compiled by g++ (GCC) 4.6.0 20101017 (experimental) on i686-pc-linux-gnu // Test for range-based for loop inside lambda // { dg-options "-std=c++0x" } // { dg-do run } #define _GLIBCXX_DEBUG #include <iostream> #include <vector> int main(){ std::vector<int> v(1); [&]() { for(auto i: v); }(); } Apparently it crashes during safe sequence destruction once main is finished. It does work (i.e., does not crash) without any one of _GLIBCXX_DEBUG, lambda, or range-based for. Also, it does not crash if optimization is on (e.g., with -O).