missing-field-initializers warning not reporting missing designated initializers (original) (raw)
In the following code, the missing-field-initializers does not produce a warning that b is not explicitly initialized.
Changing CheckForMissingFields to True here:
| // Disable check for missing fields when designators are used. |
|---|
| // This matches gcc behaviour. |
| CheckForMissingFields = false; |
seems to produce the expected warning.
The comment suggests
// Disable check for missing fields when designators are used. // This matches gcc behaviour.
However, GCC does produce the warning in that case.
Comparison with GCC: https://godbolt.org/z/WeYdY11q3
struct ExampleStruct { int a; int b; };
ExampleStruct buildExampleStruct(int a) { ExampleStruct e{ .a=a }; return e; }
Build flags: -Werror=missing-field-initializers -std=c++20
Expected behavior:
main.cpp:10:5: error: missing field 'b' initializer [-Werror,-Wmissing-field-initializers]
matching GCCs
:9:5: error: missing initializer for member 'ExampleStruct::b' [-Werror=missing-field-initializers]Actual behavior: Compiles without warning/error.