[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 12:35:19 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 {{'requires_explicit_initialization' attribute is ignored in non-aggregate type 'NonAgg'}}
+  };
+  NonAgg nonagg;  // no-warning
+  (void)nonagg;
+
+  struct S {
+    [[clang::requires_explicit_initialization]] int x; // expected-note 7{{'x' declared here}}
----------------
higher-performance wrote:

Updated.

https://github.com/llvm/llvm-project/pull/102040


More information about the cfe-commits mailing list