Skip to content

Commit 05bb2f8

Browse files
committed
[clang] Improve the documentation for the init_priority attribute
The documentation wasn't very clear about whether ordering is controlled within or across TUs, and same for dylibs. Clarify that, and also add mentions for the state of support on Mach-O platforms.
1 parent f09db6a commit 05bb2f8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ def InitPriorityDocs : Documentation {
121121
In C++, the order in which global variables are initialized across translation
122122
units is unspecified, unlike the ordering within a single translation unit. The
123123
``init_priority`` attribute allows you to specify a relative ordering for the
124-
initialization of objects declared at namespace scope in C++. The priority is
125-
given as an integer constant expression between 101 and 65535 (inclusive).
126-
Priorities outside of that range are reserved for use by the implementation. A
127-
lower value indicates a higher priority of initialization. Note that only the
128-
relative ordering of values is important. For example:
124+
initialization of objects declared at namespace scope in C++, even between translation
125+
units (but within a single final linked image). The priority is given as an integer
126+
constant expression between 101 and 65535 (inclusive). Priorities outside of that
127+
range are reserved for use by the implementation. A lower value indicates a higher
128+
priority of initialization. Note that only the relative ordering of values is
129+
important. For example:
129130

130131
.. code-block:: c++
131132

@@ -136,12 +137,18 @@ relative ordering of values is important. For example:
136137
``Obj2`` will be initialized *before* ``Obj1`` despite the usual order of
137138
initialization being the opposite.
138139

140+
Note that this attribute does not control the initialization order of objects
141+
across final linked image boundaries like shared objects and executables.
142+
139143
On Windows, ``init_seg(compiler)`` is represented with a priority of 200 and
140144
``init_seg(library)`` is represented with a priority of 400. ``init_seg(user)``
141145
uses the default 65535 priority.
142146

143147
This attribute is only supported for C++ and Objective-C++ and is ignored in
144148
other language modes. Currently, this attribute is not implemented on z/OS.
149+
This attribute also does not control the order of initialization across
150+
translation units on Mach-O platforms, where it only affects the order within
151+
a single TU.
145152
}];
146153
}
147154

0 commit comments

Comments
 (0)