]> granicus.if.org Git - clang/commitdiff
Bugfix: don't assert if someone manages to declare an operator new/delete template...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jun 2014 00:43:02 +0000 (00:43 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jun 2014 00:43:02 +0000 (00:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210230 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprCXX.cpp
test/CodeGenCXX/new.cpp

index 0492813f8faa41caf22014665d210da866fbf8df..f2332bde5f627cad5b4866d14c92b80f1f9ffc72 100644 (file)
@@ -1041,8 +1041,9 @@ RValue CodeGenFunction::EmitBuiltinNewDeleteCall(const FunctionProtoType *Type,
   DeclarationName Name = Ctx.DeclarationNames
       .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
   for (auto *Decl : Ctx.getTranslationUnitDecl()->lookup(Name))
-    if (Ctx.hasSameType(cast<FunctionDecl>(Decl)->getType(), QualType(Type, 0)))
-      return EmitNewDeleteCall(*this, cast<FunctionDecl>(Decl), Type, Args);
+    if (auto *FD = dyn_cast<FunctionDecl>(Decl))
+      if (Ctx.hasSameType(FD->getType(), QualType(Type, 0)))
+        return EmitNewDeleteCall(*this, cast<FunctionDecl>(Decl), Type, Args);
   llvm_unreachable("predeclared global operator new/delete is missing");
 }
 
index d8aa258cbbf27500f2e283aae3f15b25350845dc..862161b19385797bcaed942986147156f065f5c5 100644 (file)
@@ -2,6 +2,9 @@
 
 typedef __typeof__(sizeof(0)) size_t;
 
+// Declare an 'operator new' template to tickle a bug in __builtin_operator_new.
+template<typename T> void *operator new(size_t, int (*)(T));
+
 // Ensure that this declaration doesn't cause operator new to lose its
 // 'noalias' attribute.
 void *operator new[](size_t);
@@ -33,7 +36,6 @@ void *operator new[](size_t, const std::nothrow_t &) throw();
 void operator delete(void *, const std::nothrow_t &) throw();
 void operator delete[](void *, const std::nothrow_t &) throw();
 
-
 void t2(int* a) {
   int* b = new (a) int;
 }