[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 10:45:32 PDT 2024
================
@@ -1472,3 +1472,56 @@ template<typename T> struct Outer {
};
};
Outer<int>::Inner outerinner;
+
+void aggregate() {
+ struct NonAgg {
+ NonAgg() { }
+ [[clang::requires_explicit_initialization]] int f; // expected-warning {{attribute is ignored}}
+ };
+ NonAgg nonagg;
+ (void)nonagg;
+
+ struct S {
+ [[clang::requires_explicit_initialization]] int x; // expected-note {{declared}} // expected-note {{declared}} // expected-note {{declared}} // expected-note {{declared}}
----------------
erichkeane wrote:
```suggestion
[[clang::requires_explicit_initialization]] int x; // expected-note 4{{declared here}}
```
THOUGH, I VASTLY prefer to use 'bookmarks' for diagnostics and have these notes be shown in text right below the warning.
Also, please don't use partial matches so aggressively, it makes reviewing these now/in the future much more difficult
https://github.com/llvm/llvm-project/pull/102040
More information about the cfe-commits
mailing list