Skip to content

[analyzer] Add documentation for std::variant checker #76501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ New features

- Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
accesses via wrong alternatives.
`Documentation <https://clang.llvm.org/docs/analyzer/checkers.html#alpha-core-stdvariant-c>`__.
(`#66481 <https://github.com/llvm/llvm-project/pull/66481>`_)

- Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect
Expand Down
15 changes: 15 additions & 0 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,21 @@ This checker is a part of ``core.StackAddressEscape``, but is temporarily disabl
// returned block
}

.. _alpha-core-StdVariant:

alpha.core.StdVariant (C++)
"""""""""""""""""""""""""""
Check if a value of active type is retrieved from an ``std::variant`` instance with ``std::get``.
In case of bad variant type access (the accessed type differs from the active type)
a warning is emitted. Currently, this checker does not take exception handling into account.

.. code-block:: cpp

void test() {
std::variant<int, char> v = 25;
char c = stg::get<char>(v); // warn: "int" is the active alternative
}

.. _alpha-core-TestAfterDivZero:

alpha.core.TestAfterDivZero (C)
Expand Down