Bug 52619

Summary: ICE/segmentation fault in lambda function
Product: gcc Reporter: Tobias Schuele <t.schuele>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal Keywords: c++-lambda
Priority: P3    
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2012-03-20 00:00:00
Bug Depends on:    
Bug Blocks: 54367    

Description Tobias Schuele 2012-03-19 15:23:13 UTC
Hi, the following piece of code causes an ICE (segmentation fault) when compiled with gcc-4.7.0-RC-20120302 (no problem with gcc 4.6.3):

#include <atomic>

template<typename T>
struct test {
  std::atomic<int> x;
  void foo() {
    auto cond = [this] {return x != 0;};
  }
};

It works if the value of x is loaded explicitly:

auto cond = [this] {return x.load() != 0;};
Comment 1 Paolo Carlini 2012-03-20 10:54:16 UTC
Confirmed. We should figure out a reduced testcase not including anything (note: the internals of <atomic> are completely different in 4.7 vs 4.6)
Comment 2 Paolo Carlini 2012-03-20 11:03:00 UTC
The crash happens in lvalue_kind: an INDIRECT_REF with no TREE_TYPE.
Comment 3 Tobias Schuele 2012-03-22 15:36:42 UTC
Here is a testcase not including anything:

template <typename T>
struct foo {
  operator T() {
    return T();
  }
};

template<typename T>
struct test {
  foo<int> x;
  void bar() {
    auto f = [this] {return x != 0;};
  }
};

As in the above testcase, the ICE disappears if implicit type conversion is avoided:

    auto f = [this] {return (int)x != 0;};
Comment 4 Paolo Carlini 2012-03-22 16:30:02 UTC
Thanks!
Comment 5 Paolo Carlini 2012-10-04 01:31:22 UTC
Probably Dup of PR54403.
Comment 6 Paolo Carlini 2013-02-06 10:12:00 UTC
Fixed by the patch which fixed PR54122.

*** This bug has been marked as a duplicate of bug 54122 ***