r287057 - PR23281: Fix implementation of DR1891 to implement the intent: that is, a
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 15 16:03:24 PST 2016
Author: rsmith
Date: Tue Nov 15 18:03:24 2016
New Revision: 287057
URL: http://llvm.org/viewvc/llvm-project?rev=287057&view=rev
Log:
PR23281: Fix implementation of DR1891 to implement the intent: that is, a
lambda-expression does not have a move-assignment operator.
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/test/CXX/drs/dr18xx.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
cfe/trunk/test/SemaCXX/lambda-expressions.cpp
cfe/trunk/www/cxx_dr_status.html
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=287057&r1=287056&r2=287057&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Nov 15 18:03:24 2016
@@ -993,7 +993,11 @@ public:
!hasUserDeclaredCopyConstructor() &&
!hasUserDeclaredCopyAssignment() &&
!hasUserDeclaredMoveConstructor() &&
- !hasUserDeclaredDestructor();
+ !hasUserDeclaredDestructor() &&
+ // C++1z [expr.prim.lambda]p21: "the closure type has a deleted copy
+ // assignment operator". The intent is that this counts as a user
+ // declared copy assignment, but we do not model it that way.
+ !isLambda();
}
/// \brief Determine whether we need to eagerly declare a move assignment
Modified: cfe/trunk/test/CXX/drs/dr18xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr18xx.cpp?rev=287057&r1=287056&r2=287057&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr18xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr18xx.cpp Tue Nov 15 18:03:24 2016
@@ -7,11 +7,11 @@
// expected-no-diagnostics
#endif
-void dr1891() { // dr1891: 3.6
+void dr1891() { // dr1891: 4.0
#if __cplusplus >= 201103L
int n;
- auto a = []{}; // expected-note 2{{candidate}}
- auto b = [=]{ return n; }; // expected-note 2{{candidate}}
+ auto a = []{}; // expected-note 2{{candidate}} expected-note 2{{here}}
+ auto b = [=]{ return n; }; // expected-note 2{{candidate}} expected-note 2{{here}}
typedef decltype(a) A;
typedef decltype(b) B;
@@ -20,5 +20,10 @@ void dr1891() { // dr1891: 3.6
A x; // expected-error {{no matching constructor}}
B y; // expected-error {{no matching constructor}}
+
+ a = a; // expected-error {{copy assignment operator is implicitly deleted}}
+ a = static_cast<A&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
+ b = b; // expected-error {{copy assignment operator is implicitly deleted}}
+ b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
#endif
}
Modified: 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=287057&r1=287056&r2=287057&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp Tue Nov 15 18:03:24 2016
@@ -7,7 +7,7 @@ struct MoveOnly {
template<typename T> T &&move(T&);
void test_special_member_functions(MoveOnly mo, int i) {
- auto lambda1 = [i]() { }; // expected-note {{lambda expression begins here}} expected-note 2{{candidate}}
+ auto lambda1 = [i]() { }; // expected-note 2{{lambda expression begins here}} expected-note 2{{candidate}}
// Default constructor
decltype(lambda1) lambda2; // expected-error{{no matching constructor}}
@@ -16,7 +16,7 @@ void test_special_member_functions(MoveO
lambda1 = lambda1; // expected-error{{copy assignment operator is implicitly deleted}}
// Move assignment operator
- lambda1 = move(lambda1);
+ lambda1 = move(lambda1); // expected-error{{copy assignment operator is implicitly deleted}}
// Copy constructor
decltype(lambda1) lambda3 = lambda1;
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=287057&r1=287056&r2=287057&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Tue Nov 15 18:03:24 2016
@@ -95,6 +95,39 @@ namespace ImplicitCapture {
}
}
+namespace SpecialMembers {
+ void f() {
+ auto a = []{}; // expected-note 2{{here}} expected-note 2{{candidate}}
+ decltype(a) b; // expected-error {{no matching constructor}}
+ decltype(a) c = a;
+ decltype(a) d = static_cast<decltype(a)&&>(a);
+ a = a; // expected-error {{copy assignment operator is implicitly deleted}}
+ a = static_cast<decltype(a)&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
+ }
+ struct P {
+ P(const P&) = delete; // expected-note {{deleted here}}
+ };
+ struct Q {
+ ~Q() = delete; // expected-note {{deleted here}}
+ };
+ struct R {
+ R(const R&) = default;
+ R(R&&) = delete;
+ R &operator=(const R&) = delete;
+ R &operator=(R&&) = delete;
+ };
+ void g(P &p, Q &q, R &r) {
+ auto pp = [p]{}; // expected-error {{deleted constructor}}
+ auto qq = [q]{}; // expected-error {{deleted function}} expected-note {{because}}
+
+ auto a = [r]{}; // expected-note 2{{here}}
+ decltype(a) b = a;
+ decltype(a) c = static_cast<decltype(a)&&>(a); // ok, copies R
+ a = a; // expected-error {{copy assignment operator is implicitly deleted}}
+ a = static_cast<decltype(a)&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
+ }
+}
+
namespace PR12031 {
struct X {
template<typename T>
Modified: cfe/trunk/www/cxx_dr_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_dr_status.html?rev=287057&r1=287056&r2=287057&view=diff
==============================================================================
--- cfe/trunk/www/cxx_dr_status.html (original)
+++ cfe/trunk/www/cxx_dr_status.html Tue Nov 15 18:03:24 2016
@@ -11161,7 +11161,7 @@ and <I>POD class</I></td>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1891">1891</a></td>
<td>DRWP</td>
<td>Move constructor/assignment for closure class</td>
- <td class="full" align="center">Clang 3.6</td>
+ <td class="svn" align="center">SVN</td>
</tr>
<tr id="1892">
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1892">1892</a></td>
More information about the cfe-commits
mailing list