Bug 41896 - [c++0x] Segfault because of a nested lambda function
Summary: [c++0x] Segfault because of a nested lambda function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Jason Merrill
URL:
Keywords:
: 42738 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-11-01 14:31 UTC by Ádám Rák
Modified: 2010-02-10 22:46 UTC (History)
4 users (show)

See Also:
Host: x86_64-unknown-linux
Target: x86_64-unknown-linux
Build: x86_64-unknown-linux
Known to work:
Known to fail:
Last reconfirmed: 2010-02-10 22:01:58


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ádám Rák 2009-11-01 14:31:40 UTC
Code for triggering the BUG:

float nested_lambda()
{
	float val;

	[val]()
	{
		[val]()
		{
		}
	}
}

 float nested_lambda() nested_lambda()::<lambda()>
<stdin>:7:4: internal compiler error: Szegmens hiba
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

according to gdb, the segfault originates at: cp/semantics.c:2814, and it's a null pointer dereferencing. After a bit of inspection, it was revealed that in the code:

decl = add_default_capture (lambda_stack,

llambda_stack is NULL.

I tried the code:
float nested_lambda()
{
	float val;

	[val]()
	{
		float val2 = val;
		[val2]()
		{
		}
	}
}

which seems to be working fine.
Comment 1 Paolo Carlini 2009-11-15 16:58:46 UTC
Let's CC Jason here too, being an issue with lambda...
Comment 2 Paolo Carlini 2010-01-18 02:37:39 UTC
*** Bug 42738 has been marked as a duplicate of this bug. ***
Comment 3 Jason Merrill 2010-02-10 22:45:35 UTC
Subject: Bug 41896

Author: jason
Date: Wed Feb 10 22:45:07 2010
New Revision: 156673

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156673
Log:
	PR c++/41896
	* semantics.c (outer_lambda_capture_p): Use current_function_decl
	instead of current_class_type.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Jason Merrill 2010-02-10 22:46:23 UTC
Fixed.
Comment 5 Jason Merrill 2010-02-11 02:13:06 UTC
Subject: Bug 41896

Author: jason
Date: Thu Feb 11 02:12:53 2010
New Revision: 156678

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156678
Log:
	PR c++/41896
	* semantics.c (outer_lambda_capture_p): Revert.
	(add_capture): Only finish_member_declaration if
	we're in the lambda class.
	(register_capture_members): New.
	* cp-tree.h: Declare it.
	* parser.c (cp_parser_lambda_expression): Call it.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/semantics.c