diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6897,8 +6897,8 @@ "array size must be specified in new expression with no initializer">; def err_bad_new_type : Error< "cannot allocate %select{function|reference}1 type %0 with new">; -def err_new_incomplete_type : Error< - "allocation of incomplete type %0">; +def err_new_incomplete_or_sizeless_type : Error< + "allocation of %select{incomplete|sizeless}0 type %1">; def err_new_array_nonconst : Error< "only the first dimension of an allocated array may have dynamic size">; def err_new_array_size_unknown_from_init : Error< diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2340,7 +2340,8 @@ return Diag(Loc, diag::err_bad_new_type) << AllocType << 1 << R; else if (!AllocType->isDependentType() && - RequireCompleteType(Loc, AllocType, diag::err_new_incomplete_type,R)) + RequireCompleteSizedType( + Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R)) return true; else if (RequireNonAbstractType(Loc, AllocType, diag::err_allocation_of_abstract_type)) diff --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp --- a/clang/test/SemaCXX/sizeless-1.cpp +++ b/clang/test/SemaCXX/sizeless-1.cpp @@ -411,6 +411,15 @@ } catch (svint8_t &) { // expected-error {{cannot catch reference to sizeless type 'svint8_t'}} } + new svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}} + new svint8_t(); // expected-error {{allocation of sizeless type 'svint8_t'}} + new svint8_t[10]; // expected-error {{allocation of sizeless type 'svint8_t'}} + new svint8_t *; + + new (global_int8_ptr) svint8_t; // expected-error {{allocation of sizeless type 'svint8_t'}} + 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'}} + 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();