@@ -1603,30 +1603,41 @@ def ExplicitInitDocs : Documentation {
16031603 let Category = DocCatField;
16041604 let Content = [{
16051605The ``clang::requires_explicit_initialization`` attribute indicates that the
1606- field of an aggregate must be initialized explicitly by users when the class
1607- is constructed. Its usage is invalid on non-aggregates.
1606+ field of an aggregate must be initialized explicitly by users when the type
1607+ is constructed. The attribute supports both C and C++, but its usage is invalid
1608+ on non-aggregates.
16081609
16091610Note that this attribute is *not* a memory safety feature, and is *not* intended
16101611to guard against use of uninitialized memory.
16111612
1612- Rather, it is intended for use in "parameter-objects", used to simulate the
1613- passing of named parameters.
1613+ Rather, it is intended for use in "parameter-objects", used to simulate,
1614+ for example, the passing of named parameters.
16141615The attribute generates a warning when explicit initializers for such
1615- "named parameters" are not provided:
1616+ variables are not provided (this occurs regardless of whether any in-class field
1617+ initializers exist):
16161618
16171619.. code-block:: c++
16181620
1621+ struct Buffer {
1622+ void *address [[clang::requires_explicit_initialization]];
1623+ size_t length [[clang::requires_explicit_initialization]] = 0;
1624+ };
1625+
16191626 struct ArrayIOParams {
16201627 size_t count [[clang::requires_explicit_initialization]];
16211628 size_t element_size [[clang::requires_explicit_initialization]];
16221629 int flags = 0;
16231630 };
16241631
1625- size_t ReadArray(FILE *file, void *buffer, ArrayIOParams params);
1632+ size_t ReadArray(FILE *file, struct Buffer buffer,
1633+ struct ArrayIOParams params);
16261634
16271635 int main() {
16281636 unsigned int buf[512];
1629- ReadArray(stdin, buf, {
1637+ ReadArray(stdin, {
1638+ buf
1639+ // warning: field 'length' is not explicitly initialized
1640+ }, {
16301641 .count = sizeof(buf) / sizeof(*buf),
16311642 // warning: field 'element_size' is not explicitly initialized
16321643 });
0 commit comments