Remember the "found declaration" for an overload candidate, which is the
entity (if applicable) which was actually looked up.  If a candidate was found
via a using declaration, this is the UsingShadowDecl;  otherwise, if
the candidate is template specialization, this is the template;  otherwise,
this is the function.

The point of this exercise is that "found declarations" are the entities
we do access control for, not their underlying declarations.  Broadly speaking,
this patch fixes access control for using declarations.

There is a *lot* of redundant code calling into the overload-resolution APIs;
we really ought to clean that up.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98945 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index c0b699a..13a7ead 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4204,6 +4204,8 @@
   DeclContext::lookup_const_iterator Con, ConEnd;
   for (llvm::tie(Con, ConEnd) = ClassDecl->lookup(ConstructorName);
        Con != ConEnd; ++Con) {
+    DeclAccessPair FoundDecl = DeclAccessPair::make(*Con, (*Con)->getAccess());
+
     // Find the constructor (which may be a template).
     CXXConstructorDecl *Constructor = 0;
     FunctionTemplateDecl *ConstructorTmpl= dyn_cast<FunctionTemplateDecl>(*Con);
@@ -4220,12 +4222,11 @@
         ((Kind.getKind() == InitializationKind::IK_Default) && 
          Constructor->isDefaultConstructor())) {
       if (ConstructorTmpl)
-        SemaRef.AddTemplateOverloadCandidate(ConstructorTmpl,
-                                             ConstructorTmpl->getAccess(),
+        SemaRef.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
                                              /*ExplicitArgs*/ 0,
                                              Args, NumArgs, CandidateSet);
       else
-        SemaRef.AddOverloadCandidate(Constructor, Constructor->getAccess(),
+        SemaRef.AddOverloadCandidate(Constructor, FoundDecl,
                                      Args, NumArgs, CandidateSet);
     }
   }
@@ -4535,10 +4536,10 @@
       if (Conv->getConversionType()->isLValueReferenceType() &&
           (AllowExplicit || !Conv->isExplicit())) {
         if (ConvTemplate)
-          AddTemplateConversionCandidate(ConvTemplate, I.getAccess(), ActingDC,
+          AddTemplateConversionCandidate(ConvTemplate, I.getPair(), ActingDC,
                                          Init, DeclType, CandidateSet);
         else
-          AddConversionCandidate(Conv, I.getAccess(), ActingDC, Init,
+          AddConversionCandidate(Conv, I.getPair(), ActingDC, Init,
                                  DeclType, CandidateSet);
       }
     }