diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-09-27 21:10:38 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-09-27 21:10:38 +0200 |
commit | 8ca333471792082b70360b87c33a1219534b4ed1 (patch) | |
tree | 2ca31d880419a194ebf4e7a0fe6a924476ebc7ab /gcc/cp/parser.c | |
parent | 459bcfb0bec5bb642685e0b54551995ab51fb156 (diff) | |
download | gcc-8ca333471792082b70360b87c33a1219534b4ed1.zip gcc-8ca333471792082b70360b87c33a1219534b4ed1.tar.gz gcc-8ca333471792082b70360b87c33a1219534b4ed1.tar.bz2 |
Implement P0018R3, C++17 lambda capture of *this by value as [=,*this]
Implement P0018R3, C++17 lambda capture of *this by value as [=,*this]
* parser.c (cp_parser_lambda_introducer): Formatting fix. Pass
true instead of false as by_reference_p to add_capture for 'this'.
Parse '*this' simple-capture.
* lambda.c (build_capture_proxy): Handle '*this' capture by value.
(add_capture): Adjust function comment. For id == this_identifier,
treat by_reference_p as capturing '*this' by reference, i.e. 'this'
by value, and !by_reference_p as capturing '*this' by value.
(add_default_capture): For implicit 'this' capture, always pass
by_reference_p true rather than false.
* g++.dg/cpp1z/lambda-this1.C: New test.
* g++.dg/cpp1z/lambda-this2.C: New test.
From-SVN: r240556
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5ec8b1b..f672b8d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9899,7 +9899,25 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) cp_lexer_consume_token (parser->lexer); add_capture (lambda_expr, /*id=*/this_identifier, - /*initializer=*/finish_this_expr(), + /*initializer=*/finish_this_expr (), + /*by_reference_p=*/true, + explicit_init_p); + continue; + } + + /* Possibly capture `*this'. */ + if (cp_lexer_next_token_is (parser->lexer, CPP_MULT) + && cp_lexer_nth_token_is_keyword (parser->lexer, 2, RID_THIS)) + { + location_t loc = cp_lexer_peek_token (parser->lexer)->location; + if (cxx_dialect < cxx1z) + pedwarn (loc, 0, "%<*this%> capture only available with " + "-std=c++1z or -std=gnu++1z"); + cp_lexer_consume_token (parser->lexer); + cp_lexer_consume_token (parser->lexer); + add_capture (lambda_expr, + /*id=*/this_identifier, + /*initializer=*/finish_this_expr (), /*by_reference_p=*/false, explicit_init_p); continue; |