Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -10036,9 +10036,11 @@ } } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) { QualType ArrayElemTy = ArrayTy->getElementType(); + if (RHSTy->isReferenceType()) + RHSTy = RHSTy->getPointeeType(); if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) || ArrayElemTy->isDependentType() || RHSTy->isDependentType() || - RHSTy->isReferenceType() || ArrayElemTy->isCharType() || + ArrayElemTy->isCharType() || S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy)) return; S.Diag(Loc, diag::warn_division_sizeof_array) Index: clang/test/Sema/div-sizeof-array.cpp =================================================================== --- clang/test/Sema/div-sizeof-array.cpp +++ clang/test/Sema/div-sizeof-array.cpp @@ -46,4 +46,8 @@ int array[10]; int narray = sizeof(array) / sizeof(int &); int narray2 = sizeof(array) / sizeof(decltype(array[0])); + + int *arrptrs[10]; // expected-note {{array 'arrptrs' declared here}} + int len = sizeof(arrptrs) / sizeof(decltype(*arrptrs[0])); // expected-warning {{expression does not compute the number of elements in this array; element type is 'int *', not 'int'}} + // expected-note@-1 {{place parentheses around the 'sizeof(decltype(*arrptrs[0]))' expression to silence this warning}} }