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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150256 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
index b897d5f..d1384f1 100644
--- a/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
@@ -8,18 +8,22 @@
     (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}}
 }
diff --git a/test/FixIt/fixit-cxx0x.cpp b/test/FixIt/fixit-cxx0x.cpp
index 28a9619..e642b05 100644
--- a/test/FixIt/fixit-cxx0x.cpp
+++ b/test/FixIt/fixit-cxx0x.cpp
@@ -46,3 +46,15 @@
     friend enum class E; // expected-error {{must use 'enum' not 'enum class'}}
   };
 }
+
+struct S2 { 
+  void f(int i); 
+  void g(int i);
+};
+
+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}}
+}