Files
TheRock/compiler/amd-llvm/clang-tools-extra/docs/clang-tidy/checks/misc/static-initialization-cycle.rst
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

64 lines
2.0 KiB
ReStructuredText

.. title:: clang-tidy - misc-static-initialization-cycle
misc-static-initialization-cycle
================================
Finds cyclical initialization of static variables.
The cycle can come from reference to static variables or from (static) function
calls during initialization. Such cycles can cause undefined behavior. In this
context "static" means C++ ``static`` class members, global variables, global
functions, and ``static`` variables inside functions.
For the purpose of this check, the initialization of a static variable
*uses* another static variable or function if it appears in the initializer
expression. A function *uses* a static variable or function if the variable
or function appears at any place in the function code (except if the variable
is assigned to). The check can detect cycles in this "usage graph".
The check does not consider conditions in function code and does not follow the
value of static variables (if assigned to another variable). For this reason it
can produce false positives in some cases.
Examples
--------
.. code-block:: c++
struct S { static int A; };
int B = S::A;
int S::A = B;
Cycle in variable initialization.
.. code-block:: c++
int f1(int X, int Y);
struct S { static int A; };
int B = S::A + 1;
int S::A = f1(B, 2);
Cyclical initialization: ``B`` uses value of ``S::A``, and ``S::A`` may use
value of ``B`` (the check gives always warning regardless of the code of
``f1``).
.. code-block:: c++
struct S { static int A; };
int f1() {
return S::A;
}
int S::A = f1();
This code results in initialization of ``S::A`` with itself through a function
call. The check would emit a warning in any case when ``S::A`` appears in
``f1`` (even if the return value is not affected by it).
References
----------
* CERT C++ Coding Standard rule `DCL56-CPP. Avoid cycles during initialization
of static objects <https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL56-CPP.+Avoid+cycles+during+initialization+of+static+objects>`_.