[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 4 02:46:46 PDT 2024
================
@@ -1419,6 +1419,28 @@ is not specified.
}];
}
+def ExplicitInitDocs : Documentation {
+ let Category = DocCatField;
+ let Content = [{
+The ``clang::explicit_init`` attribute indicates that the field must be
+initialized explicitly by the caller when the class is constructed.
----------------
ilya-biryukov wrote:
Thanks! LG!
> we might want to forbid its usage on non-aggregates entirely.
I guess we could simply warn if the class in which the field is used is non-aggregate, but that entails the problems that were raised with the changed semantics of what's aggregate between C++17 and C++20 (especially if people use `Werror`).
I guess having a warning that is off by default is a no-brainer, it clearly adds value **if** people want it. But it might also happen that nobody uses it and the work for it is wasted.
Or we could simply document that the attribute is ignored for non-aggregate types in the documentation.
https://github.com/llvm/llvm-project/pull/102040
More information about the cfe-commits
mailing list