Issue Details
- Number
- 25631
- Title
- linter to check omitted fields when constructing aggregate types?
- Description
- It would be nice to have a linter/tidy/whatever to enforce all non-defaulted fields in an aggregate type are initialized.
Assuming the code:
```cpp
struct A {
struct Options {
unsigned cache_size;
signed delta;
bool in_memory = false;
};
A(const Options&) {} // unsafe (may have fields uninitialized)
A(unsigned cache_size, signed delta, bool in_memory = false) {} // safe, all non-default args are initialized
};
int main() {
(void)A{
A::Options{
.delta = -1,
},
};
}
```
This leaves `cache_size` uninitialized when using designated initializers. (The problem exists even without designated initializers, but with designated initializers recently enabled it seems likely that we'll increase the use of aggregate types)
- URL
-
https://github.com/bitcoin/bitcoin/issue/25631
- Closed by
-
Back to List