Author: Richard Sandiford Date: 2020-03-17T12:45:00Z New Revision: 4ece6f051bd088fb8d4862bedf590f4f9d86cd17
URL: https://github.com/llvm/llvm-project/commit/4ece6f051bd088fb8d4862bedf590f4f9d86cd17 DIFF: https://github.com/llvm/llvm-project/commit/4ece6f051bd088fb8d4862bedf590f4f9d86cd17.diff LOG: [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 Added: Modified: clang/lib/Sema/SemaExprCXX.cpp clang/test/SemaCXX/sizeless-1.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index f50e5ea02c86..24e312ef6d01 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -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()) { diff --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp index 40fa436dd1de..5cbf1923d705 100644 --- a/clang/test/SemaCXX/sizeless-1.cpp +++ b/clang/test/SemaCXX/sizeless-1.cpp @@ -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(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits