diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-13 00:54:12 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-11-13 00:54:12 +0000 |
commit | 044c8aa39d582ebc6bca1720c65ddd06fb27780c (patch) | |
tree | 0a83266368cc275bf32a755e11b708ee1f6b4176 /test | |
parent | d449c792d98f58277e02c0ddc8330cd9de5f82f5 (diff) |
Fix some wrong-code bugs in implicitly-defined assignment operators:
- In C++11, perform overload resolution over all assignment operators, rather than just looking for copy/move assignment operators.
- Clean up after temporaries produced by operator= immediately, rather than accumulating them until the end of the function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CXX/special/class.copy/p28-cxx11.cpp | 19 | ||||
-rw-r--r-- | test/CodeGenCXX/temporaries.cpp | 21 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/CXX/special/class.copy/p28-cxx11.cpp b/test/CXX/special/class.copy/p28-cxx11.cpp new file mode 100644 index 0000000000..dc501d91f7 --- /dev/null +++ b/test/CXX/special/class.copy/p28-cxx11.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++98 %s -fsyntax-only +// RUN: %clang_cc1 -std=c++11 %s -verify + +// In C++11, we must perform overload resolution to determine which function is +// called by a defaulted assignment operator, and the selected operator might +// not be a copy or move assignment (it might be a specialization of a templated +// 'operator=', for instance). +struct A { + A &operator=(const A &); + + template<typename T> + A &operator=(T &&) { return T::error; } // expected-error {{no member named 'error' in 'A'}} +}; + +struct B : A { + B &operator=(B &&); +}; + +B &B::operator=(B &&) = default; // expected-note {{here}} diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp index e90c94796f..a369c2e369 100644 --- a/test/CodeGenCXX/temporaries.cpp +++ b/test/CodeGenCXX/temporaries.cpp @@ -537,3 +537,24 @@ namespace PR11365 { (void) (A [3]) {}; } } + +namespace AssignmentOp { + struct A { ~A(); }; + struct B { A operator=(const B&); }; + struct C : B { B b1, b2; }; + // CHECK: define void @_ZN12AssignmentOp1fE + void f(C &c1, const C &c2) { + // CHECK: call {{.*}} @_ZN12AssignmentOp1CaSERKS0_( + c1 = c2; + } + + // Ensure that each 'A' temporary is destroyed before the next subobject is + // copied. + // CHECK: define {{.*}} @_ZN12AssignmentOp1CaSERKS0_( + // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS + // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev( + // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS + // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev( + // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS + // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev( +} |