re PR c++/86499 (lambda-expressions with capture-default are allowed at namespace scope)

PR c++/86499
	* 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.

From-SVN: r263749
This commit is contained in:
Marek Polacek 2018-08-21 18:37:23 +00:00 committed by Marek Polacek
parent 55082d81a0
commit 774fb6c4eb
5 changed files with 24 additions and 1 deletions

View 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.

View 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))

View file

@ -13,6 +13,10 @@
* 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.

View file

@ -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" }
}

View 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" }