[cfe-commits] r106986 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/new-delete.cpp

Chandler Carruth chandlerc at gmail.com
Sun Jun 27 17:30:51 PDT 2010


Author: chandlerc
Date: Sun Jun 27 19:30:51 2010
New Revision: 106986

URL: http://llvm.org/viewvc/llvm-project?rev=106986&view=rev
Log:
Suppress diagnosing access violations while looking up deallocation functions
much as we already do for allocation function lookup. Explicitly check access
for the function we actually select in one case that was previously missing,
but being caught behind the blanket diagnostics for all overload candidates.
This fixs PR7436.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/new-delete.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=106986&r1=106985&r2=106986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Jun 27 19:30:51 2010
@@ -1317,11 +1317,15 @@
   if (Found.isAmbiguous())
     return true;
 
+  Found.suppressDiagnostics();
+
   for (LookupResult::iterator F = Found.begin(), FEnd = Found.end();
        F != FEnd; ++F) {
     if (CXXMethodDecl *Delete = dyn_cast<CXXMethodDecl>(*F))
       if (Delete->isUsualDeallocationFunction()) {
         Operator = Delete;
+        CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(),
+                              F.getPair());
         return false;
       }
   }

Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=106986&r1=106985&r2=106986&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Sun Jun 27 19:30:51 2010
@@ -263,3 +263,27 @@
 template void h<unsigned[10]>(unsigned); // expected-note {{in instantiation of function template specialization 'Test1::h<unsigned int [10]>' requested here}}
 
 }
+
+// Don't diagnose access for overload candidates that aren't selected.
+namespace PR7436 {
+struct S1 {
+  void* operator new(size_t);
+  void operator delete(void* p);
+
+private:
+  void* operator new(size_t, void*); // expected-note {{declared private here}}
+  void operator delete(void*, void*);
+};
+class S2 {
+  void* operator new(size_t); // expected-note {{declared private here}}
+  void operator delete(void* p); // expected-note {{declared private here}}
+};
+
+void test(S1* s1, S2* s2) { 
+  delete s1;
+  delete s2; // expected-error {{is a private member}}
+  (void)new S1();
+  (void)new (0L) S1(); // expected-error {{is a private member}}
+  (void)new S2(); // expected-error {{is a private member}}
+}
+}





More information about the cfe-commits mailing list