Commit 2bf492a1 by Jason Merrill Committed by Jason Merrill

re PR c++/63601 (Segfault on usage of 'this' in unevaluated context inside lambda)

	PR c++/63601
	* lambda.c (current_nonlambda_function): New.
	* semantics.c (finish_this_expr): Use it.
	* cp-tree.h: Declare it.

From-SVN: r216488
parent 64dbfdec
2014-10-20 Jason Merrill <jason@redhat.com>
PR c++/63601
* lambda.c (current_nonlambda_function): New.
* semantics.c (finish_this_expr): Use it.
* cp-tree.h: Declare it.
2014-10-17 Alan Modra <amodra@gmail.com> 2014-10-17 Alan Modra <amodra@gmail.com>
PR middle-end/61848 PR middle-end/61848
......
...@@ -5961,6 +5961,7 @@ extern bool is_normal_capture_proxy (tree); ...@@ -5961,6 +5961,7 @@ extern bool is_normal_capture_proxy (tree);
extern void register_capture_members (tree); extern void register_capture_members (tree);
extern tree lambda_expr_this_capture (tree, bool); extern tree lambda_expr_this_capture (tree, bool);
extern tree maybe_resolve_dummy (tree, bool); extern tree maybe_resolve_dummy (tree, bool);
extern tree current_nonlambda_function (void);
extern tree nonlambda_method_basetype (void); extern tree nonlambda_method_basetype (void);
extern void maybe_add_lambda_conv_op (tree); extern void maybe_add_lambda_conv_op (tree);
extern bool is_lambda_ignored_entity (tree); extern bool is_lambda_ignored_entity (tree);
......
...@@ -777,6 +777,17 @@ maybe_resolve_dummy (tree object, bool add_capture_p) ...@@ -777,6 +777,17 @@ maybe_resolve_dummy (tree object, bool add_capture_p)
return object; return object;
} }
/* Returns the innermost non-lambda function. */
tree
current_nonlambda_function (void)
{
tree fn = current_function_decl;
while (fn && LAMBDA_FUNCTION_P (fn))
fn = decl_function_context (fn);
return fn;
}
/* Returns the method basetype of the innermost non-lambda function, or /* Returns the method basetype of the innermost non-lambda function, or
NULL_TREE if none. */ NULL_TREE if none. */
......
...@@ -2438,7 +2438,7 @@ finish_increment_expr (tree expr, enum tree_code code) ...@@ -2438,7 +2438,7 @@ finish_increment_expr (tree expr, enum tree_code code)
tree tree
finish_this_expr (void) finish_this_expr (void)
{ {
tree result; tree result = NULL_TREE;
if (current_class_ptr) if (current_class_ptr)
{ {
...@@ -2450,25 +2450,19 @@ finish_this_expr (void) ...@@ -2450,25 +2450,19 @@ finish_this_expr (void)
else else
result = current_class_ptr; result = current_class_ptr;
} }
else if (current_function_decl
&& DECL_STATIC_FUNCTION_P (current_function_decl)) if (result)
{ /* The keyword 'this' is a prvalue expression. */
return rvalue (result);
tree fn = current_nonlambda_function ();
if (fn && DECL_STATIC_FUNCTION_P (fn))
error ("%<this%> is unavailable for static member functions"); error ("%<this%> is unavailable for static member functions");
result = error_mark_node; else if (fn)
}
else
{
if (current_function_decl)
error ("invalid use of %<this%> in non-member function"); error ("invalid use of %<this%> in non-member function");
else else
error ("invalid use of %<this%> at top level"); error ("invalid use of %<this%> at top level");
result = error_mark_node; return error_mark_node;
}
/* The keyword 'this' is a prvalue expression. */
result = rvalue (result);
return result;
} }
/* Finish a pseudo-destructor expression. If SCOPE is NULL, the /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
......
// PR c++/63601
// { dg-do compile { target c++11 } }
auto f = []{ sizeof(this); }; // { dg-error "this" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment