diff options
author | Marek Polacek <polacek@redhat.com> | 2018-08-21 18:37:23 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2018-08-21 18:37:23 +0000 |
commit | 774fb6c4eb205eaf9d3b6667e7de9c90cc1784ad (patch) | |
tree | 1eda2ec33c05aeb27bb7e881205a0ff36e5efab1 | |
parent | 55082d81a0cb409d2c1a54889bbed72b369c4da8 (diff) | |
download | gcc-774fb6c4eb205eaf9d3b6667e7de9c90cc1784ad.zip gcc-774fb6c4eb205eaf9d3b6667e7de9c90cc1784ad.tar.gz gcc-774fb6c4eb205eaf9d3b6667e7de9c90cc1784ad.tar.bz2 |
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
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-non-local.C | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C | 2 |
5 files changed, 24 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 29f3fd8..0fbd816 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index aa5286b..49d476b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c87f80..b5ba160 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. 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 index 0000000..005f8f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-non-local.C @@ -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" } +} diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C index b4b8e72..e8e9477 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this10.C @@ -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" } |