Hi! Another easy patch where c++2a just allows something we've already accepted with a pedwarn.
Bootstrapped/regtested on x86_64-linux and i686-linux, including make check-c++-all, ok for trunk? 2017-09-20 Jakub Jelinek <ja...@redhat.com> 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. --- gcc/cp/parser.c.jj 2017-09-19 16:38:14.000000000 +0200 +++ gcc/cp/parser.c 2017-09-20 09:32:44.117646033 +0200 @@ -10183,7 +10183,8 @@ cp_parser_lambda_introducer (cp_parser* 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); --- gcc/testsuite/g++.dg/cpp1z/lambda-this1.C.jj 2016-09-27 21:09:59.000000000 +0200 +++ gcc/testsuite/g++.dg/cpp1z/lambda-this1.C 2017-09-20 09:52:54.893394307 +0200 @@ -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 { --- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C.jj 2014-03-10 10:50:00.000000000 +0100 +++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C 2017-09-20 10:40:43.608253519 +0200 @@ -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 } Jakub