]> granicus.if.org Git - clang/commitdiff
Fix a crash on template delete operators.
authorChandler Carruth <chandlerc@gmail.com>
Sun, 8 Aug 2010 07:04:00 +0000 (07:04 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 8 Aug 2010 07:04:00 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110542 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b1d601551412b755ad5615cea850c982222a6577..7bebce16e1f3aaf7a35ddf0e03b4a49677753958 100644 (file)
@@ -1301,8 +1301,14 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
   llvm::SmallVector<DeclAccessPair,4> Matches;
   for (LookupResult::iterator F = Found.begin(), FEnd = Found.end();
        F != FEnd; ++F) {
-    CXXMethodDecl *Delete = cast<CXXMethodDecl>((*F)->getUnderlyingDecl());
-    if (Delete->isUsualDeallocationFunction())
+    NamedDecl *ND = (*F)->getUnderlyingDecl();
+
+    // Ignore template operator delete members from the check for a usual
+    // deallocation function.
+    if (isa<FunctionTemplateDecl>(ND))
+      continue;
+
+    if (cast<CXXMethodDecl>(ND)->isUsualDeallocationFunction())
       Matches.push_back(F.getPair());
   }
 
index 816b808346af25d6d8338ac6091747270dda2a81..b127e667c5315e319751eeb490c3a9bca3218e42 100644 (file)
@@ -332,3 +332,15 @@ namespace PR7810 {
     static void operator delete(void *volatile);
   };
 }
+
+// Don't crash on template delete operators
+namespace TemplateDestructors {
+  struct S {
+    virtual ~S() {}
+
+    void* operator new(const size_t size);
+    template<class T> void* operator new(const size_t, const int, T*);
+    void operator delete(void*, const size_t);
+    template<class T> void operator delete(void*, const size_t, const int, T*);
+  };
+}