]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/60375 ([c++11] ICE with invalid use of lambda)
authorJason Merrill <jason@redhat.com>
Tue, 25 Mar 2014 18:00:37 +0000 (14:00 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 25 Mar 2014 18:00:37 +0000 (14:00 -0400)
PR c++/60375
* parser.c (cp_parser_lambda_expression): Don't parse the body of
a lambda in unevaluated context.

From-SVN: r208817

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C [new file with mode: 0644]

index 47c989098ca4d375cf54f0bb92f2685da8b67d79..23a2c8fc3f350b61c5e725359b3c85ba4937477c 100644 (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.
 
index 4ca08a13d64357d0f0ad9c103d3520d9723c544f..2e117a53155c0feeec84154e91bb627ddffe1e1b 100644 (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)
index 898f685aa57000fddc4080b9067446dd09bc7997..dcea1690dded1bc7de2ccd075d39ca94ed128fb6 100644 (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" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C
new file mode 100644 (file)
index 0000000..14cb298
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/60375
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  decltype( [](){ return this; }() ) x; // { dg-error "unevaluated" }
+};