Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler crashes on generic lambda

Tags:

c++

c++11

qt

c++14

qt5

I have C++14 enabled in code (a Qt5 project) similar to the following:

auto func = [&](auto p, auto pp) {
    if(!p)
        return;
    pp = p;
    p->init();
    this->member_function(pp->thing()); // replaces member_function(pp->thing());
};
MyClass *p1;
...
func(p1, m_p);
m_p->doSomething();

After receiving:

internal compiler error: Segmentation fault

Debugging I found m_pdid not change after the call to func, as I was expecting. Does generic lambda (auto) really works so? How do I go to change m_p in code like the above?

like image 377
KcFnMi Avatar asked May 03 '16 02:05

KcFnMi


2 Answers

File a bug report in gcc's bugzilla. Whether your code is valid C++, or not, the compiler should not blow up with a segmentation fault.

like image 111
Sam Varshavchik Avatar answered Oct 06 '22 13:10

Sam Varshavchik


Segmentation fault in the compiler is very bad, but have you tried using auto& pp? It looks like m_p is being passed by value, not reference.

like image 44
Kyle A Avatar answered Oct 06 '22 13:10

Kyle A