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 @@ -6123,8 +6123,8 @@ "array subscript is not an integer">; def err_subscript_function_type : Error< "subscript of pointer to function type %0">; -def err_subscript_incomplete_type : Error< - "subscript of pointer to incomplete type %0">; +def err_subscript_incomplete_or_sizeless_type : Error< + "subscript of pointer to %select{incomplete|sizeless}0 type %1">; def err_dereference_incomplete_type : Error< "dereference of pointer to incomplete type %0">; def ext_gnu_subscript_void_type : Extension< diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4885,8 +4885,9 @@ // See IsCForbiddenLValueType. if (!ResultType.hasQualifiers()) VK = VK_RValue; } else if (!ResultType->isDependentType() && - RequireCompleteType(LLoc, ResultType, - diag::err_subscript_incomplete_type, BaseExpr)) + RequireCompleteSizedType( + LLoc, ResultType, + diag::err_subscript_incomplete_or_sizeless_type, BaseExpr)) return ExprError(); assert(VK == VK_RValue || LangOpts.CPlusPlus || diff --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c --- a/clang/test/Sema/sizeless-1.c +++ b/clang/test/Sema/sizeless-1.c @@ -142,6 +142,10 @@ *&volatile_int8 = local_int8; *&const_volatile_int8 = local_int8; // expected-error {{read-only variable is not assignable}} + global_int8_ptr[0] = local_int8; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + global_int8_ptr[1] = local_int8; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + overf(local_int8); overf(local_int16); 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 @@ -163,6 +163,10 @@ *&volatile_int8 = local_int8; *&const_volatile_int8 = local_int8; // expected-error {{read-only variable is not assignable}} + global_int8_ptr[0] = local_int8; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + global_int8_ptr[1] = local_int8; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}} + overf(local_int8); overf(local_int16);