public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52739] New: [c++0x] Segfault because of nested lambda member capture inside member template
@ 2012-03-27 14:51 bruno-gcc at defraine dot net
  2012-03-27 15:08 ` [Bug c++/52739] " redi at gcc dot gnu.org
  2012-03-27 16:38 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: bruno-gcc at defraine dot net @ 2012-03-27 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52739
           Summary: [c++0x] Segfault because of nested lambda member
                    capture inside member template
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bruno-gcc@defraine.net


In the following specific combination of a class template, a member template,
and two nested lambdas, where the outer lambda captures `this' and the inner
lambda captures a member of `this', I can trigger a gcc segmentation fault.

test.cpp contains:

template<int n>
class Test {
    int i;
public:
    template<typename Func>
    void foo(const Func& f);
};

template<int n> template<typename Func>
void Test<n>::foo(const Func& f) {
    auto lam1 = [this,&f]() {
        auto lam2 = [&i,&f]() {
            f(i);
        };
    };
}

void bar(Test<1>& t) {
    t.foo([](int i) { });
}

The compilation:

$ g++ -Wall -O2 -std=c++0x -c test.cpp 
test.cpp: In lambda function:
test.cpp:12:17: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

The segmentation fault is always reproducible with gcc 4.6.2 on two platforms:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc-4.6.2/libexec/gcc/x86_64-unknown-linux-gnu/4.6.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-4.6.2
--enable-languages=c,c++,fortran --disable-multilib
Thread model: posix
gcc version 4.6.2 (GCC) 

$ g++-fsf-4.6 -v
Using built-in specs.
COLLECT_GCC=g++-fsf-4.6
COLLECT_LTO_WRAPPER=/sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.2.0/4.6.2/lto-wrapper
Target: x86_64-apple-darwin11.2.0
Configured with: ../gcc-4.6.2/configure --prefix=/sw --prefix=/sw/lib/gcc4.6
--mandir=/sw/share/man --infodir=/sw/lib/gcc4.6/info
--enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw
--with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw
--with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
--program-suffix=-fsf-4.6 --enable-cloog-backend=isl
Thread model: posix
gcc version 4.6.2 (GCC) 

I haven't tested this yet using gcc 4.6.3 nor gcc 4.7. My apologies if this has
been already fixed.


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

* [Bug c++/52739] [c++0x] Segfault because of nested lambda member capture inside member template
  2012-03-27 14:51 [Bug c++/52739] New: [c++0x] Segfault because of nested lambda member capture inside member template bruno-gcc at defraine dot net
@ 2012-03-27 15:08 ` redi at gcc dot gnu.org
  2012-03-27 16:38 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-27 15:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-03-27
      Known to work|                            |4.7.0
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-27 15:06:16 UTC ---
$ g++-4.6.3 -std=c++0x t.cc
t.cc: In lambda function:
t.cc:12:23: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
$
$ g++-4.7.0 -std=c++0x t.cc
t.cc: In lambda function:
t.cc:12:23: error: capture of non-variable 'Test<n>::i'
t.cc:3:9: note: 'int Test<n>::i' declared here
t.cc: In lambda function:
t.cc:13:15: error: 'this' was not captured for this lambda function


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

* [Bug c++/52739] [c++0x] Segfault because of nested lambda member capture inside member template
  2012-03-27 14:51 [Bug c++/52739] New: [c++0x] Segfault because of nested lambda member capture inside member template bruno-gcc at defraine dot net
  2012-03-27 15:08 ` [Bug c++/52739] " redi at gcc dot gnu.org
@ 2012-03-27 16:38 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-27 16:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |paolo.carlini at oracle dot
                   |                            |com
         Resolution|                            |FIXED

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-27 15:54:04 UTC ---
Then we can resolve it.


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

end of thread, other threads:[~2012-03-27 15:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-27 14:51 [Bug c++/52739] New: [c++0x] Segfault because of nested lambda member capture inside member template bruno-gcc at defraine dot net
2012-03-27 15:08 ` [Bug c++/52739] " redi at gcc dot gnu.org
2012-03-27 16:38 ` 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).