Skip to content

[clang-tidy] readability-redundant-member-init vs -Wmissing-field-initializers  #90235

@dieram3

Description

@dieram3

I just came across an incompatibility between the new readability-redundant-member-init check and the -Wmissing-field-initializers diagnostic. It is a common pattern to have an aggregate type representing a set of options, some of which are optional, e.g.:

struct options {
    int required_1;
    int required_2;
    std::optional<int> optional{};
};

Now, if I have the following:

void foo(options opts);

void bar() {
    foo({
        .required_1 = 4,
        .required_2 = 2,
        // optional omitted.
    });
}

readability-redundant-member-init will complain the initializer for optional is redundant. However, if I remove it, -Wmissing-field-initializers will complain that the field initializer for optional is missing.

Compiler Explorer repro: https://godbolt.org/z/xfzPv8h47

Is there a way to make these two agree? Or maybe readability-redundant-member-init needs a new option or adjustment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions