Index: clang/include/clang/Basic/DiagnosticGroups.td =================================================================== --- clang/include/clang/Basic/DiagnosticGroups.td +++ clang/include/clang/Basic/DiagnosticGroups.td @@ -729,6 +729,7 @@ def UninitializedSometimes : DiagGroup<"sometimes-uninitialized">; def UninitializedStaticSelfInit : DiagGroup<"static-self-init">; def UninitializedConstReference : DiagGroup<"uninitialized-const-reference">; +def UninitializedArrayElements : DiagGroup<"uninitialized-array-elements">; def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes, UninitializedStaticSelfInit, UninitializedConstReference]>; Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2214,6 +2214,9 @@ "reference %0 is not yet bound to a value when used within its own" " initialization">, InGroup; +def warn_uninit_fixed_size_array : Warning< + "fixed-size array contains uninitialized elements">, + InGroup, DefaultIgnore; def warn_uninit_var : Warning< "variable %0 is uninitialized when %select{used here|captured by block}1">, InGroup, DefaultIgnore; Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -980,6 +980,24 @@ if (RequiresSecondPass && !hadError) FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass, nullptr, 0); + + if (const ConstantArrayType *CAType = dyn_cast(T)) { + if (FullyStructuredList->getNumInits() < + CAType->getSize().getZExtValue()) { + S.Diag(IL->getBeginLoc(), diag::warn_uninit_fixed_size_array) + << IL->getSourceRange(); + } else { + Expr **inits = FullyStructuredList->getInits(); + for (unsigned i = 0, e = FullyStructuredList->getNumInits(); i != e; + ++i) { + if (inits[i] == nullptr) { + S.Diag(IL->getBeginLoc(), diag::warn_uninit_fixed_size_array) + << IL->getSourceRange(); + break; + } + } + } + } } if (hadError && FullyStructuredList) FullyStructuredList->markError();