Skip to content

Commit 84a820f

Browse files
Update documentation
1 parent eb073da commit 84a820f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,31 +1602,42 @@ is not specified.
16021602
def ExplicitInitDocs : Documentation {
16031603
let Category = DocCatField;
16041604
let Content = [{
1605-
The ``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.
1605+
The ``clang::requires_explicit_initialization`` attribute indicates that a
1606+
field of an aggregate must be initialized explicitly by the user when an object
1607+
of the aggregate type is constructed. The attribute supports both C and C++,
1608+
but its usage is invalid on non-aggregates.
16081609

16091610
Note that this attribute is *not* a memory safety feature, and is *not* intended
16101611
to 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.
16141615
The 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

Comments
 (0)