Bug 70343 - internal compiler error: in tsubst_copy, wrong code with lambda in template fn
Summary: internal compiler error: in tsubst_copy, wrong code with lambda in template fn
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.3.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code, wrong-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-03-21 17:19 UTC by tower120
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-03-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tower120 2016-03-21 17:19:10 UTC
The following code cause ICE in 4.9.2, in 5.3 cause Segmentation fault. Works ok in non-templated version. Woks ok with clang and VS.

http://coliru.stacked-crooked.com/a/82069f4880198da6


#include <iostream>     // std::cout
#include <new>          // ::operator new
#include <vector>
#include <tuple>
#include <type_traits>

using namespace std;

struct Empty{};

    
template<class T>   /* <-- Because of Template */
struct Data{
    int x;
    float y;
    
    int properties_parcel4[10];
    
    Empty j = [&](){
		int i = 10;
                properties_parcel4[0] = i;
		return Empty(); 
    }();    
};

int main () {
    Data<int> k;
    
  return 0;
}
Comment 1 Richard Biener 2016-03-22 08:46:28 UTC
Confirmed.
Comment 2 tower120 2016-03-22 14:45:10 UTC
The workaround for all versions is use lambda that doesn't CAPTURE this, e.g.

http://coliru.stacked-crooked.com/a/e223ddb156d817c1


struct Empty{};
    
template<class T> 
struct Data{
    int properties_parcel4[10];
    
    Empty j = [](auto& self){
         self.properties_parcel4[0] = 10;
		return Empty(); 
    }(*this);    
};

int main () {
    Data<int> k;
    
  return 0;
}


P.S. This maybe somehow related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636 - problem workarounds are same.
Comment 3 paolo@gcc.gnu.org 2017-10-03 21:16:28 UTC
Author: paolo
Date: Tue Oct  3 21:15:56 2017
New Revision: 253388

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

	PR c++/70343
	* g++.dg/cpp0x/lambda/lambda-70343.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-70343.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2017-10-03 21:17:00 UTC
Fixed in trunk.