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
This commit is contained in:
Jason Merrill 2014-03-25 14:00:37 -04:00 committed by Jason Merrill
parent 45156f1474
commit 1cbba79d07
4 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,9 @@
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
* decl.c (create_array_type_for_decl): Complain about array of auto.

View File

@ -8718,14 +8718,17 @@ cp_parser_lambda_expression (cp_parser* parser)
{
tree lambda_expr = build_lambda_expr ();
tree type;
bool ok;
bool ok = true;
LAMBDA_EXPR_LOCATION (lambda_expr)
= cp_lexer_peek_token (parser->lexer)->location;
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
it now. */
@ -8770,12 +8773,15 @@ cp_parser_lambda_expression (cp_parser* parser)
/* By virtue of defining a local class, a lambda expression has access to
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)
cp_parser_lambda_body (parser, lambda_expr);
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. */
LAMBDA_EXPR_CAPTURE_LIST (lambda_expr)

View File

@ -5,3 +5,5 @@ template <class T>
struct A { };
A<decltype([]{ return 1; }())> a; // { dg-error "lambda.*unevaluated context" }
// { dg-prune-output "template argument" }
// { dg-prune-output "invalid type" }

View File

@ -0,0 +1,7 @@
// PR c++/60375
// { dg-do compile { target c++11 } }
struct A
{
decltype( [](){ return this; }() ) x; // { dg-error "unevaluated" }
};