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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 25 10:43:41 PDT 2024


================
@@ -6457,6 +6474,19 @@ void InitializationSequence::InitializeFrom(Sema &S,
     }
   }
 
+  if (!S.getLangOpts().CPlusPlus &&
+      Kind.getKind() == InitializationKind::IK_Default) {
+    RecordDecl *Rec = DestType->getAsRecordDecl();
+    if (Rec && Rec->hasUninitializedExplicitInitFields()) {
+      VarDecl *Var = dyn_cast_or_null<VarDecl>(Entity.getDecl());
+      if (Var && !Initializer) {
+        S.Diag(Var->getLocation(), diag::warn_field_requires_explicit_init)
----------------
erichkeane wrote:

same here.

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


More information about the cfe-commits mailing list