]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/86499
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Aug 2018 18:37:23 +0000 (18:37 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 21 Aug 2018 18:37:23 +0000 (18:37 +0000)
* parser.c (cp_parser_lambda_introducer): Give error if a non-local
lambda has a capture-default.

* g++.dg/cpp0x/lambda/lambda-non-local.C: New test.
* g++.dg/cpp0x/lambda/lambda-this10.C: Adjust dg-error.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263749 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 29f3fd86466d86ccdacea33124d83b7164f2b0a6..0fbd8167a047e1654055d252c620d971ba3eff59 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/86499
+       * parser.c (cp_parser_lambda_introducer): Give error if a non-local
+       lambda has a capture-default.
+
 2018-08-21  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * decl.c (check_static_variable_definition): Change to return void.
index aa5286b24ccbb6e7c8d77bffbcc60c15d7045744..49d476b383fb37f38d9191ac9d50373b37331a7f 100644 (file)
@@ -10285,6 +10285,9 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
     {
       cp_lexer_consume_token (parser->lexer);
       first = false;
+
+      if (!(at_function_scope_p () || parsing_nsdmi ()))
+       error ("non-local lambda expression cannot have a capture-default");
     }
 
   while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_SQUARE))
index 6c87f8017d3569e1784980e7d154ee97773400a7..b5ba160b6b3ed238bf7f1492ff644b1319b2dc8f 100644 (file)
        * g++.dg/cpp0x/Wnarrowing12.C: New test.
        * g++.dg/cpp0x/rv-cast5.C: Add static_cast.
 
+       PR c++/86499
+       * g++.dg/cpp0x/lambda/lambda-non-local.C: New test.
+       * g++.dg/cpp0x/lambda/lambda-this10.C: Adjust dg-error.
+
 2018-08-21  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/expr_func7.adb, gnat.dg/expr_func7.ads: New testcase.
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-non-local.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-non-local.C
new file mode 100644 (file)
index 0000000..005f8f3
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/86499
+// { dg-do compile { target c++11 } }
+
+auto l1 = [=]{}; // { dg-error "non-local lambda expression cannot have a capture-default" }
+auto l2 = [&]{}; // { dg-error "non-local lambda expression cannot have a capture-default" }
+
+namespace {
+  auto l3 = [=]{}; // { dg-error "non-local lambda expression cannot have a capture-default" }
+  auto l4 = [&]{}; // { dg-error "non-local lambda expression cannot have a capture-default" }
+}
index b4b8e7201aabadc4aa6eb7a6a6937481cfe09be5..e8e94771ef0615ed2b9bfe8a2919564ca0516544 100644 (file)
@@ -1,4 +1,4 @@
 // PR c++/54383
 // { dg-do compile { target c++11 } }
 
-auto foo = [&](int a) { return a > this->b; }; // { dg-error "this" }
+auto foo = [&](int a) { return a > this->b; }; // { dg-error "non-local|this" }