brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 4506bff Raw
23 lines · plain
1.. title:: clang-tidy - darwin-dispatch-once-nonstatic2 3darwin-dispatch-once-nonstatic4==============================5 6Finds declarations of ``dispatch_once_t`` variables without static or global7storage. The behavior of using ``dispatch_once_t`` predicates with automatic or8dynamic storage is undefined by libdispatch, and should be avoided.9 10It is a common pattern to have functions initialize internal static or global11data once when the function runs, but programmers have been known to miss the12static on the ``dispatch_once_t`` predicate, leading to an uninitialized flag13value at the mercy of the stack.14 15Programmers have also been known to make ``dispatch_once_t`` variables be16members of structs or classes, with the intent to lazily perform some expensive17struct or class member initialization only once; however, this violates the18libdispatch requirements.19 20See the discussion section of21`Apple's dispatch_once documentation <https://developer.apple.com/documentation/dispatch/1447169-dispatch_once>`_22for more information.23