]> granicus.if.org Git - clang/commitdiff
The type-to-delete may not be a pointer if it's a dependent type.
authorCraig Silverstein <csilvers2000@yahoo.com>
Wed, 20 Oct 2010 00:38:15 +0000 (00:38 +0000)
committerCraig Silverstein <csilvers2000@yahoo.com>
Wed, 20 Oct 2010 00:38:15 +0000 (00:38 +0000)
Here's example code:
---
template<class T> 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

lib/AST/ExprCXX.cpp

index 6e73b9cbc209a5f8908cc24226a05ee8fc926496..02a24dd27e06528c4af77d1e6c4771c974e1ba1e 100644 (file)
@@ -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<PointerType>()->getPointeeType();
+  return ArgType->getAs<PointerType>()->getPointeeType();
 }
 
 Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; }