According to modern C++ guidelines, we should prefer uniform initialization everywhere, for example:
int x{0};
However, when I try to combine uniform initialization with C++20’s designated initializers, Clangd issues a warning.
Example:
struct S {
int x;
};
S s{
.x{0} // Warning: Braces around scalar initializer
};
According to Clangd, this should be used:
S s{
.x = 0
};
But why does Clangd warn about .x{0}?
Is this syntax actually valid in C++20 or C++23?
Should designated initializers with braces be avoided?