-Wmissing-field-initializers 什么时候触发警告?

When does -Wmissing-field-initializers triggers warning?

顾名思义,它在缺少字段初始值设定项时触发。但它没有触发以下代码的任何警告。

#include <stdio.h>

struct test {
    int a, b, c;
};

void func(struct test test) {
    printf("%d, %d, %d\n", test.a, test.b, test.c);
}

int main() {
    func((struct test) {12, .a = 1, 12, .a = 13, .b = 13});
    return 0;
}

当我 运行 gcc test.c -Wmissing-field-initializers 时编译时没有警告。并打印出 13, 13, 0。这是 -Wmissing-field-initializers 的默认行为吗?

来自documentation

此选项不会对指定的初始化程序发出警告

尝试

#include <stdio.h>

struct test {
    int a, b, c;
};

void func(struct test test) {
    printf("%d, %d, %d\n", test.a, test.b, test.c);
}

int main() {
    func((struct test) {1, 2}); // Now you get a warning
    return 0;
}