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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 10:19:24 PDT 2024


================
@@ -119,6 +119,15 @@ FIELD(HasInitMethod, 1, NO_MERGE)
 /// within anonymous unions or structs.
 FIELD(HasInClassInitializer, 1, NO_MERGE)
 
+/// Custom attribute that is True if any field is marked as requiring explicit
+/// initialization with [[clang::requires_explicit_initialization]] in a type
+/// without a user-provided default constructor, or if this is the case for any
+/// base classes and/or member variables whose types are aggregates.
+///
+/// In this case, default-construction is diagnosed, as it would not explicitly
+/// initialize the field.
+FIELD(HasUninitializedExplicitInitFields, 1, NO_MERGE)
----------------
erichkeane wrote:

Hmm... is there a good reason to store this as a bit rather than doing a `hasAttr` check? This increases the cost of `FieldDecl` for everyone.

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


More information about the cfe-commits mailing list