[cfe-commits] r81930 - in /cfe/trunk: lib/AST/DeclCXX.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/conversion-delete-expr.cpp test/SemaCXX/direct-initializer.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Sep 15 15:15:24 PDT 2009


Author: fjahanian
Date: Tue Sep 15 17:15:23 2009
New Revision: 81930

URL: http://llvm.org/viewvc/llvm-project?rev=81930&view=rev
Log:
1) don't do overload resolution in selecting conversion
to pointer function for delete expression. 2)
Treat type conversion function and its 'const' version
as identical in building the visible conversion list.

Modified:
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/conversion-delete-expr.cpp
    cfe/trunk/test/SemaCXX/direct-initializer.cpp

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=81930&r1=81929&r2=81930&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Sep 15 17:15:23 2009
@@ -314,7 +314,7 @@
         else 
           TConvType = 
             getASTContext().getCanonicalType(
-                                        cast<FunctionDecl>(TopConv)->getType());
+                        cast<CXXConversionDecl>(TopConv)->getConversionType());
         TopConversionsTypeSet.insert(TConvType);
       }
     }
@@ -334,7 +334,8 @@
                             ConversionTemplate->getTemplatedDecl()->getType());
       else
         ConvType = 
-          getASTContext().getCanonicalType(cast<FunctionDecl>(Conv)->getType());
+          getASTContext().getCanonicalType(
+                          cast<CXXConversionDecl>(Conv)->getConversionType());
       if (inTopClass || !TopConversionsTypeSet.count(ConvType)) {
         if (FunctionTemplateDecl *ConversionTemplate =
               dyn_cast<FunctionTemplateDecl>(Conv))

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=81930&r1=81929&r2=81930&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Sep 15 17:15:23 2009
@@ -736,7 +736,6 @@
     QualType Type = Ex->getType();
 
     if (const RecordType *Record = Type->getAs<RecordType>()) {
-      OverloadCandidateSet CandidateSet;
       llvm::SmallVector<CXXConversionDecl *, 4> ObjectPtrConversions;
       CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
       OverloadedFunctionDecl *Conversions = 
@@ -755,32 +754,27 @@
         QualType ConvType = Conv->getConversionType().getNonReferenceType();
         if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>())
           if (ConvPtrType->getPointeeType()->isObjectType())
-            AddConversionCandidate(Conv, Ex, ConvType, CandidateSet);
+            ObjectPtrConversions.push_back(Conv);
       }
-      OverloadCandidateSet::iterator Best;
-      switch (BestViableFunction(CandidateSet, Ex->getLocStart(), Best)) {
-        case OR_Success:
-          {
-            Operand.release();
-            CXXConversionDecl *Conversion
-              = cast<CXXConversionDecl>(Best->Function);
-            if (PerformImplicitConversion(Ex, 
-                                          Conversion->getConversionType(), 
-                                          "converting"))
-              return ExprError();
-            
-            Operand = Owned(Ex);
-            Type = Ex->getType();
-            break;
-          }
-        case OR_No_Viable_Function:
-        case OR_Deleted:
-          break;  // Will issue error below.
-        case OR_Ambiguous:
-          Diag(StartLoc, diag::err_ambiguous_delete_operand)
-                  << Type << Ex->getSourceRange();
-          PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
-          return ExprError();
+      if (ObjectPtrConversions.size() == 1) {
+        // We have a single conversion to a pointer-to-object type. Perform
+        // that conversion.
+        Operand.release();
+        if (!PerformImplicitConversion(Ex, 
+                            ObjectPtrConversions.front()->getConversionType(), 
+                                      "converting")) {
+          Operand = Owned(Ex);
+          Type = Ex->getType();
+        }
+      }
+      else if (ObjectPtrConversions.size() > 1) {
+        Diag(StartLoc, diag::err_ambiguous_delete_operand)
+              << Type << Ex->getSourceRange();
+        for (unsigned i= 0; i < ObjectPtrConversions.size(); i++) {
+          CXXConversionDecl *Conv = ObjectPtrConversions[i];
+          Diag(Conv->getLocation(), diag::err_ovl_candidate);
+        }
+        return ExprError();
       }
     }
 

Modified: cfe/trunk/test/SemaCXX/conversion-delete-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion-delete-expr.cpp?rev=81930&r1=81929&r2=81930&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/conversion-delete-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion-delete-expr.cpp Tue Sep 15 17:15:23 2009
@@ -78,19 +78,18 @@
 
 // Test7
 struct Base {
-   operator int*();	// expected-note {{candidate function}}
+   operator int*();	
 };
 
 struct Derived : Base {
    // not the same function as Base's non-const operator int()
-   operator int*() const;  // expected-note {{candidate function}}
+   operator int*() const;
 };
 
 void foo6(const Derived cd, Derived d) {
 	// overload resolution selects Derived::operator int*() const;
 	delete cd;
-
-	delete d;	// expected-error {{ambiguous conversion of delete expression of type 'struct Derived' to a pointer}}
+	delete d;	
 }
 
 // Test8

Modified: cfe/trunk/test/SemaCXX/direct-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/direct-initializer.cpp?rev=81930&r1=81929&r2=81930&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/direct-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/direct-initializer.cpp Tue Sep 15 17:15:23 2009
@@ -36,15 +36,15 @@
 }
 
 struct Base {
-   operator int*() const; // expected-note {{candidate function}}
+   operator int*() const; 
 };
 
 struct Derived : Base {
-   operator int*(); // expected-note {{candidate function}}
+   operator int*(); 
 };
 
 void foo(const Derived cd, Derived d) {
-        int *pi = cd;
-        int *ppi = d; // expected-error {{ambiguity in initializing value of type 'int *' with initializer of type 'struct Derived'}}
+        int *pi = cd;	// expected-error {{incompatible type initializing 'struct Derived const', expected 'int *'}}
+        int *ppi = d; 
 
 }





More information about the cfe-commits mailing list