From: Craig Silverstein Date: Wed, 20 Oct 2010 00:38:15 +0000 (+0000) Subject: The type-to-delete may not be a pointer if it's a dependent type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fa0b78c82b864be1f956ca4af9564db7c8bb5b6;p=clang The type-to-delete may not be a pointer if it's a dependent type. Here's example code: --- template class MyClass { struct S { }; S* NewS() { return new S; } void DeleteS() { delete NewS(); } }; --- CXXDeleteExpr::getDestroyedType() on the 'delete NewS()' expression would crash before this change. Now it returns a dependent type object. Solution suggested by dgregor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 6e73b9cbc2..02a24dd27e 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -158,8 +158,12 @@ QualType CXXDeleteExpr::getDestroyedType() const { else break; } + // The type-to-delete may not be a pointer if it's a dependent type. + const Type *ArgType = Arg->getType(); + if (ArgType->isDependentType()) + return ArgType; - return Arg->getType()->getAs()->getPointeeType(); + return ArgType->getAs()->getPointeeType(); } Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; }