Skip to content

Commit bb3348e

Browse files
committed
Downgrade deletion of a void* from an error (which is should be) to an
extension warning (which other compilers seem to use). Works around a known bug in Xalan. llvm-svn: 104509
1 parent 6c47d64 commit bb3348e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,6 +2262,8 @@ def err_default_init_const : Error<
22622262
"default initialization of an object of const type %0"
22632263
"%select{| requires a user-provided default constructor}1">;
22642264
def err_delete_operand : Error<"cannot delete expression of type %0">;
2265+
def ext_delete_void_ptr_operand : ExtWarn<
2266+
"cannot delete expression with pointer-to-'void' type %0">;
22652267
def err_ambiguous_delete_operand : Error<"ambiguous conversion of delete "
22662268
"expression of type %0 to a pointer">;
22672269
def warn_delete_incomplete : Warning<

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,13 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
13981398
<< Type << Ex->getSourceRange());
13991399

14001400
QualType Pointee = Type->getAs<PointerType>()->getPointeeType();
1401-
if (Pointee->isFunctionType() || Pointee->isVoidType())
1401+
if (Pointee->isVoidType() && !isSFINAEContext()) {
1402+
// The C++ standard bans deleting a pointer to a non-object type, which
1403+
// effectively bans deletion of "void*". However, most compilers support
1404+
// this, so we treat it as a warning unless we're in a SFINAE context.
1405+
Diag(StartLoc, diag::ext_delete_void_ptr_operand)
1406+
<< Type << Ex->getSourceRange();
1407+
} else if (Pointee->isFunctionType() || Pointee->isVoidType())
14021408
return ExprError(Diag(StartLoc, diag::err_delete_operand)
14031409
<< Type << Ex->getSourceRange());
14041410
else if (!Pointee->isDependentType() &&

clang/test/SemaCXX/new-delete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void bad_deletes()
103103
delete 0; // expected-error {{cannot delete expression of type 'int'}}
104104
delete [0] (int*)0; // expected-error {{expected ']'}} \
105105
// expected-note {{to match this '['}}
106-
delete (void*)0; // expected-error {{cannot delete expression}}
106+
delete (void*)0; // expected-warning {{cannot delete expression with pointer-to-'void' type 'void *'}}
107107
delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
108108
::S::delete (int*)0; // expected-error {{expected unqualified-id}}
109109
}

0 commit comments

Comments
 (0)