[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:40 PDT 2024


================
@@ -4561,6 +4569,15 @@ static void TryConstructorInitialization(Sema &S,
 
   CXXConstructorDecl *CtorDecl = cast<CXXConstructorDecl>(Best->Function);
   if (Result != OR_Deleted) {
+    if (!IsListInit && Kind.getKind() == InitializationKind::IK_Default &&
+        DestRecordDecl != nullptr && DestRecordDecl->isAggregate() &&
+        DestRecordDecl->hasUninitializedExplicitInitFields()) {
+      S.Diag(Kind.getLocation(), diag::warn_field_requires_explicit_init)
+          << ("in " +
----------------
erichkeane wrote:

"in " should be part of the diagnostic, we shouldn't be calculating strings like this here (as the idea is that some day we should be able to translate the DiagnosticSemaKinds.td file for a translated compiler).

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


More information about the cfe-commits mailing list