Skip to content

missing-field-initializers warning not reporting missing designated initializers #56628

Closed
@ottojo

Description

@ottojo

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

<source>:9:5: error: missing initializer for member 'ExampleStruct::b' [-Werror=missing-field-initializers]

Actual behavior: Compiles without warning/error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions