Skip to content

Commit

Permalink
[clang] Fix wrong warning about missing init for flexible array membe…
Browse files Browse the repository at this point in the history
…rs (#66341)

9108897 shouldn't have removed an
additional check that field has incomplete array type.

Fixes #66300

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
  • Loading branch information
Fznamznon and AaronBallman committed Sep 15, 2023
1 parent 7cc5d07 commit 38b4df5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,8 @@ void InitListChecker::CheckStructUnionTypes(
if (HasDesignatedInit && InitializedFields.count(*it))
continue;

if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
!it->getType()->isIncompleteArrayType()) {
SemaRef.Diag(IList->getSourceRange().getEnd(),
diag::warn_missing_field_initializers)
<< *it;
Expand Down
11 changes: 11 additions & 0 deletions clang/test/Sema/missing-field-initializers.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
{ 1, 2 },
{ 1 } // expected-warning {{missing field 'b' initializer}}
};

// GH66300
struct S {
int f0;
int f1[];
};

// We previously would accidentally diagnose missing a field initializer for
// f1, now we no longer issue that warning (note, this code is still unsafe
// because of the buffer overrun).
struct S s = {1, {1, 2}};

0 comments on commit 38b4df5

Please sign in to comment.