public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56973] New: crash when capturing variables in nested lambdas
@ 2013-04-15 18:35 dirkmoermans at gmail dot com
  2013-04-21 11:41 ` [Bug c++/56973] " dirkmoermans at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dirkmoermans at gmail dot com @ 2013-04-15 18:35 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-10 23:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-15 18:35 [Bug c++/56973] New: crash when capturing variables in nested lambdas dirkmoermans at gmail dot com
2013-04-21 11:41 ` [Bug c++/56973] " dirkmoermans at gmail dot com
2013-04-21 11:43 ` dirkmoermans at gmail dot com
2013-04-24  9:38 ` paolo.carlini at oracle dot com
2013-07-10 23:30 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).