Bug 69977 - internal compiler error: Segmentation fault when using generic lambdas
Summary: internal compiler error: Segmentation fault when using generic lambdas
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.3.1
: P3 normal
Target Milestone: 6.4
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-02-26 11:02 UTC by jakub.gocol
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.3.0
Last reconfirmed: 2016-02-26 00:00:00


Attachments
compiler output, preprocessed input that causes crash (1.00 KB, application/x-tar)
2016-02-26 11:02 UTC, jakub.gocol
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jakub.gocol 2016-02-26 11:02:03 UTC
Created attachment 37802 [details]
compiler output, preprocessed input that causes crash

class A {
private:
    void method(int i) {
        (void) i;
    }

public:
    void publicMethod() {
        auto lambda = [&] (const auto k) {
            method(k);
        };
        lambda(42);
    }
};

int main()
{
    A a;
    a.publicMethod();
    return 0;
}

===

Following code causes g++ to crash:
    test.cpp: In lambda function:
    test.cpp:10:13: internal compiler error: Segmentation fault
                 method(k);
                 ^
I'm compiling with command: g++ -std=c++14 file.cpp

output of g++ -v:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 5.3.1-8' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.3.1 20160205 (Debian 5.3.1-8) 


In attachment I provided:
- full compiler output (with backtrace)
- preprocessed input that causes crash
- preprocessed, slightly modified input, that works as expected
Comment 1 Richard Biener 2016-02-26 11:47:43 UTC
Confirmed on the GCC 5 branch, trunk rejects the testcase:

> ./cc1plus  -quiet t.ii -std=c++14
t.ii: In instantiation of ‘A::publicMethod()::<lambda(auto:1)> [with auto:1 = int]’:
t.ii:9:33:   required by substitution of ‘template<class auto:1> A::publicMethod()::<lambda(auto:1)>::operator decltype (((A::publicMethod()::<lambda(auto:1)>)0u).operator()(static_cast<const auto:1>(<anonymous>))) (*)(auto:1)() const [with auto:1 = int]’
t.ii:12:11:   required from here
t.ii:10:6: error: cannot call member function ‘void A::method(int)’ without object
      method(k);
      ^~~~~~
Comment 2 Jonathan Wakely 2016-02-26 13:05:56 UTC
Trunk rejects it incorrectly, I think that's PR 61636
Comment 3 paolo@gcc.gnu.org 2017-10-02 09:42:08 UTC
Author: paolo
Date: Mon Oct  2 09:41:36 2017
New Revision: 253340

URL: https://gcc.gnu.org/viewcvs?rev=253340&root=gcc&view=rev
Log:
2017-10-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/69977
	* g++.dg/cpp1y/lambda-generic-69977.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/lambda-generic-69977.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2017-10-02 09:43:53 UTC
Thanks Jon. Confirmed fixed in 6.4.0. To be safe I added the testcase anyway.