https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109739
Bug ID: 109739
Summary: bogus warning due to -Wmissing-field-initializers in
C++20 with designated initializers on struct with
empty base class
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tobias.rittweiler at contractors dot roche.com
Target Milestone: ---
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include <cstdint>
struct Empty {};
struct S : Empty {
uint32_t Uint32;
};
void consume(const S&) {}
void test() {
S s = { .Uint32 = 42 };
consume(s);
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
gcc-13.1 -std=c++20 -Werror=missing-field-initializers
<source>: In function 'void test()':
<source>:12:26: error: missing initializer for member 'S::<anonymous>'
[-Werror=missing-field-initializers]
12 | S s = { .Uint32 = 42 };
| ^
cc1plus: some warnings being treated as errors
Compiler returned: 1
My reading of
https://en.cppreference.com/w/cpp/language/aggregate_initialization is that
since C++17 base classes are allowed in class type to form an "aggregate" and
designated initializers are allowed since C++20.
So I would expect this example to be free of any warning.
(I am aware of the situation that the man page currently says that
`-Wmissing-field-initializers` "does not warn about designated initializers"
but that is evidently not true in the C++ frontend, as has been pointed out
before, see [1], [2].)
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39589#c11
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96868#c3