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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 11:35:18 PST 2024


================
@@ -1111,6 +1116,10 @@ void CXXRecordDecl::addedMember(Decl *D) {
     } else if (!T.isCXX98PODType(Context))
       data().PlainOldData = false;
 
+    if (Field->hasAttr<ExplicitInitAttr>() && !Field->hasInClassInitializer()) {
+      setHasUninitializedExplicitInitFields(true);
+    }
----------------
AaronBallman wrote:

```suggestion
    if (Field->hasAttr<ExplicitInitAttr>() && !Field->hasInClassInitializer())
      setHasUninitializedExplicitInitFields(true);
```
I thought we decided that the attribute + an in-class initializer is valid and the user is still expected to explicitly initialize the field?

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


More information about the cfe-commits mailing list