Implement caching of copy assignment operator lookup.

I believe, upon, careful review, that this code causes us to incorrectly
handle exception specifications of copy assignment operators in C++03
mode. However, we currently do not seem to properly implement the subtle
distinction between copying of members and bases made by implicit copy
constructors and assignment operators in C++03 - namely that they are
limited in their overload selection - in all cases. As such, I feel that
committing this code is correct pending a careful review of our
implementation of these semantics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132841 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 92ade1e..46058b6 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2269,7 +2269,8 @@
           (SM == CXXCopyConstructor &&
             cast<CXXConstructorDecl>(M)->isCopyConstructor())) {
         QualType ArgType = M->getType()->getAs<FunctionProtoType>()->getArgType(0);
-        if (ArgType->getPointeeType().isConstQualified())
+        if (!ArgType->isReferenceType() ||
+            ArgType->getPointeeType().isConstQualified())
           Result->setConstParamMatch(true);
       }
     } else {
@@ -2310,10 +2311,10 @@
   return cast_or_null<CXXConstructorDecl>(Result->getMethod());
 }
 
-/// \brief Look up the copy constructor for the given class.
-CXXConstructorDecl *Sema::LookupCopyConstructor(CXXRecordDecl *Class,
-                                                unsigned Quals,
-                                                bool *ConstParamMatch) {
+/// \brief Look up the copying constructor for the given class.
+CXXConstructorDecl *Sema::LookupCopyingConstructor(CXXRecordDecl *Class,
+                                                   unsigned Quals,
+                                                   bool *ConstParamMatch) {
   assert(!(Quals & ~(Qualifiers::Const | Qualifiers::Volatile)) &&
          "non-const, non-volatile qualifiers for copy ctor arg");
   SpecialMemberOverloadResult *Result =
@@ -2341,6 +2342,27 @@
   return Class->lookup(Name);
 }
 
+/// \brief Look up the copying assignment operator for the given class.
+CXXMethodDecl *Sema::LookupCopyingAssignment(CXXRecordDecl *Class,
+                                             unsigned Quals, bool RValueThis,
+                                             unsigned ThisQuals,
+                                             bool *ConstParamMatch) {
+  assert(!(Quals & ~(Qualifiers::Const | Qualifiers::Volatile)) &&
+         "non-const, non-volatile qualifiers for copy assignment arg");
+  assert(!(ThisQuals & ~(Qualifiers::Const | Qualifiers::Volatile)) &&
+         "non-const, non-volatile qualifiers for copy assignment this");
+  SpecialMemberOverloadResult *Result =
+    LookupSpecialMember(Class, CXXCopyAssignment, Quals & Qualifiers::Const,
+                        Quals & Qualifiers::Volatile, RValueThis,
+                        ThisQuals & Qualifiers::Const,
+                        ThisQuals & Qualifiers::Volatile);
+
+  if (ConstParamMatch)
+    *ConstParamMatch = Result->hasConstParamMatch();
+
+  return Result->getMethod();
+}
+
 /// \brief Look for the destructor of the given class.
 ///
 /// During semantic analysis, this routine should be used in lieu of