Skip to content

Commit e102df2

Browse files
ferdymercurydpiparo
authored andcommitted
[cling] document caveat
Fixes root-project/root#18961
1 parent 576aa5e commit e102df2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

manual/cling/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,11 @@ next screen.
926926
img="03000093.png"
927927
caption="The object inspector of `fKeys`, the list of keys in the memory."
928928
%}
929+
930+
## Caveats
931+
932+
### Static Initialization Order Fiasco
933+
934+
When using the Cling interpreter, the lifetime of static variables is controlled, because of the lazy initialization (the variable is initialized the first time the function is called, and destroyed deterministically too). With static members, you often run into the [Static Initialization Order Fiasco] like in this issue. When multiple translation units have static variables, the order of their initialization is undefined. This can lead to runtime bugs if one static depends on another that hasn't yet been initialized.
935+
936+
Thus, in Cling, it's strongly encouraged to avoid static const member variables and prefer static member functions that return references to static objects, or static non-const variables.

0 commit comments

Comments
 (0)