public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
@ 2012-11-29 19:39 akramnik at gmail dot com
  2012-11-29 20:04 ` [Bug c++/55532] " matt at godbolt dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: akramnik at gmail dot com @ 2012-11-29 19:39 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

             Bug #: 55532
           Summary: Runtime segfault calling mutable lambda wrapped in a
                    non-mutable lambda within a template function
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akramnik@gmail.com


The following code segfaults at runtime when we call fun2.

Compiled with "g++-4.7 -std=c++11 -o main main.cpp"

Code:

struct Foo {
    void doit() {
    }
};

template<typename T>
void oops(Foo &foo, const T &) {
    auto fun = [&] () mutable {
        foo.doit();
    };
    auto fun2 = [=]() {
        fun();
    };
    fun2();
}

int main() {
    Foo foo;
    oops(foo, 1);
}

Note:  if we make it non-templated function, we get a compiler error which
correctly detects the mutable/non-mutable disparity.

main.cpp:11:13: error: passing ‘const oops(Foo&, const int&)::<lambda()>’ as
‘this’ argument of ‘oops(Foo&, const int&)::<lambda()>’ discards qualifiers
[-fpermissive]


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
@ 2012-11-29 20:04 ` matt at godbolt dot org
  2012-11-29 20:16 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: matt at godbolt dot org @ 2012-11-29 20:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

--- Comment #1 from Matt Godbolt <matt at godbolt dot org> 2012-11-29 20:03:47 UTC ---
I can reproduce this on GCC 4.8 (rev 185382], and g++ 4.6.3.  Adding -O makes
the issue go away (as the whole program is optimized to "return 0;").

From the assembler dump the segv appears to happen when the compiler is
generating a "this" pointer for the inner lambda:

void oops<int>(Foo&, int const&)::{lambda()#1}::_FUN():
    pushq    %rbp
    movq    %rsp, %rbp
>>>	movl	$0, %edi
    call    void oops<int>(Foo&, int const&)::{lambda()#1}::operator()()
    popq    %rbp
    ret

[this output can also be seen at http://url.godbolt.org/mdjvf ]


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
  2012-11-29 20:04 ` [Bug c++/55532] " matt at godbolt dot org
@ 2012-11-29 20:16 ` paolo.carlini at oracle dot com
  2012-12-06 15:54 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-29 20:16 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|akramnik at gmail dot com   |
             Blocks|                            |54367
           Severity|major                       |normal


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
  2012-11-29 20:04 ` [Bug c++/55532] " matt at godbolt dot org
  2012-11-29 20:16 ` paolo.carlini at oracle dot com
@ 2012-12-06 15:54 ` redi at gcc dot gnu.org
  2013-03-13  3:13 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-06 15:54 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-12-06
     Ever Confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-06 15:54:18 UTC ---
Confirmed, I think the code should be rejected.


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
                   ` (2 preceding siblings ...)
  2012-12-06 15:54 ` redi at gcc dot gnu.org
@ 2013-03-13  3:13 ` jason at gcc dot gnu.org
  2013-03-17  2:37 ` jason at gcc dot gnu.org
  2013-03-23 19:22 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-13  3:13 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |jason at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
                   ` (3 preceding siblings ...)
  2013-03-13  3:13 ` jason at gcc dot gnu.org
@ 2013-03-17  2:37 ` jason at gcc dot gnu.org
  2013-03-23 19:22 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-17  2:37 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-17 02:35:35 UTC ---
Author: jason
Date: Sun Mar 17 02:35:18 2013
New Revision: 196729

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196729
Log:
    PR c++/56447
    PR c++/55532
    * pt.c (instantiate_class_template_1): Instantiate lambda capture
    list here.
    (tsubst_copy_and_build): Not here.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv8.C
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mutable2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c


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

* [Bug c++/55532] Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function
  2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
                   ` (4 preceding siblings ...)
  2013-03-17  2:37 ` jason at gcc dot gnu.org
@ 2013-03-23 19:22 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-23 19:22 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55532

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.1

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-23 19:21:55 UTC ---
Fixed for 4.8.1.


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

end of thread, other threads:[~2013-03-23 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-29 19:39 [Bug c++/55532] New: Runtime segfault calling mutable lambda wrapped in a non-mutable lambda within a template function akramnik at gmail dot com
2012-11-29 20:04 ` [Bug c++/55532] " matt at godbolt dot org
2012-11-29 20:16 ` paolo.carlini at oracle dot com
2012-12-06 15:54 ` redi at gcc dot gnu.org
2013-03-13  3:13 ` jason at gcc dot gnu.org
2013-03-17  2:37 ` jason at gcc dot gnu.org
2013-03-23 19:22 ` jason at gcc dot gnu.org

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).