From: Douglas Gregor Date: Tue, 29 Sep 2009 21:38:53 +0000 (+0000) Subject: The C++ delete expression strips cv-qualifiers from the pointed-to type. My previous... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1070c9f7acc889336be6f80c70dc1b32622cc83d;p=clang The C++ delete expression strips cv-qualifiers from the pointed-to type. My previous fix eliminated this behavior, so bring it back again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83113 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 5846866dc6..0ad18cdb31 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -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); diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index 087b4643e3..682ebd8243 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -132,3 +132,8 @@ public: void X4::release(X3 *x) { delete x; } + +class X6 { +public: + void Destroy() const { delete this; } +};