diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-12 17:34:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-12 17:34:23 +0000 |
commit | 1a22d2889b234fcb10cad83be231b113e6d3a8b3 (patch) | |
tree | 3541530945b1094d8edb43e46dbe3bd668a048f1 /clang/lib | |
parent | 0501c63609a567b89289f3412e5d0225f239d7ea (diff) | |
download | bcm5719-llvm-1a22d2889b234fcb10cad83be231b113e6d3a8b3.tar.gz bcm5719-llvm-1a22d2889b234fcb10cad83be231b113e6d3a8b3.zip |
Lambdas have a deleted default constructor and a deleted copy
assignment operator, per C++ [expr.prim.lambda]p19. Make it so.
llvm-svn: 150345
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLambda.cpp | 14 |
3 files changed, 21 insertions, 7 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 22d2a20d457..42b102f55a0 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -635,6 +635,7 @@ DeclContext *Sema::getFunctionLevelDeclContext() { 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/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 467cf43797e..b8ea85bea96 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -4340,6 +4340,13 @@ bool Sema::ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM) { 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 @@ bool Sema::ShouldDeleteCopyAssignmentOperator(CXXMethodDecl *MD) { 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/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index e82654ef06d..2bd69edb07c 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -406,6 +406,13 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, 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 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, 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); |