[cfe-commits] r150345 - in /cfe/trunk: lib/Sema/Sema.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaLambda.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp
Douglas Gregor
dgregor at apple.com
Sun Feb 12 09:34:24 PST 2012
Author: dgregor
Date: Sun Feb 12 11:34:23 2012
New Revision: 150345
URL: http://llvm.org/viewvc/llvm-project?rev=150345&view=rev
Log:
Lambdas have a deleted default constructor and a deleted copy
assignment operator, per C++ [expr.prim.lambda]p19. Make it so.
Added:
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp (with props)
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp (with props)
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=150345&r1=150344&r2=150345&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Feb 12 11:34:23 2012
@@ -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();
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=150345&r1=150344&r2=150345&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Feb 12 11:34:23 2012
@@ -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
Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=150345&r1=150344&r2=150345&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Sun Feb 12 11:34:23 2012
@@ -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);
Added: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp?rev=150345&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp Sun Feb 12 11:34:23 2012
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++11 %s -Wunused -verify
+
+struct MoveOnly {
+ MoveOnly(MoveOnly&&);
+ MoveOnly(const MoveOnly&);
+};
+
+template<typename T> T &&move(T&);
+void test_special_member_functions(MoveOnly mo, int i) {
+ // FIXME: terrible note
+ auto lambda1 = [i]() { }; // expected-note{{function has been explicitly marked deleted here}} \
+ // expected-note{{the implicit copy assignment operator}} \
+ // expected-note{{the implicit move assignment operator}} \
+
+ // Default constructor
+ decltype(lambda1) lambda2; // expected-error{{call to deleted constructor}}
+
+ // Copy assignment operator
+ lambda1 = lambda1; // expected-error{{overload resolution selected deleted operator '='}}
+
+ // Move assignment operator
+ lambda1 = move(lambda1);
+
+ // Copy constructor
+ decltype(lambda1) lambda3 = lambda1;
+ decltype(lambda1) lambda4(lambda1);
+
+ // Move constructor
+ decltype(lambda1) lambda5 = move(lambda1);
+ decltype(lambda1) lambda6(move(lambda1));
+}
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp?rev=150345&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp Sun Feb 12 11:34:23 2012
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 %s -Wunused -verify
+
+template<typename T>
+void destroy(T* ptr) {
+ ptr->~T();
+ (*ptr).~T();
+}
+
+void destructor() {
+ auto lambda = []{};
+ destroy(&lambda);
+}
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp?rev=150345&r1=150344&r2=150345&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp Sun Feb 12 11:34:23 2012
@@ -8,6 +8,7 @@
template<typename T>
struct bogus_override_if_virtual : public T {
+ bogus_override_if_virtual() : T(*(T*)0) { }
int operator()() const;
};
Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp?rev=150345&r1=150344&r2=150345&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp Sun Feb 12 11:34:23 2012
@@ -45,9 +45,11 @@
struct S1 {
int x, y;
+ S1 &operator=(int*);
int operator()(int);
void f() {
[&]()->int {
+ S1 &s1 = operator=(&this->x);
return operator()(this->x + y);
}();
}
More information about the cfe-commits
mailing list