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

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