llvm / llvm/llvm-project

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

Open
#174,256 4 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.