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