Skip to content

Commit 4cd3741

Browse files
committed
Add documentation for the constructor and destructor attributes
1 parent 98e8f04 commit 4cd3741

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def Constructor : InheritableAttr {
11581158
let Spellings = [GCC<"constructor">];
11591159
let Args = [DefaultIntArgument<"Priority", 65535>];
11601160
let Subjects = SubjectList<[Function]>;
1161-
let Documentation = [Undocumented];
1161+
let Documentation = [CtorDtorDocs];
11621162
}
11631163

11641164
def CPUSpecific : InheritableAttr {
@@ -1424,7 +1424,7 @@ def Destructor : InheritableAttr {
14241424
let Spellings = [GCC<"destructor">];
14251425
let Args = [DefaultIntArgument<"Priority", 65535>];
14261426
let Subjects = SubjectList<[Function]>;
1427-
let Documentation = [Undocumented];
1427+
let Documentation = [CtorDtorDocs];
14281428
}
14291429

14301430
def EmptyBases : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7241,3 +7241,33 @@ the variables were declared in. It is not possible to check the return value
72417241
(if any) of these ``cleanup`` callback functions.
72427242
}];
72437243
}
7244+
7245+
def CtorDtorDocs : Documentation {
7246+
let Category = DocCatFunction;
7247+
let Content = [{
7248+
The ``constructor`` attribute causes the function to be called before entering
7249+
``main()``, and the ``destructor`` attribute causes the function to be called
7250+
after returning from ``main()`` or when the ``exit()`` function has been
7251+
called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
7252+
marked ``destructor`` from being called.
7253+
7254+
The constructor or destructor function should not accept any arguments and its
7255+
return type should be ``void``.
7256+
7257+
The attributes accept an optional argument used to specify the priority order
7258+
in which to execute constructor and destructor functions. The priority is
7259+
given as an integer constant expression between 101 and 65535 (inclusive).
7260+
Priorities outside of that range are reserved for use by the implementation. A
7261+
lower value indicates a higher priority of initialization. Note that only the
7262+
relative ordering of values is important. For example:
7263+
7264+
.. code-block:: c++
7265+
7266+
__attribute__((constructor(200))) void foo(void);
7267+
__attribute__((constructor(101))) void bar(void);
7268+
7269+
``bar()`` will be called before ``foo()``, and both will be called before
7270+
``main()``. If no argument is given to the ``constructor`` or ``destructor``
7271+
attribute, they default to the value ``65535``.
7272+
}];
7273+
}

0 commit comments

Comments
 (0)