diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-09-20 21:36:47 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-09-20 21:36:47 +0200 |
commit | 2ffb574542b10b14841c2807047e7396e3a63f37 (patch) | |
tree | 7a26e0a41d63380941332667f2b8a5f7d7ad8d52 /gcc | |
parent | fb3cd39dcfcecf8e9bc605bd3fe3ee74c8407b90 (diff) | |
download | gcc-2ffb574542b10b14841c2807047e7396e3a63f37.zip gcc-2ffb574542b10b14841c2807047e7396e3a63f37.tar.gz gcc-2ffb574542b10b14841c2807047e7396e3a63f37.tar.bz2 |
P0409R2 - allow lambda capture [=, this]
P0409R2 - allow lambda capture [=, this]
* parser.c (cp_parser_lambda_introducer): For cxx2a don't pedwarn on
redundant [=, this].
* g++.dg/cpp1z/lambda-this1.C: Don't expect error for c++2a on [=, this]
capture. Add further tests.
* g++.dg/cpp0x/lambda/lambda-capture-redundancy.C: Don't expect error
for c++2a on [=, this] capture.
From-SVN: r253030
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/lambda-this1.C | 20 |
5 files changed, 34 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 01a03f9..b4edd80 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-09-20 Jakub Jelinek <jakub@redhat.com> + + P0409R2 - allow lambda capture [=, this] + * parser.c (cp_parser_lambda_introducer): For cxx2a don't pedwarn on + redundant [=, this]. + 2017-09-18 Jason Merrill <jason@redhat.com> PR c++/82069 - ICE with lambda in template diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c9cb3cb..25b91df 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10183,7 +10183,8 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) if (cp_lexer_next_token_is_keyword (parser->lexer, RID_THIS)) { location_t loc = cp_lexer_peek_token (parser->lexer)->location; - if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_COPY) + if (cxx_dialect < cxx2a + && LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_COPY) pedwarn (loc, 0, "explicit by-copy capture of %<this%> redundant " "with by-copy capture default"); cp_lexer_consume_token (parser->lexer); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7caf07a..801adf0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2017-09-20 Jakub Jelinek <jakub@redhat.com> + P0409R2 - allow lambda capture [=, this] + * g++.dg/cpp1z/lambda-this1.C: Don't expect error for c++2a on [=, this] + capture. Add further tests. + * g++.dg/cpp0x/lambda/lambda-capture-redundancy.C: Don't expect error + for c++2a on [=, this] capture. + * g++.dg/cpp1z/cplusplus.C: Test that __cplusplus is equal to 201703L. * g++.dg/cpp1z/cplusplus_1z.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C index 49fbdf3..baeb814 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C @@ -7,7 +7,7 @@ void S2::f(int i) { [&, i]{ }; // OK [&, &i]{ }; // { dg-error "" } i preceded by & when & is the default [=, i]{ }; // { dg-error "" } i not preceded by & when = is the default - [=, this]{ }; // { dg-error "" } this when = is the default + [=, this]{ }; // { dg-error "" "" { target c++17_down } } this when = is the default [i, i]{ }; // { dg-error "" } i repeated [this, this]{ }; // { dg-error "" } i repeated } diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-this1.C b/gcc/testsuite/g++.dg/cpp1z/lambda-this1.C index 5a4c5f9..a154380 100644 --- a/gcc/testsuite/g++.dg/cpp1z/lambda-this1.C +++ b/gcc/testsuite/g++.dg/cpp1z/lambda-this1.C @@ -17,13 +17,31 @@ struct A { auto h = [*this] () mutable { a++; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } auto i = [=] { return a; }; auto j = [&] { return a; }; - auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" } + // P0409R2 - C++2A lambda capture [=, this] + auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } } auto l = [&, this] { return a; }; auto m = [=, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } auto n = [&, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } auto o = [*this, &v] { return a + v; };// { dg-error "'*this' capture only available with" "" { target c++14_down } } auto p = [*this] { this = 0; }; // { dg-error "lvalue required as left operand of assignment" } // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + auto q = [=, this, *this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 } + auto r = [=, this, this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-1 } + auto s = [=, *this, this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + // { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 } + auto t = [=, *this, *this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + auto u = [&, this, *this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + auto w = [&, this, this] { return a; };// { dg-error "already captured 'this'" } + auto x = [&, *this, this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } + auto y = [&, *this, *this] { return a; };// { dg-error "already captured 'this'" } + // { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 } } }; struct B { |