summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-10 17:46:20 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-10 17:46:20 +0000
commita1bffa26ca7770475d8c45365a7d3a0c823d7f1d (patch)
treeb1166e37c3fafa267071df6560c0af6e70ca57e8 /clang/test/CXX
parent01db64f0ac4b2f545233a50791d2ac90b2efe6a5 (diff)
downloadbcm5719-llvm-a1bffa26ca7770475d8c45365a7d3a0c823d7f1d.tar.gz
bcm5719-llvm-a1bffa26ca7770475d8c45365a7d3a0c823d7f1d.zip
Allow implicit capture of 'this' in a lambda even when the capture
default is '=', and reword the warning about explicitly capturing 'this' in such lambdas to indicate that only explicit capture is banned. Introduce Fix-Its for this and other "save the programmer from themself" rules regarding what can be explicitly captured and what must be implicitly captured. llvm-svn: 150256
Diffstat (limited to 'clang/test/CXX')
-rw-r--r--clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
index b897d5f10a3..d1384f19dd1 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
@@ -8,18 +8,22 @@ class X0 {
(void)[this, this] () {}; // expected-error {{'this' can appear only once}}
(void)[=, foo] () {}; // expected-error {{'&' must precede a capture when}}
(void)[=, &foo] () {};
- (void)[=, this] () {}; // expected-error {{'this' cannot appear}}
+ (void)[=, this] () {}; // expected-error {{'this' cannot be explicitly captured}}
(void)[&, foo] () {};
(void)[&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}}
(void)[&, this] () {};
}
};
-struct S2 { void f(int i); };
+struct S2 {
+ void f(int i);
+ void g(int i);
+};
void S2::f(int i) {
(void)[&, i]{ };
(void)[&, &i]{ }; // expected-error{{'&' cannot precede a capture when the capture default is '&'}}
- (void)[=, this]{ }; // expected-error{{'this' cannot appear in a capture list when the capture default is '='}}
+ (void)[=, this]{ }; // expected-error{{'this' cannot be explicitly captured}}
+ (void)[=]{ this->g(i); };
(void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
}
OpenPOWER on IntegriCloud