Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/darwin/dispatch-once-nonstatic.rst

raw
1 .. title:: clang-tidy - darwin-dispatch-once-nonstatic
2
3 darwin-dispatch-once-nonstatic
4 ==============================
5
6 Finds declarations of ``dispatch_once_t`` variables without static or global
7 storage. The behavior of using ``dispatch_once_t`` predicates with automatic or
8 dynamic storage is undefined by libdispatch, and should be avoided.
9
10 It is a common pattern to have functions initialize internal static or global
11 data once when the function runs, but programmers have been known to miss the
12 static on the ``dispatch_once_t`` predicate, leading to an uninitialized flag
13 value at the mercy of the stack.
14
15 Programmers have also been known to make ``dispatch_once_t`` variables be
16 members of structs or classes, with the intent to lazily perform some expensive
17 struct or class member initialization only once; however, this violates the
18 libdispatch requirements.
19
20 See the discussion section of
21 `Apple's dispatch_once documentation <https://developer.apple.com/documentation/dispatch/1447169-dispatch_once>`_
22 for more information.