]> granicus.if.org Git - clang/commitdiff
The C++ delete expression strips cv-qualifiers from the pointed-to type. My previous...
authorDouglas Gregor <dgregor@apple.com>
Tue, 29 Sep 2009 21:38:53 +0000 (21:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 29 Sep 2009 21:38:53 +0000 (21:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83113 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5846866dc67ed42bfae43c8b4f9420d93924fc02..0ad18cdb31314c3da1996dfc6e04362e468a6d0d 100644 (file)
@@ -849,6 +849,18 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
                                    << Ex->getSourceRange()))
       return ExprError();
 
+    // C++ [expr.delete]p2:
+    //   [Note: a pointer to a const type can be the operand of a 
+    //   delete-expression; it is not necessary to cast away the constness 
+    //   (5.2.11) of the pointer expression before it is used as the operand 
+    //   of the delete-expression. ]
+    ImpCastExprToType(Ex, Context.getPointerType(Context.VoidTy), 
+                      CastExpr::CK_NoOp);
+    
+    // Update the operand.
+    Operand.take();
+    Operand = ExprArg(*this, Ex);
+    
     DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName(
                                       ArrayForm ? OO_Array_Delete : OO_Delete);
 
index 087b4643e30c9b9ebe69e9088ff3885de5630742..682ebd8243e7363630c556dc34a3c9351dd53f01 100644 (file)
@@ -132,3 +132,8 @@ public:
 void X4::release(X3 *x) {
   delete x;
 }
+
+class X6 {
+public:
+  void Destroy() const { delete this; }
+};