Skip to content

Commit 38b4df5

Browse files
[clang] Fix wrong warning about missing init for flexible array members (#66341)
9108897 shouldn't have removed an additional check that field has incomplete array type. Fixes #66300 Co-authored-by: Aaron Ballman <[email protected]>
1 parent 7cc5d07 commit 38b4df5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,8 @@ void InitListChecker::CheckStructUnionTypes(
23952395
if (HasDesignatedInit && InitializedFields.count(*it))
23962396
continue;
23972397

2398-
if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
2398+
if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
2399+
!it->getType()->isIncompleteArrayType()) {
23992400
SemaRef.Diag(IList->getSourceRange().getEnd(),
24002401
diag::warn_missing_field_initializers)
24012402
<< *it;

clang/test/Sema/missing-field-initializers.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
5050
{ 1, 2 },
5151
{ 1 } // expected-warning {{missing field 'b' initializer}}
5252
};
53+
54+
// GH66300
55+
struct S {
56+
int f0;
57+
int f1[];
58+
};
59+
60+
// We previously would accidentally diagnose missing a field initializer for
61+
// f1, now we no longer issue that warning (note, this code is still unsafe
62+
// because of the buffer overrun).
63+
struct S s = {1, {1, 2}};

0 commit comments

Comments
 (0)