Skip to content

Commit e6b5fa1

Browse files
author
jakub
committed
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253030 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 27a0cfe commit e6b5fa1

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

gcc/cp/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2017-09-20 Jakub Jelinek <[email protected]>
2+
3+
P0409R2 - allow lambda capture [=, this]
4+
* parser.c (cp_parser_lambda_introducer): For cxx2a don't pedwarn on
5+
redundant [=, this].
6+
17
2017-09-18 Jason Merrill <[email protected]>
28

39
PR c++/82069 - ICE with lambda in template

gcc/cp/parser.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10183,7 +10183,8 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
1018310183
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_THIS))
1018410184
{
1018510185
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
10186-
if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_COPY)
10186+
if (cxx_dialect < cxx2a
10187+
&& LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_COPY)
1018710188
pedwarn (loc, 0, "explicit by-copy capture of %<this%> redundant "
1018810189
"with by-copy capture default");
1018910190
cp_lexer_consume_token (parser->lexer);

gcc/testsuite/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
2017-09-20 Jakub Jelinek <[email protected]>
22

3+
P0409R2 - allow lambda capture [=, this]
4+
* g++.dg/cpp1z/lambda-this1.C: Don't expect error for c++2a on [=, this]
5+
capture. Add further tests.
6+
* g++.dg/cpp0x/lambda/lambda-capture-redundancy.C: Don't expect error
7+
for c++2a on [=, this] capture.
8+
39
* g++.dg/cpp1z/cplusplus.C: Test that __cplusplus is equal to 201703L.
410
* g++.dg/cpp1z/cplusplus_1z.C: New test.
511

gcc/testsuite/g++.dg/cpp0x/lambda/lambda-capture-redundancy.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void S2::f(int i) {
77
[&, i]{ }; // OK
88
[&, &i]{ }; // { dg-error "" } i preceded by & when & is the default
99
[=, i]{ }; // { dg-error "" } i not preceded by & when = is the default
10-
[=, this]{ }; // { dg-error "" } this when = is the default
10+
[=, this]{ }; // { dg-error "" "" { target c++17_down } } this when = is the default
1111
[i, i]{ }; // { dg-error "" } i repeated
1212
[this, this]{ }; // { dg-error "" } i repeated
1313
}

gcc/testsuite/g++.dg/cpp1z/lambda-this1.C

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,31 @@ struct A {
1717
auto h = [*this] () mutable { a++; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
1818
auto i = [=] { return a; };
1919
auto j = [&] { return a; };
20-
auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" }
20+
// P0409R2 - C++2A lambda capture [=, this]
21+
auto k = [=, this] { return a; };// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } }
2122
auto l = [&, this] { return a; };
2223
auto m = [=, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
2324
auto n = [&, *this] { return a; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
2425
auto o = [*this, &v] { return a + v; };// { dg-error "'*this' capture only available with" "" { target c++14_down } }
2526
auto p = [*this] { this = 0; }; // { dg-error "lvalue required as left operand of assignment" }
2627
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
28+
auto q = [=, this, *this] { return a; };// { dg-error "already captured 'this'" }
29+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
30+
// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 }
31+
auto r = [=, this, this] { return a; };// { dg-error "already captured 'this'" }
32+
// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-1 }
33+
auto s = [=, *this, this] { return a; };// { dg-error "already captured 'this'" }
34+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
35+
// { dg-error "explicit by-copy capture of 'this' redundant with by-copy capture default" "" { target c++17_down } .-2 }
36+
auto t = [=, *this, *this] { return a; };// { dg-error "already captured 'this'" }
37+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
38+
auto u = [&, this, *this] { return a; };// { dg-error "already captured 'this'" }
39+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
40+
auto w = [&, this, this] { return a; };// { dg-error "already captured 'this'" }
41+
auto x = [&, *this, this] { return a; };// { dg-error "already captured 'this'" }
42+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
43+
auto y = [&, *this, *this] { return a; };// { dg-error "already captured 'this'" }
44+
// { dg-error "'*this' capture only available with" "" { target c++14_down } .-1 }
2745
}
2846
};
2947
struct B {

0 commit comments

Comments
 (0)