Commit 1cbba79d by Jason Merrill Committed by Jason Merrill

re PR c++/60375 ([c++11] ICE with invalid use of lambda)

	PR c++/60375
	* parser.c (cp_parser_lambda_expression): Don't parse the body of
	a lambda in unevaluated context.

From-SVN: r208817
parent 45156f14
2014-03-25 Jason Merrill <jason@redhat.com> 2014-03-25 Jason Merrill <jason@redhat.com>
PR c++/60375
* parser.c (cp_parser_lambda_expression): Don't parse the body of
a lambda in unevaluated context.
PR c++/60628 PR c++/60628
* decl.c (create_array_type_for_decl): Complain about array of auto. * decl.c (create_array_type_for_decl): Complain about array of auto.
......
...@@ -8718,14 +8718,17 @@ cp_parser_lambda_expression (cp_parser* parser) ...@@ -8718,14 +8718,17 @@ cp_parser_lambda_expression (cp_parser* parser)
{ {
tree lambda_expr = build_lambda_expr (); tree lambda_expr = build_lambda_expr ();
tree type; tree type;
bool ok; bool ok = true;
LAMBDA_EXPR_LOCATION (lambda_expr) LAMBDA_EXPR_LOCATION (lambda_expr)
= cp_lexer_peek_token (parser->lexer)->location; = cp_lexer_peek_token (parser->lexer)->location;
if (cp_unevaluated_operand) if (cp_unevaluated_operand)
error_at (LAMBDA_EXPR_LOCATION (lambda_expr), {
"lambda-expression in unevaluated context"); error_at (LAMBDA_EXPR_LOCATION (lambda_expr),
"lambda-expression in unevaluated context");
ok = false;
}
/* We may be in the middle of deferred access check. Disable /* We may be in the middle of deferred access check. Disable
it now. */ it now. */
...@@ -8770,12 +8773,15 @@ cp_parser_lambda_expression (cp_parser* parser) ...@@ -8770,12 +8773,15 @@ cp_parser_lambda_expression (cp_parser* parser)
/* By virtue of defining a local class, a lambda expression has access to /* By virtue of defining a local class, a lambda expression has access to
the private variables of enclosing classes. */ the private variables of enclosing classes. */
ok = cp_parser_lambda_declarator_opt (parser, lambda_expr); ok &= cp_parser_lambda_declarator_opt (parser, lambda_expr);
if (ok) if (ok)
cp_parser_lambda_body (parser, lambda_expr); cp_parser_lambda_body (parser, lambda_expr);
else if (cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE)) else if (cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
cp_parser_skip_to_end_of_block_or_statement (parser); {
if (cp_parser_skip_to_closing_brace (parser))
cp_lexer_consume_token (parser->lexer);
}
/* The capture list was built up in reverse order; fix that now. */ /* The capture list was built up in reverse order; fix that now. */
LAMBDA_EXPR_CAPTURE_LIST (lambda_expr) LAMBDA_EXPR_CAPTURE_LIST (lambda_expr)
......
...@@ -5,3 +5,5 @@ template <class T> ...@@ -5,3 +5,5 @@ template <class T>
struct A { }; struct A { };
A<decltype([]{ return 1; }())> a; // { dg-error "lambda.*unevaluated context" } A<decltype([]{ return 1; }())> a; // { dg-error "lambda.*unevaluated context" }
// { dg-prune-output "template argument" }
// { dg-prune-output "invalid type" }
// PR c++/60375
// { dg-do compile { target c++11 } }
struct A
{
decltype( [](){ return this; }() ) x; // { dg-error "unevaluated" }
};
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