Bug 56464 - [C++11] Crashes when using implicit this in a lambda capture in member initializer
Summary: [C++11] Crashes when using implicit this in a lambda capture in member initia...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.8.0
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 54367
  Show dependency treegraph
 
Reported: 2013-02-26 16:18 UTC by Olivier Goffart
Modified: 2013-03-04 17:14 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Goffart 2013-02-26 16:18:36 UTC
GCC segfault on this (valid) code:

struct bug { bug*a = [&](){return this;}(); };
Comment 1 Marek Polacek 2013-02-26 16:26:00 UTC
With trunk (may be a dup, there are a lot of lambda-related crashes):

lam.C:1:35: internal compiler error: Segmentation fault
 struct bug { bug*a = [&](){return this;}(); };
                                   ^
0xc495e1 crash_signal
	/home/marek/src/gcc/gcc/toplev.c:332
0x54b550 tree_not_check2(tree_node*, char const*, int, char const*, tree_code, tree_code)
	/home/marek/src/gcc/gcc/tree.h:3706
0x71390e lambda_expr_this_capture(tree_node*)
	/home/marek/src/gcc/gcc/cp/semantics.c:9450
0x6f5c8b finish_this_expr()
	/home/marek/src/gcc/gcc/cp/semantics.c:2295
0x663afe cp_parser_primary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:4133
0x666731 cp_parser_postfix_expression
	/home/marek/src/gcc/gcc/cp/parser.c:5629
0x6687d6 cp_parser_unary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:6685
0x669337 cp_parser_cast_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7266
0x669394 cp_parser_binary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7365
0x669a0a cp_parser_assignment_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7590
0x669c34 cp_parser_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7741
0x66b7a3 cp_parser_lambda_body
	/home/marek/src/gcc/gcc/cp/parser.c:8632
0x66a62a cp_parser_lambda_expression
	/home/marek/src/gcc/gcc/cp/parser.c:8194
0x66397e cp_parser_primary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:4085
0x666731 cp_parser_postfix_expression
	/home/marek/src/gcc/gcc/cp/parser.c:5629
0x6687d6 cp_parser_unary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:6685
0x669337 cp_parser_cast_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7266
0x669394 cp_parser_binary_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7365
0x669a0a cp_parser_assignment_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7590
0x669d4f cp_parser_constant_expression
	/home/marek/src/gcc/gcc/cp/parser.c:7821
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 2 Paolo Carlini 2013-02-27 10:21:37 UTC
Right now we don't have that many left, but this one is a Dup of PR54383.

*** This bug has been marked as a duplicate of bug 53383 ***
Comment 3 Paolo Carlini 2013-02-27 10:24:21 UTC

*** This bug has been marked as a duplicate of bug 54383 ***
Comment 4 poenitz 2013-03-02 15:16:54 UTC
I am afraid I don't understand the process. How can an "ice-on-valid-code" be a duplicate of a "ice-on-invalid-code"? Yes, the cause for the crash might technically be the same, but in the other case it might be covered by "undefined behaviour", here not.
Comment 5 Jonathan Wakely 2013-03-02 22:20:44 UTC
That one's easy, it can be both ice-on-valid-code and ice-on-invalid-code

If it crashes in the same place and is fixed by the same fix, it's the same bug, no?
Comment 6 Jason Merrill 2013-03-04 03:12:05 UTC
Not a duplicate.  54367 is the case where there is no 'this', this bug is the case where 'this' is for a NSDMI.
Comment 7 Paolo Carlini 2013-03-04 09:45:14 UTC
Sorry, I didn't notice that in 54383 we aren't in a class.
Comment 8 Jason Merrill 2013-03-04 17:12:47 UTC
Author: jason
Date: Mon Mar  4 17:12:32 2013
New Revision: 196437

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196437
Log:
	PR c++/56464
	PR c++/54383
	* semantics.c (lambda_expr_this_capture): Handle NSDMI
	and non-class scopes.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi1.C
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
Comment 9 Jason Merrill 2013-03-04 17:14:22 UTC
Fixed for 4.8.