Skip to content

-Wmissing-designated-field-initializers complains even when the field has a default CTOR #174256

@kcc

Description

@kcc
cat ~/tmp/missing-designated-field-initializer-test.cpp
struct Foo {
  Foo(){}  // CTOR
};

struct Bar {
  int a{};
  Foo foo;
};

Bar getBar() {
  return {.a = 42};
}
~/LLVM-21.1.0-Linux-X64/bin/clang -c -Wmissing-designated-field-initializers  ~/tmp/missing-designated-field-initializer-test.cpp
.../tmp/missing-designated-field-initializer-test.cpp:11:18: warning: missing field 'foo' initializer [-Wmissing-designated-field-initializers]
   11 |   return {.a = 42};
      |                  ^
1 warning generated.

This warning would be extremely useful if foo didn't have a constructor, but in this case this warning is just a noise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions