]> granicus.if.org Git - clang/commitdiff
Introduce a new routine, LookupConstructors(), and use it for all
authorDouglas Gregor <dgregor@apple.com>
Fri, 2 Jul 2010 23:12:18 +0000 (23:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 2 Jul 2010 23:12:18 +0000 (23:12 +0000)
constructor-name lookup.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107536 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaInit.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/SemaOverload.cpp

index 9ec790bcdc11e4b6f0d7a985a7cdc066cf6be00e..c8294109fc509d74751cf273537d5c63ab65a366 100644 (file)
@@ -1478,6 +1478,7 @@ public:
   void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
                                     QualType T1, QualType T2,
                                     UnresolvedSetImpl &Functions);
+  DeclContext::lookup_result LookupConstructors(CXXRecordDecl *Class);
   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
 
   void ArgumentDependentLookup(DeclarationName Name, bool Operator,
index 0891ac0a548904c18b4f7277fd2b6e3d54cf1672..3d954618c209310864d267b0ce9b6b2afe8bb175 100644 (file)
@@ -2272,11 +2272,8 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
     // The type we're converting to is a class type. Enumerate its constructors
     // to see if there is a suitable conversion.
     CXXRecordDecl *T1RecordDecl = cast<CXXRecordDecl>(T1RecordType->getDecl());
-    DeclarationName ConstructorName
-      = S.Context.DeclarationNames.getCXXConstructorName(
-                           S.Context.getCanonicalType(T1).getUnqualifiedType());
     DeclContext::lookup_iterator Con, ConEnd;
-    for (llvm::tie(Con, ConEnd) = T1RecordDecl->lookup(ConstructorName);
+    for (llvm::tie(Con, ConEnd) = S.LookupConstructors(T1RecordDecl);
          Con != ConEnd; ++Con) {
       NamedDecl *D = *Con;
       DeclAccessPair FoundDecl = DeclAccessPair::make(D, D->getAccess());
@@ -2670,11 +2667,8 @@ static void TryConstructorInitialization(Sema &S,
   CXXRecordDecl *DestRecordDecl
     = cast<CXXRecordDecl>(DestRecordType->getDecl());
     
-  DeclarationName ConstructorName
-    = S.Context.DeclarationNames.getCXXConstructorName(
-                     S.Context.getCanonicalType(DestType).getUnqualifiedType());
   DeclContext::lookup_iterator Con, ConEnd;
-  for (llvm::tie(Con, ConEnd) = DestRecordDecl->lookup(ConstructorName);
+  for (llvm::tie(Con, ConEnd) = S.LookupConstructors(DestRecordDecl);
        Con != ConEnd; ++Con) {
     NamedDecl *D = *Con;
     DeclAccessPair FoundDecl = DeclAccessPair::make(D, D->getAccess());
@@ -2850,11 +2844,8 @@ static void TryUserDefinedConversion(Sema &S,
     
     // Try to complete the type we're converting to.
     if (!S.RequireCompleteType(Kind.getLocation(), DestType, 0)) {    
-      DeclarationName ConstructorName
-        = S.Context.DeclarationNames.getCXXConstructorName(
-                     S.Context.getCanonicalType(DestType).getUnqualifiedType());
       DeclContext::lookup_iterator Con, ConEnd;
-      for (llvm::tie(Con, ConEnd) = DestRecordDecl->lookup(ConstructorName);
+      for (llvm::tie(Con, ConEnd) = S.LookupConstructors(DestRecordDecl);
            Con != ConEnd; ++Con) {
         NamedDecl *D = *Con;
         DeclAccessPair FoundDecl = DeclAccessPair::make(D, D->getAccess());
@@ -3303,12 +3294,9 @@ static Sema::OwningExprResult CopyObject(Sema &S,
     return move(CurInit);
 
   // Perform overload resolution using the class's copy constructors.
-  DeclarationName ConstructorName
-    = S.Context.DeclarationNames.getCXXConstructorName(
-                  S.Context.getCanonicalType(S.Context.getTypeDeclType(Class)));
   DeclContext::lookup_iterator Con, ConEnd;
   OverloadCandidateSet CandidateSet(Loc);
-  for (llvm::tie(Con, ConEnd) = Class->lookup(ConstructorName);
+  for (llvm::tie(Con, ConEnd) = S.LookupConstructors(Class);
        Con != ConEnd; ++Con) {
     // Only consider copy constructors.
     CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(*Con);
index 3a62c1151a067597cdfedfddd32e274be7f71766..6d590893bdccbc4dba92b11b66bea455ff7cb14d 100644 (file)
@@ -1990,6 +1990,16 @@ void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
   }
 }
 
+/// \brief Look up the constructors for the given class.
+DeclContext::lookup_result Sema::LookupConstructors(CXXRecordDecl *Class) {
+  if (!Class->getDefinition())
+    return DeclContext::lookup_result();
+
+  CanQualType T = Context.getCanonicalType(Context.getTypeDeclType(Class));
+  DeclarationName Name = Context.DeclarationNames.getCXXConstructorName(T);
+  return Class->lookup(Name);
+}
+
 /// \brief Look for the destructor of the given class.
 ///
 /// During semantic analysis, this routine should be used in lieu of 
index 664c4f3c093b863bea605a47cc24c3899c220505..5b511d7d03c8665f74a61fa1efe8279a0a69e032 100644 (file)
@@ -1896,12 +1896,8 @@ OverloadingResult Sema::IsUserDefinedConversion(Expr *From, QualType ToType,
       // We're not going to find any constructors.
     } else if (CXXRecordDecl *ToRecordDecl
                  = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
-      DeclarationName ConstructorName
-        = Context.DeclarationNames.getCXXConstructorName(
-                       Context.getCanonicalType(ToType).getUnqualifiedType());
       DeclContext::lookup_iterator Con, ConEnd;
-      for (llvm::tie(Con, ConEnd)
-             = ToRecordDecl->lookup(ConstructorName);
+      for (llvm::tie(Con, ConEnd) = LookupConstructors(ToRecordDecl);
            Con != ConEnd; ++Con) {
         NamedDecl *D = *Con;
         DeclAccessPair FoundDecl = DeclAccessPair::make(D, D->getAccess());