]> granicus.if.org Git - clang/commitdiff
Have CXXDeleteExpr::getDestroyedType return the actual destroyed type
authorCraig Silverstein <csilvers2000@yahoo.com>
Tue, 16 Nov 2010 07:16:25 +0000 (07:16 +0000)
committerCraig Silverstein <csilvers2000@yahoo.com>
Tue, 16 Nov 2010 07:16:25 +0000 (07:16 +0000)
in more situations.  In particular, for code like

   template<class T> void Fn() { T* x; delete x; }

getDestroyedType() will now return T rather than T*, as it would
before this change.  On the other hand, for code like this:

   template<class T> void Fn() { T x; delete x; }

getDestroyedType() will return an empty QualType(), since it doesn't
know what the actual destroyed type would be.  Previously, it would
return T.

OKed by rjmccall

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

include/clang/AST/ExprCXX.h
lib/AST/ExprCXX.cpp

index 3b8ecf293071ac6ce99db69b6a17c5ec66a1ebcf..78edd4beecc7212048299aa5a7f6896421f2f7a0 100644 (file)
@@ -1150,6 +1150,9 @@ public:
   Expr *getArgument() { return cast<Expr>(Argument); }
   const Expr *getArgument() const { return cast<Expr>(Argument); }
 
+  /// \brief Retrieve the type being destroyed.  If the type being
+  /// destroyed is a dependent type which may or may not be a pointer,
+  /// return an invalid type.
   QualType getDestroyedType() const;
   
   virtual SourceRange getSourceRange() const {
index 60785d471acde1eec10933396da675b200059b90..1820ff77074ab9a564b7b09676def7d301a9d10d 100644 (file)
@@ -162,8 +162,9 @@ QualType CXXDeleteExpr::getDestroyedType() const {
   }
   // The type-to-delete may not be a pointer if it's a dependent type.
   const QualType ArgType = Arg->getType();
-  if (ArgType->isDependentType())
-    return ArgType;
+
+  if (ArgType->isDependentType() && !ArgType->isPointerType())
+    return QualType();
 
   return ArgType->getAs<PointerType>()->getPointeeType();
 }