https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126319
Bug ID: 126319
Summary: -Wmissing-field-initializers with designated
initializers indicates a base class even though all
members are default-initialized
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jonathan.poelen at gmail dot com
Target Milestone: ---
When inheritance is used, it is not possible to reference the base class with
designated initializers, and gcc issues the -Wmissing-field-initializers
warning even if all members of the base classes are default-initialized.
https://godbolt.org/z/x5Y1EjY5E
struct ABase
{
int x = 0;
};
struct A : ABase
{
int a = 0;
int b;
};
int main()
{
(void)A{.b=1}; // missing initializer for member 'A::ABase' -> NOK
}
When all members of the base classes are default-initialized and all
non-default-initialized members are designated initialized, there should be no
warning.
In comparison, Clang simply ignores inherited members (though I believe this is
a bug).