This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/56973] New: crash when capturing variables in nested lambdas
- From: "dirkmoermans at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 15 Apr 2013 18:35:00 +0000
- Subject: [Bug c++/56973] New: crash when capturing variables in nested lambdas
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56973
Bug #: 56973
Summary: crash when capturing variables in nested lambdas
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dirkmoermans@gmail.com
The valid C++11 program below segfaults on my machine:
=====
#include <cassert>
#include <cstring>
#include <iterator>
void test(const char* s)
{
constexpr /*static*/ struct {const char* s;} ar[]={
{"e4"},
{"e5"},
{"Nf3"},
{"Nc6"},
{"Bb5"},
{"a6"}
};
auto it=std::begin(ar);
auto compare=[&it](const char* s)
{
assert(std::strcmp(it->s,s)==0);
};
auto test=[&](const char* s)
{
it=std::begin(ar);
compare(s);
};
test(s);
}
int main(int argc, const char* argv[])
{
test(argv[1]);
test(argv[2]);
test(argv[3]);
return 0;
}
=====
I compile with: $ g++ -g -O --std=c++11 bug.cc.
I run as: $ ./a.out e4 e4 e4
My machine is a 64 bit linux intel core duo 2 (T4200).
If I make "ar" static the program passes, so I assume that ar is overwritten
prematurely on the stack.
The error only occurs from optimization-levels "-O" onwards.