aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate/instantiate-default-assignment-operator.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-01 20:49:11 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-01 20:49:11 +0000
commit06a9f3680d22529a2fcf20c52d71cf221d99d910 (patch)
tree5f6d00a7e5c5855cb9b22c00f8e4f6cdf944b7d7 /test/SemaTemplate/instantiate-default-assignment-operator.cpp
parent4c50b697bbf76c13f5b7860518a5ac0484dbbc90 (diff)
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators. Previously, Sema provided type-checking and template instantiation for copy assignment operators, then CodeGen would synthesize the actual body of the copy constructor. Unfortunately, the two were not in sync, and CodeGen might pick a copy-assignment operator that is different from what Sema chose, leading to strange failures, e.g., link-time failures when CodeGen called a copy-assignment operator that was not instantiation, run-time failures when copy-assignment operators were overloaded for const/non-const references and the wrong one was picked, and run-time failures when by-value copy-assignment operators did not have their arguments properly copy-initialized. This implementation synthesizes the implicitly-defined copy assignment operator bodies in Sema, so that the resulting ASTs encode exactly what CodeGen needs to do; there is no longer any special code in CodeGen to synthesize copy-assignment operators. The synthesis of the body is relatively simple, and we generate one of three different kinds of copy statements for each base or member: - For a class subobject, call the appropriate copy-assignment operator, after overload resolution has determined what that is. - For an array of scalar types or an array of class types that have trivial copy assignment operators, construct a call to __builtin_memcpy. - For an array of class types with non-trivial copy assignment operators, synthesize a (possibly nested!) for loop whose inner statement calls the copy constructor. - For a scalar type, use built-in assignment. This patch fixes at least a few tests cases in Boost.Spirit that were failing because CodeGen picked the wrong copy-assignment operator (leading to link-time failures), and I suspect a number of undiagnosed problems will also go away with this change. Some of the diagnostics we had previously have gotten worse with this change, since we're going through generic code for our type-checking. I will improve this in a subsequent patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102853 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate/instantiate-default-assignment-operator.cpp')
-rw-r--r--test/SemaTemplate/instantiate-default-assignment-operator.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/test/SemaTemplate/instantiate-default-assignment-operator.cpp b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
index 5594d6c7d7..8b97f59e87 100644
--- a/test/SemaTemplate/instantiate-default-assignment-operator.cpp
+++ b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
@@ -5,13 +5,13 @@ template<typename T> struct RefPtr {
RefPtr& operator=(const PassRefPtr<T>&);
};
-struct A { RefPtr<int> a; };
-struct B : RefPtr<float> { };
+struct A { RefPtr<int> a; }; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}}
+struct B : RefPtr<float> { }; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}}
void f() {
A a1, a2;
- a1 = a2; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}}
+ a1 = a2;
B b1, b2;
- b1 = b2; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}}
+ b1 = b2;
}