[clang] 1d2fab7 - [analyzer] Add documentation for std::variant checker (#76501)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 28 13:19:55 PST 2023


Author: Gábor Spaits
Date: 2023-12-28T22:19:51+01:00
New Revision: 1d2fab74af73a279a21641b6649dca59f70e6519

URL: https://github.com/llvm/llvm-project/commit/1d2fab74af73a279a21641b6649dca59f70e6519
DIFF: https://github.com/llvm/llvm-project/commit/1d2fab74af73a279a21641b6649dca59f70e6519.diff

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

Add a short documentation for `StdVariantChecker`.

---------

Co-authored-by: Balazs Benics <benicsbalazs at gmail.com>
Co-authored-by: whisperity <whisperity at gmail.com>
Co-authored-by: DonatNagyE <donat.nagy at ericsson.com>

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/docs/analyzer/checkers.rst

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e21ec78a1e8a77..3c08d1808b0e7f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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

diff  --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 64a4752695f11f..bb637cf1b8007b 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -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 
diff ers 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)


        


More information about the cfe-commits mailing list