Skip to content

Use -Wno-missing-field-initializers

Vlad Zahorodnii requested to merge work/zzag/gcc-stfu into master

gcc spams build logs with false positive messages about uninitialized struct fields.

Consider the following example

#include <string>

struct Struct
{
    int integer;
    std::string string;
};

int main()
{
    Struct struct1;

    Struct struct2 {
        .integer = 42,
    };

    Struct struct3 {
        .string = "baz",
    };

    return 0;
}

gcc complains about missing field initializers in struct2 and struct3, not struct1, even though the behavior of the {} initializer is well specified.

If gcc wants to be useful with detecting uninitialized values, it has to complain about struct1 that actually contains an uninitialized integer value. The string in struct2 and the integer in struct3 are default initialized, they are fine. Current gcc's behavior makes no sense.

Merge request reports