Skip to content

Commit 4ece6f0

Browse files
committed
[Sema][SVE] Reject "delete" with sizeless types
Sizeless types can't be used with "new", so it doesn't make sense to use them with "delete" either. The SVE ACLE therefore doesn't allow that. This is slightly stronger than for normal incomplete types, since: struct S; void f(S *s) { delete s; } is (by necessity) just a default-on warning rather than an error. Differential Revision: https://reviews.llvm.org/D76219
1 parent c6b8484 commit 4ece6f0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
34673467
// this, so we treat it as a warning unless we're in a SFINAE context.
34683468
Diag(StartLoc, diag::ext_delete_void_ptr_operand)
34693469
<< Type << Ex.get()->getSourceRange();
3470-
} else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
3470+
} else if (Pointee->isFunctionType() || Pointee->isVoidType() ||
3471+
Pointee->isSizelessType()) {
34713472
return ExprError(Diag(StartLoc, diag::err_delete_operand)
34723473
<< Type << Ex.get()->getSourceRange());
34733474
} else if (!Pointee->isDependentType()) {

clang/test/SemaCXX/sizeless-1.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ void cxx_only(int sel) {
420420
new (global_int8_ptr) svint8_t(); // expected-error {{allocation of sizeless type 'svint8_t'}}
421421
new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}
422422

423+
delete global_int8_ptr; // expected-error {{cannot delete expression of type 'svint8_t *'}}
424+
delete[] global_int8_ptr; // expected-error {{cannot delete expression of type 'svint8_t *'}}
425+
423426
local_int8.~__SVInt8_t(); // expected-error {{object expression of non-scalar type 'svint8_t' (aka '__SVInt8_t') cannot be used in a pseudo-destructor expression}}
424427

425428
(void)svint8_t();

0 commit comments

Comments
 (0)