[cfe-commits] r88851 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp test/SemaCXX/new-delete.cpp

Anders Carlsson andersca at mac.com
Sun Nov 15 10:43:15 CST 2009


Author: andersca
Date: Sun Nov 15 10:43:15 2009
New Revision: 88851

URL: http://llvm.org/viewvc/llvm-project?rev=88851&view=rev
Log:
If we find a deallocation function in the class scope, but it is a placement function we should not look for a deallocation function in the global scope.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/new-delete.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=88851&r1=88850&r2=88851&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Nov 15 10:43:15 2009
@@ -1739,6 +1739,10 @@
                                          "expression of type %0 to a pointer">;
 def warn_delete_incomplete : Warning<
   "deleting pointer to incomplete type %0 may cause undefined behaviour">;
+def err_no_suitable_delete_member_function_found : Error<
+  "no suitable member %0 in %1">;
+def note_delete_member_function_declared_here : Note<
+  "%0 declared here">;
 def err_decrement_bool : Error<"cannot decrement expression of type bool">;
 def warn_increment_bool : Warning<
   "incrementing expression of type bool is deprecated">;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Nov 15 10:43:15 2009
@@ -844,12 +844,12 @@
     DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName(
                                       ArrayForm ? OO_Array_Delete : OO_Delete);
 
+    LookupResult Found;
     if (Pointee->isRecordType() && !UseGlobal) {
       CXXRecordDecl *Record
         = cast<CXXRecordDecl>(Pointee->getAs<RecordType>()->getDecl());
       
       // Try to find operator delete/operator delete[] in class scope.
-      LookupResult Found;
       LookupQualifiedName(Found, Record, DeleteName, LookupOrdinaryName);
       
       if (Found.isAmbiguous()) {
@@ -867,6 +867,21 @@
           }
       }
       
+      if (!OperatorDelete && !Found.empty()) {
+        // We did find operator delete/operator delete[] declarations, but
+        // none of them were suitable.
+        Diag(StartLoc, diag::err_no_suitable_delete_member_function_found)
+        << DeleteName << Record;
+        
+        for (LookupResult::iterator F = Found.begin(), FEnd = Found.end();
+             F != FEnd; ++F) {
+          Diag((*F)->getLocation(), 
+               diag::note_delete_member_function_declared_here)
+          << DeleteName;
+        }
+        return ExprError();
+      }
+      
       if (!Record->hasTrivialDestructor())
         if (const CXXDestructorDecl *Dtor = Record->getDestructor(Context))
           MarkDeclarationReferenced(StartLoc,

Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=88851&r1=88850&r2=88851&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Sun Nov 15 10:43:15 2009
@@ -178,7 +178,15 @@
 class X8 : public X6, public X7 {
 };
 
-void f(X8* x8) {
+void f(X8 *x8) {
   delete x8; // expected-error {{member 'operator delete' found in multiple base classes of different types}}
 }
 
+class X9 {
+  static void operator delete(void*, int); // expected-note {{'operator delete' declared here}}
+  static void operator delete(void*, float); // expected-note {{'operator delete' declared here}}
+};
+
+void f(X9 *x9) {
+  delete x9; // expected-error {{no suitable member 'operator delete' in 'X9'}}
+}




More information about the cfe-commits mailing list