Skip to content

Commit

Permalink
[Sema][SVE] Reject "delete" with sizeless types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rsandifo-arm committed Mar 17, 2020
1 parent c6b8484 commit 4ece6f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaExprCXX.cpp
Expand Up @@ -3467,7 +3467,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
// this, so we treat it as a warning unless we're in a SFINAE context.
Diag(StartLoc, diag::ext_delete_void_ptr_operand)
<< Type << Ex.get()->getSourceRange();
} else if (Pointee->isFunctionType() || Pointee->isVoidType()) {
} else if (Pointee->isFunctionType() || Pointee->isVoidType() ||
Pointee->isSizelessType()) {
return ExprError(Diag(StartLoc, diag::err_delete_operand)
<< Type << Ex.get()->getSourceRange());
} else if (!Pointee->isDependentType()) {
Expand Down
3 changes: 3 additions & 0 deletions clang/test/SemaCXX/sizeless-1.cpp
Expand Up @@ -420,6 +420,9 @@ void cxx_only(int sel) {
new (global_int8_ptr) svint8_t(); // expected-error {{allocation of sizeless type 'svint8_t'}}
new (global_int8_ptr) svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}}

delete global_int8_ptr; // expected-error {{cannot delete expression of type 'svint8_t *'}}
delete[] global_int8_ptr; // expected-error {{cannot delete expression of type 'svint8_t *'}}

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}}

(void)svint8_t();
Expand Down

0 comments on commit 4ece6f0

Please sign in to comment.