public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56901] New: [4.9 regression] lambda with implicit capture by reference
@ 2013-04-10  8:29 zeratul976 at hotmail dot com
  2013-04-10  8:30 ` [Bug c++/56901] " zeratul976 at hotmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: zeratul976 at hotmail dot com @ 2013-04-10  8:29 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56901
           Summary: [4.9 regression] lambda with implicit capture by
                    reference
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zeratul976@hotmail.com


The following code compiles with gcc 4.8 and clang, but not with gcc 4.9:


template <typename>
void foo_impl()
{
    int data;
    auto L = [&](){ return data; };
    [&](){ L(); }();
}

void foo()
{
    foo_impl<int>();
}


The error is:


test.cpp: In instantiation of 'foo_impl() [with <template-parameter-1-1> =
int]::__lambda1':
test.cpp:6:12:   required from 'struct foo_impl() [with
<template-parameter-1-1> = int]::__lambda1'
test.cpp:6:19:   required from 'void foo_impl() [with <template-parameter-1-1>
= int]'
test.cpp:11:19:   required from here
test.cpp:5:14: error: uninitialized const member 'foo_impl() [with
<template-parameter-1-1> = int]::__lambda0::__data'
     auto L = [&](){ return data; };
              ^


The error goes away if:
  - foo_impl is made a nontemplate
  - the call to the second lambda is inlined
  - either lambda is made to capture by value instead of reference


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

end of thread, other threads:[~2013-04-16 21:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-10  8:29 [Bug c++/56901] New: [4.9 regression] lambda with implicit capture by reference zeratul976 at hotmail dot com
2013-04-10  8:30 ` [Bug c++/56901] " zeratul976 at hotmail dot com
2013-04-10  8:50 ` paolo.carlini at oracle dot com
2013-04-10  9:30 ` rguenth at gcc dot gnu.org
2013-04-11 16:51 ` jason at gcc dot gnu.org
2013-04-16 21:43 ` 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).