public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dirkmoermans at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/56973] New: crash when capturing variables in nested lambdas
Date: Mon, 15 Apr 2013 18:35:00 -0000	[thread overview]
Message-ID: <bug-56973-4@http.gcc.gnu.org/bugzilla/> (raw)


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.


             reply	other threads:[~2013-04-15 18:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-15 18:35 dirkmoermans at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-56973-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).