summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorFaisal Vali <faisalv@yahoo.com>2017-08-19 03:43:07 +0000
committerFaisal Vali <faisalv@yahoo.com>2017-08-19 03:43:07 +0000
commit8194a3e975e5933b8e76a71b0cc2ac3651c75246 (patch)
tree8073bacd6a0c308004d2a775386fc57991385cb1 /clang/test
parent7aff8cfa555764f2b6ad03c50dd53bc1972e3ebd (diff)
downloadbcm5719-llvm-8194a3e975e5933b8e76a71b0cc2ac3651c75246.tar.gz
bcm5719-llvm-8194a3e975e5933b8e76a71b0cc2ac3651c75246.zip
[c++2a] Implement P0409R2 - Allow lambda capture [=,this] (by hamzasood)
This patch, by hamzasood, implements P0409R2, and allows [=, this] pre-C++2a as an extension (with appropriate warnings) for consistency. https://reviews.llvm.org/D36572 Thanks Hamza! llvm-svn: 311224
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp4
-rw-r--r--clang/test/FixIt/fixit-cxx0x.cpp1
-rw-r--r--clang/test/SemaCXX/cxx2a-lambda-equals-this.cpp15
3 files changed, 17 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 b9b8cd76c01..1cc1fd974ca 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,7 +8,7 @@ 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 be explicitly captured}}
+ (void)[=, this] () {}; // expected-warning {{C++2a extension}}
(void)[&, foo] () {};
(void)[&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}}
(void)[&, this] () {};
@@ -23,7 +23,7 @@ struct S2 {
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 be explicitly captured}}
+ (void)[=, this]{ }; // expected-warning{{C++2a extension}}
(void)[=]{ this->g(i); };
(void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
(void)[i(0), i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}}
diff --git a/clang/test/FixIt/fixit-cxx0x.cpp b/clang/test/FixIt/fixit-cxx0x.cpp
index 5aebcb3defa..337b5d62bed 100644
--- a/clang/test/FixIt/fixit-cxx0x.cpp
+++ b/clang/test/FixIt/fixit-cxx0x.cpp
@@ -54,7 +54,6 @@ struct S2 {
void S2::f(int i) {
(void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}}
- (void)[=, this]{ this->g(5); }; // expected-error{{'this' cannot be explicitly captured}}
(void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
(void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
(void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
diff --git a/clang/test/SemaCXX/cxx2a-lambda-equals-this.cpp b/clang/test/SemaCXX/cxx2a-lambda-equals-this.cpp
new file mode 100644
index 00000000000..ce6916322e5
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2a-lambda-equals-this.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+// expected-no-diagnostics
+
+// This test does two things.
+// Deleting the copy constructor ensures that an [=, this] capture doesn't copy the object.
+// Accessing a member variable from the lambda ensures that the capture actually works.
+class A {
+ A(const A &) = delete;
+ int i;
+
+ void func() {
+ auto L = [=, this]() -> int { return i; };
+ L();
+ }
+};
OpenPOWER on IntegriCloud