]> granicus.if.org Git - clang/commitdiff
Suppress diagnosing access violations while looking up deallocation functions
authorChandler Carruth <chandlerc@gmail.com>
Mon, 28 Jun 2010 00:30:51 +0000 (00:30 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 28 Jun 2010 00:30:51 +0000 (00:30 +0000)
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.

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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/new-delete.cpp

index 4d93e72be20f3b67d52fd4ed5840f3da6f05ecd2..97300f7d63e152a34bd2e6419f0bd4d3abd59c97 100644 (file)
@@ -1317,11 +1317,15 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
   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;
       }
   }
index 3f1da0292b4a273bd70bbdb86eb06f06d6c6f205..cd1da4b5933377863933fdce5e800f5ee1328986 100644 (file)
@@ -263,3 +263,27 @@ template void h<unsigned>(unsigned);
 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}}
+}
+}