Lambdas have a deleted default constructor and a deleted copy
assignment operator, per C++ [expr.prim.lambda]p19. Make it so.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150345 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 22d2a20..42b102f 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -635,6 +635,7 @@
     if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) {
       DC = DC->getParent();
     } else if (isa<CXXMethodDecl>(DC) &&
+               cast<CXXMethodDecl>(DC)->getOverloadedOperator() == OO_Call &&
                cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
       DC = DC->getParent()->getParent();
     }
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 467cf43..b8ea85b 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4340,6 +4340,13 @@
   switch (CSM) {
   case CXXDefaultConstructor:
     IsConstructor = true;
+
+    // C++11 [expr.lambda.prim]p19:
+    //   The closure type associated with a lambda-expression has a
+    //   deleted (8.4.3) default constructor.
+    if (RD->isLambda())
+      return true;
+
     break;
   case CXXCopyConstructor:
     IsConstructor = true;
@@ -4621,6 +4628,12 @@
   if (!LangOpts.CPlusPlus0x || RD->isInvalidDecl())
     return false;
 
+  // C++11 [expr.lambda.prim]p19:
+  //   The closure type associated with a lambda-expression has a
+  //   [...] deleted copy assignment operator.
+  if (RD->isLambda())
+    return true;
+
   SourceLocation Loc = MD->getLocation();
 
   // Do access control from the constructor
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp
index e82654e..2bd69ed 100644
--- a/lib/Sema/SemaLambda.cpp
+++ b/lib/Sema/SemaLambda.cpp
@@ -406,6 +406,13 @@
       CallOperator->setType(FunctionTy);
     }
 
+    // C++ [expr.prim.lambda]p7:
+    //   The lambda-expression's compound-statement yields the
+    //   function-body (8.4) of the function call operator [...].
+    ActOnFinishFunctionBody(CallOperator, Body, /*IsInstantation=*/false);
+    CallOperator->setLexicalDeclContext(Class);
+    Class->addDecl(CallOperator);
+
     // C++11 [expr.prim.lambda]p6:
     //   The closure type for a lambda-expression with no lambda-capture
     //   has a public non-virtual non-explicit const conversion function
@@ -450,15 +457,8 @@
       Class->addDecl(Conversion);
     }
 
-    // C++ [expr.prim.lambda]p7:
-    //   The lambda-expression's compound-statement yields the
-    //   function-body (8.4) of the function call operator [...].
-    ActOnFinishFunctionBody(CallOperator, Body, /*IsInstantation=*/false);
-
     // Finalize the lambda class.
     SmallVector<Decl*, 4> Fields(Class->field_begin(), Class->field_end());
-    CallOperator->setLexicalDeclContext(Class);
-    Class->addDecl(CallOperator);
     ActOnFields(0, Class->getLocation(), Class, Fields, 
                 SourceLocation(), SourceLocation(), 0);
     CheckCompletedCXXClass(Class);